blob: 9ef86eb7f986e48353cb9608dd3c5acab1649a6d [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;
Hyosun Kim8bac3be2024-06-28 13:35:30 +0000167import android.telephony.satellite.ProvisionSubscriberId;
Sarah Chin503828c2023-02-01 23:54:20 -0800168import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000169import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800170import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800171import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800172import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700175import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800177import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800178
Andrew Lee312e8172014-10-23 17:01:36 -0700179import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800180import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800181import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800182import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800183import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700185import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700186import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800187import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800188import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700189import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700190import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800191import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700192import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800193import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800194import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000197import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700198import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800199import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800201import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800202import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800203import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700204import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700205import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700206import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700208import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800209import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700210import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700211import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700212import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700213import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800214import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800215import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700216import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000217import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700218import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700219import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800220import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800221import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800222import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700223import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000224import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800225import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700226import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700227import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800228import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700229import com.android.internal.telephony.imsphone.ImsPhone;
230import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000231import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800232import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000233import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800234import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
235import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700236import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700237import com.android.internal.telephony.uicc.IccIoResult;
238import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700240import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800241import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000243import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800244import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000245import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800246import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000247import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700248import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700249import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800250import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800251import com.android.phone.callcomposer.CallComposerPictureManager;
252import com.android.phone.callcomposer.CallComposerPictureTransfer;
253import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800254import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000255import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700256import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700257import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000258import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700259import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800260import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700261import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700262import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800263import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800264import com.android.services.telephony.TelecomAccountRegistry;
265import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000266import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800267import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800268
Hall Liu82694d52020-12-11 18:22:04 -0800269import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700270import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800271import java.io.IOException;
272import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700273import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800275import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000276import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800277import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800278import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800279import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800280import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100281import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800282import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700283import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800284import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800285import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700286import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800287import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800288import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800289import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
291/**
292 * Implementation of the ITelephony interface.
293 */
Santos Cordon117fee72014-05-16 17:56:12 -0700294public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 private static final String LOG_TAG = "PhoneInterfaceManager";
296 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
297 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800298 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299
300 // Message codes used with mMainThreadHandler
301 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700302 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
303 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700304 private static final int CMD_OPEN_CHANNEL = 9;
305 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
306 private static final int CMD_CLOSE_CHANNEL = 11;
307 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800308 private static final int CMD_NV_READ_ITEM = 13;
309 private static final int EVENT_NV_READ_ITEM_DONE = 14;
310 private static final int CMD_NV_WRITE_ITEM = 15;
311 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
312 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
313 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700314 private static final int CMD_RESET_MODEM_CONFIG = 19;
315 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800316 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
317 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800318 private static final int CMD_SEND_ENVELOPE = 25;
319 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700320 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
321 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
322 private static final int CMD_EXCHANGE_SIM_IO = 31;
323 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800324 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
325 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700326 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
327 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700328 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
329 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700330 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
331 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
332 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
333 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700334 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
335 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
336 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
337 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700338 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800339 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
340 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000341 private static final int CMD_SWITCH_SLOTS = 50;
342 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700343 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
344 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
345 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
346 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
347 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
348 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
349 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
350 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700351 private static final int CMD_GET_ALL_CELL_INFO = 60;
352 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
353 private static final int CMD_GET_CELL_LOCATION = 62;
354 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700355 private static final int CMD_MODEM_REBOOT = 64;
356 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700357 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
358 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800359 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
360 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700361 private static final int CMD_GET_MODEM_STATUS = 70;
362 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700363 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
364 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700365 private static final int CMD_ERASE_MODEM_CONFIG = 74;
366 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800367 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
368 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
369 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
370 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800371 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
372 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800374 private static final int CMD_GET_CALL_FORWARDING = 83;
375 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
376 private static final int CMD_SET_CALL_FORWARDING = 85;
377 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
378 private static final int CMD_GET_CALL_WAITING = 87;
379 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
380 private static final int CMD_SET_CALL_WAITING = 89;
381 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700382 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
383 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
384 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
385 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700386 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
387 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800388 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
389 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800390 private static final int CMD_SET_DATA_THROTTLING = 99;
391 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800392 private static final int CMD_SET_SIM_POWER = 101;
393 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800394 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
395 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
396 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
397 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800398 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
399 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000400 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800401 private static final int CMD_GET_SLICING_CONFIG = 110;
402 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800403 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700404 private static final int CMD_ENABLE_VONR = 113;
405 private static final int EVENT_ENABLE_VONR_DONE = 114;
406 private static final int CMD_IS_VONR_ENABLED = 115;
407 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700408 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
409 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000410
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800411 // Parameters of select command.
412 private static final int SELECT_COMMAND = 0xA4;
413 private static final int SELECT_P1 = 0x04;
414 private static final int SELECT_P2 = 0;
415 private static final int SELECT_P3 = 0x10;
416
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000417 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
418 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000419 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
420 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600421 // Null cipher notification support was added in IRadioNetwork 2.2
422 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 /** The singleton instance. */
425 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800426 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427
Sarah Chin4beb2b72023-02-14 14:47:54 -0800428 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000429 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800430 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800431 private final CallManager mCM;
432 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000433
434 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800435 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800436 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800437 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final SharedPreferences mTelephonySharedPreferences;
439 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800440 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700441 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000442 private PackageManager mPackageManager;
joonhunshinf624b2a2024-04-18 04:42:12 +0000443 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Peter Wangdafb9ac2020-01-15 14:13:38 -0800445 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800446 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800447 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800448 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800449
Derek Tan97ebb422014-09-05 16:55:38 -0700450 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
451 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800452 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800453 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700454
Michelecea4cf22018-12-21 15:00:11 -0800455 // String to store multi SIM allowed
456 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
457
Derek Tan740e1672017-06-27 14:56:27 -0700458 // The AID of ISD-R.
459 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
460
yinxub1bed742017-04-17 11:45:04 -0700461 private NetworkScanRequestTracker mNetworkScanRequestTracker;
462
David Kelly5e06a7f2018-03-12 14:10:59 +0000463 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
464 private static final int MANUFACTURER_CODE_LENGTH = 8;
465
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800466 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800467 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800468
Sarah Chin2ec39f62022-08-31 17:03:26 -0700469 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
470 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
471
Derek Tan89e89d42014-07-08 17:00:10 -0700472 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700473 * Experiment flag to enable erase modem config on reset network, default value is false
474 */
475 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
476 "reset_network_erase_modem_config_enabled";
477
Rambo Wang0f050d82021-02-12 11:43:36 -0800478 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800479
Gary Jian76280a42022-12-07 16:18:33 +0800480 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
481
sandeepjsb6c87872021-09-27 15:34:44 +0000482 /**
483 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
484 * one ICCID active at the same time.
485 * Apps should use below API signatures if targeting SDK is T and beyond.
486 *
487 * @hide
488 */
489 @ChangeId
490 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
491 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800492
Naina Nallurid63128d2019-09-17 14:10:30 -0700493 /**
Chen Xu540470b2021-12-14 17:15:47 -0800494 * Apps targeting on Android T and beyond will get exception whenever icc close channel
495 * operation fails.
496 */
497 @ChangeId
498 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
499 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
500
501 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700502 * A request object to use for transmitting data to an ICC.
503 */
504 private static final class IccAPDUArgument {
505 public int channel, cla, command, p1, p2, p3;
506 public String data;
507
508 public IccAPDUArgument(int channel, int cla, int command,
509 int p1, int p2, int p3, String data) {
510 this.channel = channel;
511 this.cla = cla;
512 this.command = command;
513 this.p1 = p1;
514 this.p2 = p2;
515 this.p3 = p3;
516 this.data = data;
517 }
518 }
519
520 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700521 * A request object to use for transmitting data to an ICC.
522 */
523 private static final class ManualNetworkSelectionArgument {
524 public OperatorInfo operatorInfo;
525 public boolean persistSelection;
526
527 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
528 this.operatorInfo = operatorInfo;
529 this.persistSelection = persistSelection;
530 }
531 }
532
Sarah Chin71b3a852022-09-28 15:54:19 -0700533 private static final class PurchasePremiumCapabilityArgument {
534 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700535 public @NonNull IIntegerConsumer callback;
536
537 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800538 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700539 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700540 this.callback = callback;
541 }
542 }
543
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700544 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
546 * request after sending. The main thread will notify the request when it is complete.
547 */
548 private static final class MainThreadRequest {
549 /** The argument to use for the request */
550 public Object argument;
551 /** The result of the request that is run on the main thread */
552 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800553 // The subscriber id that this request applies to. Defaults to
554 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
555 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556
Nathan Harold92bed182018-10-12 18:16:49 -0700557 // In cases where subId is unavailable, the caller needs to specify the phone.
558 public Phone phone;
559
vagdeviaf9a5b92018-08-15 16:01:53 -0700560 public WorkSource workSource;
561
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700562 public MainThreadRequest(Object argument) {
563 this.argument = argument;
564 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800565
Nathan Harold92bed182018-10-12 18:16:49 -0700566 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
567 this.argument = argument;
568 if (phone != null) {
569 this.phone = phone;
570 }
571 this.workSource = workSource;
572 }
573
vagdeviaf9a5b92018-08-15 16:01:53 -0700574 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800575 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800576 if (subId != null) {
577 this.subId = subId;
578 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700579 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 }
582
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800583 private static final class IncomingThirdPartyCallArgs {
584 public final ComponentName component;
585 public final String callId;
586 public final String callerDisplayName;
587
588 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
589 String callerDisplayName) {
590 this.component = component;
591 this.callId = callId;
592 this.callerDisplayName = callerDisplayName;
593 }
594 }
595
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700596 /**
597 * A handler that processes messages on the main thread in the phone process. Since many
598 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
599 * inbound binder threads to the main thread in the phone process. The Binder thread
600 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
601 * on, which will be notified when the operation completes and will contain the result of the
602 * request.
603 *
604 * <p>If a MainThreadRequest object is provided in the msg.obj field,
605 * note that request.result must be set to something non-null for the calling thread to
606 * unblock.
607 */
608 private final class MainThreadHandler extends Handler {
609 @Override
610 public void handleMessage(Message msg) {
611 MainThreadRequest request;
612 Message onCompleted;
613 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000614 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800616 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617
618 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 case CMD_HANDLE_USSD_REQUEST: {
620 request = (MainThreadRequest) msg.obj;
621 final Phone phone = getPhoneFromRequest(request);
622 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800623 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700625
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 if (!isUssdApiAllowed(request.subId)) {
627 // Carrier does not support use of this API, return failure.
628 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
629 UssdResponse response = new UssdResponse(ussdRequest, null);
630 Bundle returnData = new Bundle();
631 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
632 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700633
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 request.result = true;
635 notifyRequester(request);
636 return;
637 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700638
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 try {
640 request.result = phone != null
641 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
642 } catch (CallStateException cse) {
643 request.result = false;
644 }
645 // Wake up the requesting thread
646 notifyRequester(request);
647 break;
pkanwar32d516d2016-10-14 19:37:38 -0700648 }
649
Yorke Lee716f67e2015-06-17 15:39:16 -0700650 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700651 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700652 final Phone phone = getPhoneFromRequest(request);
653 request.result = phone != null ?
654 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
655 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700656 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700658 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700660
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000664 uiccPort = getUiccPortFromRequest(request);
665 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700669 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800671 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000672 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800673 iccArgument.channel, iccArgument.cla, iccArgument.command,
674 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
675 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
682 if (ar.exception == null && ar.result != null) {
683 request.result = ar.result;
684 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800685 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 if (ar.result == null) {
687 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800688 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800690 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 } else {
692 loge("iccTransmitApduLogicalChannel: Unknown exception");
693 }
694 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 break;
697
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
699 request = (MainThreadRequest) msg.obj;
700 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000701 uiccPort = getUiccPortFromRequest(request);
702 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800704 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 } else {
707 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800708 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000709 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800710 iccArgument.cla, iccArgument.command, iccArgument.p1,
711 iccArgument.p2,
712 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700713 }
714 break;
715
716 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
717 ar = (AsyncResult) msg.obj;
718 request = (MainThreadRequest) ar.userObj;
719 if (ar.exception == null && ar.result != null) {
720 request.result = ar.result;
721 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800722 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 if (ar.result == null) {
724 loge("iccTransmitApduBasicChannel: Empty response");
725 } else if (ar.exception instanceof CommandException) {
726 loge("iccTransmitApduBasicChannel: CommandException: " +
727 ar.exception);
728 } else {
729 loge("iccTransmitApduBasicChannel: Unknown exception");
730 }
731 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 break;
734
735 case CMD_EXCHANGE_SIM_IO:
736 request = (MainThreadRequest) msg.obj;
737 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000738 uiccPort = getUiccPortFromRequest(request);
739 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800741 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 } else {
744 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
745 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000746 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700747 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
748 iccArgument.data, onCompleted);
749 }
750 break;
751
752 case EVENT_EXCHANGE_SIM_IO_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 if (ar.exception == null && ar.result != null) {
756 request.result = ar.result;
757 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800758 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700759 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700761 break;
762
Derek Tan4d5e5c12014-02-04 11:54:58 -0800763 case CMD_SEND_ENVELOPE:
764 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000765 uiccPort = getUiccPortFromRequest(request);
766 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700767 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800768 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700770 } else {
771 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800772 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700773 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800774 break;
775
776 case EVENT_SEND_ENVELOPE_DONE:
777 ar = (AsyncResult) msg.obj;
778 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700779 if (ar.exception == null && ar.result != null) {
780 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800781 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800782 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700783 if (ar.result == null) {
784 loge("sendEnvelopeWithStatus: Empty response");
785 } else if (ar.exception instanceof CommandException) {
786 loge("sendEnvelopeWithStatus: CommandException: " +
787 ar.exception);
788 } else {
789 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
790 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800791 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700792 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800793 break;
794
Shishir Agrawal566b7612013-10-28 14:41:00 -0700795 case CMD_OPEN_CHANNEL:
796 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000797 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800798 IccLogicalChannelRequest openChannelRequest =
799 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000800 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700801 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800802 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800803 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700804 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700805 } else {
806 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800807 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
808 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700809 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700810 break;
811
812 case EVENT_OPEN_CHANNEL_DONE:
813 ar = (AsyncResult) msg.obj;
814 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700815 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700816 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700817 int[] result = (int[]) ar.result;
818 int channelId = result[0];
819 byte[] selectResponse = null;
820 if (result.length > 1) {
821 selectResponse = new byte[result.length - 1];
822 for (int i = 1; i < result.length; ++i) {
823 selectResponse[i - 1] = (byte) result[i];
824 }
825 }
826 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800827 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800828
829 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700830 if (uiccPort == null) {
831 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
832 } else {
833 IccLogicalChannelRequest channelRequest =
834 (IccLogicalChannelRequest) request.argument;
835 channelRequest.channel = channelId;
836 uiccPort.onLogicalChannelOpened(channelRequest);
837 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700838 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 if (ar.result == null) {
840 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700842 if (ar.exception != null) {
843 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
844 }
845
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700846 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700847 if (ar.exception instanceof CommandException) {
848 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800849 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700850 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700851 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700852 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700853 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700854 }
855 }
856 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800857 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700858 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700859 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700860 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700861 break;
862
863 case CMD_CLOSE_CHANNEL:
864 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000865 uiccPort = getUiccPortFromRequest(request);
866 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700867 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800868 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800869 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800870 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700871 } else {
872 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000873 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700874 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700875 break;
876
877 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null) {
881 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800882 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700883 if (uiccPort == null) {
884 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
885 } else {
886 final int channelId = (Integer) request.argument;
887 uiccPort.onLogicalChannelClosed(channelId);
888 }
Chen Xu540470b2021-12-14 17:15:47 -0800889 } else {
890 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800891 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800892 if (ar.exception instanceof CommandException) {
893 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
894 CommandException.Error error =
895 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800896 if (error == CommandException.Error.INVALID_ARGUMENTS) {
897 // should only throw exceptions from the binder threads.
898 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800899 "iccCloseLogicalChannel: invalid argument ");
900 }
901 } else {
902 loge("iccCloseLogicalChannel: Unknown exception");
903 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800904 request.result = (exception != null) ? exception :
905 new IllegalStateException(
906 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800907 }
908 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800909 break;
910
911 case CMD_NV_READ_ITEM:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800914 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
915 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800916 break;
917
918 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800921 if (ar.exception == null && ar.result != null) {
922 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700923 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800924 request.result = "";
925 if (ar.result == null) {
926 loge("nvReadItem: Empty response");
927 } else if (ar.exception instanceof CommandException) {
928 loge("nvReadItem: CommandException: " +
929 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700930 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800931 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700932 }
933 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700934 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700935 break;
936
Jake Hambye994d462014-02-03 13:10:13 -0800937 case CMD_NV_WRITE_ITEM:
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
940 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800941 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700942 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800943 break;
944
945 case EVENT_NV_WRITE_ITEM_DONE:
946 handleNullReturnEvent(msg, "nvWriteItem");
947 break;
948
949 case CMD_NV_WRITE_CDMA_PRL:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800952 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800953 break;
954
955 case EVENT_NV_WRITE_CDMA_PRL_DONE:
956 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
957 break;
958
chen xu6dac5ab2018-10-26 17:39:23 -0700959 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800960 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700961 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800962 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800963 break;
964
chen xu6dac5ab2018-10-26 17:39:23 -0700965 case EVENT_RESET_MODEM_CONFIG_DONE:
966 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800967 break;
968
Sooraj Sasindran37444802020-08-11 10:40:43 -0700969 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
972 request);
973 Phone phone = getPhoneFromRequest(request);
974 if (phone != null) {
975 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
976 } else {
977 loge("isNRDualConnectivityEnabled: No phone object");
978 request.result = false;
979 notifyRequester(request);
980 }
981 break;
982 }
983
984 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception == null && ar.result != null) {
988 request.result = ar.result;
989 } else {
990 // request.result must be set to something non-null
991 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700992 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700993 request.result = ar.result;
994 } else {
995 request.result = false;
996 }
997 if (ar.result == null) {
998 loge("isNRDualConnectivityEnabled: Empty response");
999 } else if (ar.exception instanceof CommandException) {
1000 loge("isNRDualConnectivityEnabled: CommandException: "
1001 + ar.exception);
1002 } else {
1003 loge("isNRDualConnectivityEnabled: Unknown exception");
1004 }
1005 }
1006 notifyRequester(request);
1007 break;
1008
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001009 case CMD_IS_VONR_ENABLED: {
1010 request = (MainThreadRequest) msg.obj;
1011 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1012 request);
1013 Phone phone = getPhoneFromRequest(request);
1014 if (phone != null) {
1015 phone.isVoNrEnabled(onCompleted, request.workSource);
1016 } else {
1017 loge("isVoNrEnabled: No phone object");
1018 request.result = false;
1019 notifyRequester(request);
1020 }
1021 break;
1022 }
1023
1024 case EVENT_IS_VONR_ENABLED_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception == null && ar.result != null) {
1028 request.result = ar.result;
1029 } else {
1030 // request.result must be set to something non-null
1031 // for the calling thread to unblock
1032 if (ar.result != null) {
1033 request.result = ar.result;
1034 } else {
1035 request.result = false;
1036 }
1037 if (ar.result == null) {
1038 loge("isVoNrEnabled: Empty response");
1039 } else if (ar.exception instanceof CommandException) {
1040 loge("isVoNrEnabled: CommandException: "
1041 + ar.exception);
1042 } else {
1043 loge("isVoNrEnabled: Unknown exception");
1044 }
1045 }
1046 notifyRequester(request);
1047 break;
1048
Sooraj Sasindran37444802020-08-11 10:40:43 -07001049 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1052 Phone phone = getPhoneFromRequest(request);
1053 if (phone != null) {
1054 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1055 request.workSource);
1056 } else {
1057 loge("enableNrDualConnectivity: No phone object");
1058 request.result =
1059 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1060 notifyRequester(request);
1061 }
1062 break;
1063 }
1064
1065 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 if (ar.exception == null) {
1069 request.result =
1070 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1071 } else {
1072 request.result =
1073 TelephonyManager
1074 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1075 if (ar.exception instanceof CommandException) {
1076 CommandException.Error error =
1077 ((CommandException) (ar.exception)).getCommandError();
1078 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1079 request.result =
1080 TelephonyManager
1081 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001082 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1083 request.result =
1084 TelephonyManager
1085 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001086 }
1087 loge("enableNrDualConnectivity" + ": CommandException: "
1088 + ar.exception);
1089 } else {
1090 loge("enableNrDualConnectivity" + ": Unknown exception");
1091 }
1092 }
1093 notifyRequester(request);
1094 break;
1095 }
1096
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001097 case CMD_ENABLE_VONR: {
1098 request = (MainThreadRequest) msg.obj;
1099 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1100 Phone phone = getPhoneFromRequest(request);
1101 if (phone != null) {
1102 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1103 request.workSource);
1104 } else {
1105 loge("setVoNrEnabled: No phone object");
1106 request.result =
1107 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1108 notifyRequester(request);
1109 }
1110 break;
1111 }
1112
1113 case EVENT_ENABLE_VONR_DONE: {
1114 ar = (AsyncResult) msg.obj;
1115 request = (MainThreadRequest) ar.userObj;
1116 if (ar.exception == null) {
1117 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1118 } else {
1119 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1120 if (ar.exception instanceof CommandException) {
1121 CommandException.Error error =
1122 ((CommandException) (ar.exception)).getCommandError();
1123 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1124 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1125 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1126 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1127 } else {
1128 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1129 }
1130 loge("setVoNrEnabled" + ": CommandException: "
1131 + ar.exception);
1132 } else {
1133 loge("setVoNrEnabled" + ": Unknown exception");
1134 }
1135 }
1136 notifyRequester(request);
1137 break;
1138 }
1139
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1143 request);
1144 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001145 break;
1146
SongFerngWang3ef3e072020-12-21 16:41:52 +08001147 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001148 ar = (AsyncResult) msg.obj;
1149 request = (MainThreadRequest) ar.userObj;
1150 if (ar.exception == null && ar.result != null) {
1151 request.result = ar.result; // Integer
1152 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301153 // request.result must be set to something non-null
1154 // for the calling thread to unblock
1155 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001157 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001159 loge("getAllowedNetworkTypesBitmask: CommandException: "
1160 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001162 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001163 }
1164 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001165 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001166 break;
1167
SongFerngWang3ef3e072020-12-21 16:41:52 +08001168 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001169 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001170 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1171 request);
1172 Pair<Integer, Long> reasonWithNetworkTypes =
1173 (Pair<Integer, Long>) request.argument;
1174 getPhoneFromRequest(request).setAllowedNetworkTypes(
1175 reasonWithNetworkTypes.first,
1176 reasonWithNetworkTypes.second,
1177 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001178 break;
1179
SongFerngWang3ef3e072020-12-21 16:41:52 +08001180 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1181 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001182 break;
1183
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001184 case CMD_SET_VOICEMAIL_NUMBER:
1185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1187 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001188 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1189 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001190 break;
1191
1192 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1193 handleNullReturnEvent(msg, "setVoicemailNumber");
1194 break;
1195
Stuart Scott54788802015-03-30 13:18:01 -07001196 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1197 request = (MainThreadRequest) msg.obj;
1198 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1199 request);
1200 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1201 break;
1202
1203 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1204 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1205 break;
1206
Shishir Agrawal302c8692015-06-19 13:49:39 -07001207 case CMD_PERFORM_NETWORK_SCAN:
1208 request = (MainThreadRequest) msg.obj;
1209 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1210 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1211 break;
1212
Hall Liu27d24262020-09-18 19:04:59 -07001213 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001214 request = (MainThreadRequest) msg.obj;
1215 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001216 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1217 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1218 request.argument;
1219 int callForwardingReason = args.first;
1220 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001221 break;
Hall Liu27d24262020-09-18 19:04:59 -07001222 }
1223 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001224 ar = (AsyncResult) msg.obj;
1225 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001226 TelephonyManager.CallForwardingInfoCallback callback =
1227 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1228 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001229 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001230 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001231 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1232 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1233 // Service Class is a bit mask per 3gpp 27.007. Search for
1234 // any service for voice call.
1235 if ((callForwardInfo.serviceClass
1236 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001237 callForwardingInfo = new CallForwardingInfo(
1238 callForwardInfo.status
1239 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001240 callForwardInfo.reason,
1241 callForwardInfo.number,
1242 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001243 break;
1244 }
1245 }
1246 // Didn't find a call forward info for voice call.
1247 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001248 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1249 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001250 }
Hall Liu27d24262020-09-18 19:04:59 -07001251 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001252 } else {
1253 if (ar.result == null) {
1254 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1255 }
1256 if (ar.exception != null) {
1257 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1258 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001259 int errorCode = TelephonyManager
1260 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001261 if (ar.exception instanceof CommandException) {
1262 CommandException.Error error =
1263 ((CommandException) (ar.exception)).getCommandError();
1264 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001265 errorCode = TelephonyManager
1266 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001267 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001268 errorCode = TelephonyManager
1269 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001270 }
1271 }
Hall Liu27d24262020-09-18 19:04:59 -07001272 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001273 }
Shuo Qian4a594052020-01-23 11:59:30 -08001274 break;
Hall Liu27d24262020-09-18 19:04:59 -07001275 }
Shuo Qian4a594052020-01-23 11:59:30 -08001276
Hall Liu27d24262020-09-18 19:04:59 -07001277 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001278 request = (MainThreadRequest) msg.obj;
1279 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001280 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001281 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001282 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1283 request.argument).first;
1284 request.phone.setCallForwardingOption(
1285 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001286 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001287 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001288 callForwardingInfoToSet.getReason(),
1289 callForwardingInfoToSet.getNumber(),
1290 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1291 break;
Hall Liu27d24262020-09-18 19:04:59 -07001292 }
Shuo Qian4a594052020-01-23 11:59:30 -08001293
Hall Liu27d24262020-09-18 19:04:59 -07001294 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001295 ar = (AsyncResult) msg.obj;
1296 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001297 Consumer<Integer> callback =
1298 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1299 request.argument).second;
1300 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001301 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001302 int errorCode = TelephonyManager.CallForwardingInfoCallback
1303 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001304 if (ar.exception instanceof CommandException) {
1305 CommandException.Error error =
1306 ((CommandException) (ar.exception)).getCommandError();
1307 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001308 errorCode = TelephonyManager.CallForwardingInfoCallback
1309 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001310 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001311 errorCode = TelephonyManager.CallForwardingInfoCallback
1312 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001313 }
1314 }
1315 callback.accept(errorCode);
1316 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001317 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001318 }
Shuo Qian4a594052020-01-23 11:59:30 -08001319 break;
Hall Liu27d24262020-09-18 19:04:59 -07001320 }
Shuo Qian4a594052020-01-23 11:59:30 -08001321
Hall Liu27d24262020-09-18 19:04:59 -07001322 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001323 request = (MainThreadRequest) msg.obj;
1324 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1325 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1326 break;
Hall Liu27d24262020-09-18 19:04:59 -07001327 }
Shuo Qian4a594052020-01-23 11:59:30 -08001328
Hall Liu27d24262020-09-18 19:04:59 -07001329 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001332 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001334 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001335 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001336 // Service Class is a bit mask per 3gpp 27.007.
1337 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001338 if (callForwardResults.length > 1
1339 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001340 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001341 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001342 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1343 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001344 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001345 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001346 }
1347 } else {
1348 if (ar.result == null) {
1349 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1350 }
1351 if (ar.exception != null) {
1352 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1353 }
1354 if (ar.exception instanceof CommandException) {
1355 CommandException.Error error =
1356 ((CommandException) (ar.exception)).getCommandError();
1357 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001358 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001359 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001360 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1361 callWaitingStatus =
1362 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001363 }
1364 }
1365 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001366 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001367 break;
Hall Liu27d24262020-09-18 19:04:59 -07001368 }
Shuo Qian4a594052020-01-23 11:59:30 -08001369
Hall Liu27d24262020-09-18 19:04:59 -07001370 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001371 request = (MainThreadRequest) msg.obj;
1372 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001373 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1374 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001375 break;
Hall Liu27d24262020-09-18 19:04:59 -07001376 }
Shuo Qian4a594052020-01-23 11:59:30 -08001377
Hall Liu27d24262020-09-18 19:04:59 -07001378 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001379 ar = (AsyncResult) msg.obj;
1380 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001381 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1382 Consumer<Integer> callback =
1383 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1384 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001385 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001386 if (ar.exception instanceof CommandException) {
1387 CommandException.Error error =
1388 ((CommandException) (ar.exception)).getCommandError();
1389 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1390 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001391 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1392 callback.accept(
1393 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001394 } else {
1395 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1396 }
1397 } else {
1398 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1399 }
1400 } else {
1401 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1402 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001403 }
Shuo Qian4a594052020-01-23 11:59:30 -08001404 break;
Hall Liu27d24262020-09-18 19:04:59 -07001405 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001406 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
1409 CellNetworkScanResult cellScanResult;
1410 if (ar.exception == null && ar.result != null) {
1411 cellScanResult = new CellNetworkScanResult(
1412 CellNetworkScanResult.STATUS_SUCCESS,
1413 (List<OperatorInfo>) ar.result);
1414 } else {
1415 if (ar.result == null) {
1416 loge("getCellNetworkScanResults: Empty response");
1417 }
1418 if (ar.exception != null) {
1419 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1420 }
1421 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1422 if (ar.exception instanceof CommandException) {
1423 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001424 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001425 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1426 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1427 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1428 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1429 }
1430 }
1431 cellScanResult = new CellNetworkScanResult(errorCode, null);
1432 }
1433 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001434 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001435 break;
1436
1437 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1438 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001439 ManualNetworkSelectionArgument selArg =
1440 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001441 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1442 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001443 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1444 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001445 break;
1446
1447 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null) {
1451 request.result = true;
1452 } else {
1453 request.result = false;
1454 loge("setNetworkSelectionModeManual " + ar.exception);
1455 }
1456 notifyRequester(request);
1457 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001458 break;
1459
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001460 case CMD_GET_MODEM_ACTIVITY_INFO:
1461 request = (MainThreadRequest) msg.obj;
1462 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001463 if (defaultPhone != null) {
1464 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 } else {
1466 ResultReceiver result = (ResultReceiver) request.argument;
1467 Bundle bundle = new Bundle();
1468 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001469 new ModemActivityInfo(0, 0, 0,
1470 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001471 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001472 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001473 break;
1474
Hall Liud0f208c2020-10-14 16:54:44 -07001475 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001476 ar = (AsyncResult) msg.obj;
1477 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001478 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001479 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001480 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001481 if (mLastModemActivityInfo == null) {
1482 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1483 mLastModemActivitySpecificInfo[0] =
1484 new ActivityStatsTechSpecificInfo(
1485 0,
1486 0,
1487 new int[ModemActivityInfo.getNumTxPowerLevels()],
1488 0);
1489 mLastModemActivityInfo =
1490 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1491 }
1492
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001493 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001494 // Update the last modem activity info and the result of the request.
1495 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1496 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001497 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001498 } else {
1499 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001500 }
Kai Shi917fdc62022-11-28 14:01:02 -08001501 // This is needed to decouple ret from mLastModemActivityInfo
1502 // We don't want to return mLastModemActivityInfo which is updated
1503 // inside mergeModemActivityInfo()
1504 ret = new ModemActivityInfo(
1505 mLastModemActivityInfo.getTimestampMillis(),
1506 mLastModemActivityInfo.getSleepTimeMillis(),
1507 mLastModemActivityInfo.getIdleTimeMillis(),
1508 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001509
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 } else {
1511 if (ar.result == null) {
1512 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001513 error = TelephonyManager.ModemActivityInfoException
1514 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001515 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001516 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001517 error = TelephonyManager.ModemActivityInfoException
1518 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001519 } else {
1520 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001521 error = TelephonyManager.ModemActivityInfoException
1522 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001523 }
1524 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001525 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001526 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001527 bundle.putParcelable(
1528 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001529 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001530 } else {
1531 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1532 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001533 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001534 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001535 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001536 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001537
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001538 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001539 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001540 CarrierRestrictionRules argument =
1541 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001542 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001543 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001545 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001546
1547 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 if (ar.exception == null && ar.result != null) {
1551 request.result = ar.result;
1552 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001553 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1554 if (ar.exception instanceof CommandException) {
1555 loge("setAllowedCarriers: CommandException: " + ar.exception);
1556 CommandException.Error error =
1557 ((CommandException) (ar.exception)).getCommandError();
1558 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1559 request.result =
1560 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1561 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001562 } else {
1563 loge("setAllowedCarriers: Unknown exception");
1564 }
1565 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001566 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001567 break;
1568
1569 case CMD_GET_ALLOWED_CARRIERS:
1570 request = (MainThreadRequest) msg.obj;
1571 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001572 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001573 break;
1574
1575 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1576 ar = (AsyncResult) msg.obj;
1577 request = (MainThreadRequest) ar.userObj;
1578 if (ar.exception == null && ar.result != null) {
1579 request.result = ar.result;
1580 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001581 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001582 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001583 if (ar.result == null) {
1584 loge("getAllowedCarriers: Empty response");
1585 } else if (ar.exception instanceof CommandException) {
1586 loge("getAllowedCarriers: CommandException: " +
1587 ar.exception);
1588 } else {
1589 loge("getAllowedCarriers: Unknown exception");
1590 }
1591 }
arunvoddud7401012022-12-15 16:08:12 +00001592 if (request.argument != null) {
1593 // This is for the implementation of carrierRestrictionStatus.
1594 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1595 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001596 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001597 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1598 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1599 CarrierRestrictionRules carrierRestrictionRules =
1600 (CarrierRestrictionRules) ar.result;
1601 int carrierId = -1;
1602 try {
1603 CarrierIdentifier carrierIdentifier =
1604 carrierRestrictionRules.getAllowedCarriers().get(0);
1605 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1606 carrierIdentifier);
1607 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1608 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1609 }
1610 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001611 int restrictedStatus =
1612 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1613 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1614 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001615 lockStatus = TelephonyManager
1616 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001617 }
1618 } else {
1619 Rlog.e(LOG_TAG,
1620 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1621 }
1622 callback.accept(lockStatus);
1623 } else {
1624 // This is for the implementation of getAllowedCarriers.
1625 notifyRequester(request);
1626 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001627 break;
1628
Nathan Haroldb3014052017-01-25 15:57:32 -08001629 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1630 ar = (AsyncResult) msg.obj;
1631 request = (MainThreadRequest) ar.userObj;
1632 if (ar.exception == null && ar.result != null) {
1633 request.result = ar.result;
1634 } else {
1635 request.result = new IllegalArgumentException(
1636 "Failed to retrieve Forbidden Plmns");
1637 if (ar.result == null) {
1638 loge("getForbiddenPlmns: Empty response");
1639 } else {
1640 loge("getForbiddenPlmns: Unknown exception");
1641 }
1642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001643 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001644 break;
1645
1646 case CMD_GET_FORBIDDEN_PLMNS:
1647 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001648 uiccPort = getUiccPortFromRequest(request);
1649 if (uiccPort == null) {
1650 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001651 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001652 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001653 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001654 break;
1655 }
1656 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001657 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001658 if (uiccApp == null) {
1659 loge("getForbiddenPlmns() no app with specified type -- "
1660 + appType);
1661 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001662 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001663 break;
1664 } else {
1665 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1666 + " specified type -- " + appType);
1667 }
1668 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1669 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001670 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001671 break;
1672
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001673 case CMD_SWITCH_SLOTS:
1674 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001675 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001676 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001677 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001678 break;
1679
1680 case EVENT_SWITCH_SLOTS_DONE:
1681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001684 notifyRequester(request);
1685 break;
1686 case CMD_GET_NETWORK_SELECTION_MODE:
1687 request = (MainThreadRequest) msg.obj;
1688 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1689 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1690 break;
1691
1692 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1693 ar = (AsyncResult) msg.obj;
1694 request = (MainThreadRequest) ar.userObj;
1695 if (ar.exception != null) {
1696 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1697 } else {
1698 int mode = ((int[]) ar.result)[0];
1699 if (mode == 0) {
1700 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1701 } else {
1702 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1703 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001705 notifyRequester(request);
1706 break;
1707 case CMD_GET_CDMA_ROAMING_MODE:
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1710 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1711 break;
1712 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 if (ar.exception != null) {
1716 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1717 } else {
1718 request.result = ((int[]) ar.result)[0];
1719 }
1720 notifyRequester(request);
1721 break;
1722 case CMD_SET_CDMA_ROAMING_MODE:
1723 request = (MainThreadRequest) msg.obj;
1724 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1725 int mode = (int) request.argument;
1726 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1727 break;
1728 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731 request.result = ar.exception == null;
1732 notifyRequester(request);
1733 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001734 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1735 request = (MainThreadRequest) msg.obj;
1736 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1737 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1738 break;
1739 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1740 ar = (AsyncResult) msg.obj;
1741 request = (MainThreadRequest) ar.userObj;
1742 if (ar.exception != null) {
1743 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1744 } else {
1745 request.result = ((int[]) ar.result)[0];
1746 }
1747 notifyRequester(request);
1748 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001749 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1750 request = (MainThreadRequest) msg.obj;
1751 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1752 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001753 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1754 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001755 break;
1756 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
1759 request.result = ar.exception == null;
1760 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001761 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001762 case CMD_GET_ALL_CELL_INFO:
1763 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001764 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001765 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001766 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001767 case EVENT_GET_ALL_CELL_INFO_DONE:
1768 ar = (AsyncResult) msg.obj;
1769 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001770 // If a timeout occurs, the response will be null
1771 request.result = (ar.exception == null && ar.result != null)
1772 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001773 synchronized (request) {
1774 request.notifyAll();
1775 }
1776 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001777 case CMD_REQUEST_CELL_INFO_UPDATE:
1778 request = (MainThreadRequest) msg.obj;
1779 request.phone.requestCellInfoUpdate(request.workSource,
1780 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1781 break;
1782 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1783 ar = (AsyncResult) msg.obj;
1784 request = (MainThreadRequest) ar.userObj;
1785 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1786 try {
1787 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001788 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001789 cb.onError(
1790 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1791 ar.exception.getClass().getName(),
1792 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001793 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001794 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001795 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001796 } else {
1797 // use the result as returned
1798 cb.onCellInfo((List<CellInfo>) ar.result);
1799 }
1800 } catch (RemoteException re) {
1801 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1802 }
1803 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001804 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 request = (MainThreadRequest) msg.obj;
1806 WorkSource ws = (WorkSource) request.argument;
1807 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001808 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001809 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001810 }
1811 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001812 ar = (AsyncResult) msg.obj;
1813 request = (MainThreadRequest) ar.userObj;
1814 if (ar.exception == null) {
1815 request.result = ar.result;
1816 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001817 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001818 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001819 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001820 }
1821
1822 synchronized (request) {
1823 request.notifyAll();
1824 }
1825 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001826 }
chen xu6dac5ab2018-10-26 17:39:23 -07001827 case CMD_MODEM_REBOOT:
1828 request = (MainThreadRequest) msg.obj;
1829 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001830 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001831 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001832 case EVENT_CMD_MODEM_REBOOT_DONE:
1833 handleNullReturnEvent(msg, "rebootModem");
1834 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001835 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001836 request = (MainThreadRequest) msg.obj;
1837 boolean enable = (boolean) request.argument;
1838 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001839 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001840 PhoneConfigurationManager.getInstance()
1841 .enablePhone(request.phone, enable, onCompleted);
1842 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001843 }
Michele Berionne5e411512020-11-13 02:36:59 +00001844 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001845 ar = (AsyncResult) msg.obj;
1846 request = (MainThreadRequest) ar.userObj;
1847 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001848 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001849 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001850 if ((boolean) request.result) {
1851 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1852 updateModemStateMetrics();
1853 } else {
1854 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1855 + ar.exception);
1856 }
1857 notifyRequester(request);
1858 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001859 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001860 case CMD_GET_MODEM_STATUS:
1861 request = (MainThreadRequest) msg.obj;
1862 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1863 PhoneConfigurationManager.getInstance()
1864 .getPhoneStatusFromModem(request.phone, onCompleted);
1865 break;
1866 case EVENT_GET_MODEM_STATUS_DONE:
1867 ar = (AsyncResult) msg.obj;
1868 request = (MainThreadRequest) ar.userObj;
1869 int id = request.phone.getPhoneId();
1870 if (ar.exception == null && ar.result != null) {
1871 request.result = ar.result;
1872 //update the cache as modem status has changed
1873 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1874 (boolean) request.result);
1875 } else {
1876 // Return true if modem status cannot be retrieved. For most cases,
1877 // modem status is on. And for older version modems, GET_MODEM_STATUS
1878 // and disable modem are not supported. Modem is always on.
1879 // TODO: this should be fixed in R to support a third
1880 // status UNKNOWN b/131631629
1881 request.result = true;
1882 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1883 + ar.exception);
1884 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001885 notifyRequester(request);
1886 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001887 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1888 request = (MainThreadRequest) msg.obj;
1889 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1890 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1891 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1892 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1893 break;
1894 }
1895 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1896 ar = (AsyncResult) msg.obj;
1897 request = (MainThreadRequest) ar.userObj;
1898 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1899 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1900 args.second.accept(ar.exception == null);
1901 notifyRequester(request);
1902 break;
1903 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001904 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1905 request = (MainThreadRequest) msg.obj;
1906 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1907 Phone phone = getPhoneFromRequest(request);
1908 if (phone != null) {
1909 phone.getSystemSelectionChannels(onCompleted);
1910 } else {
1911 loge("getSystemSelectionChannels: No phone object");
1912 request.result = new ArrayList<RadioAccessSpecifier>();
1913 notifyRequester(request);
1914 }
1915 break;
1916 }
1917 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1918 ar = (AsyncResult) msg.obj;
1919 request = (MainThreadRequest) ar.userObj;
1920 if (ar.exception == null && ar.result != null) {
1921 request.result = ar.result;
1922 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001923 request.result = new IllegalStateException(
1924 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001925 if (ar.result == null) {
1926 loge("getSystemSelectionChannels: Empty response");
1927 } else {
1928 loge("getSystemSelectionChannels: Unknown exception");
1929 }
1930 }
1931 notifyRequester(request);
1932 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001933 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1934 ar = (AsyncResult) msg.obj;
1935 request = (MainThreadRequest) ar.userObj;
1936 if (ar.exception == null && ar.result != null) {
1937 request.result = ar.result;
1938 } else {
1939 request.result = -1;
1940 loge("Failed to set Forbidden Plmns");
1941 if (ar.result == null) {
1942 loge("setForbidenPlmns: Empty response");
1943 } else if (ar.exception != null) {
1944 loge("setForbiddenPlmns: Exception: " + ar.exception);
1945 request.result = -1;
1946 } else {
1947 loge("setForbiddenPlmns: Unknown exception");
1948 }
1949 }
1950 notifyRequester(request);
1951 break;
1952 case CMD_SET_FORBIDDEN_PLMNS:
1953 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001954 uiccPort = getUiccPortFromRequest(request);
1955 if (uiccPort == null) {
1956 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001957 request.result = -1;
1958 notifyRequester(request);
1959 break;
1960 }
1961 Pair<Integer, List<String>> setFplmnsArgs =
1962 (Pair<Integer, List<String>>) request.argument;
1963 appType = setFplmnsArgs.first;
1964 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001965 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001966 if (uiccApp == null) {
1967 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1968 request.result = -1;
1969 loge("Failed to get UICC App");
1970 notifyRequester(request);
1971 } else {
1972 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1973 ((SIMRecords) uiccApp.getIccRecords())
1974 .setForbiddenPlmns(onCompleted, fplmns);
1975 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001976 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001977 case CMD_ERASE_MODEM_CONFIG:
1978 request = (MainThreadRequest) msg.obj;
1979 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1980 defaultPhone.eraseModemConfig(onCompleted);
1981 break;
1982 case EVENT_ERASE_MODEM_CONFIG_DONE:
1983 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001984 break;
zoey chene02881a2019-12-30 16:11:23 +08001985
Kai Shif70f46f2021-03-03 13:59:46 -08001986 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1987 request = (MainThreadRequest) msg.obj;
1988 request.result = defaultPhone.eraseDataInSharedPreferences();
1989 notifyRequester(request);
1990 break;
1991
zoey chene02881a2019-12-30 16:11:23 +08001992 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1993 request = (MainThreadRequest) msg.obj;
1994 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1995 Pair<String, String> changed = (Pair<String, String>) request.argument;
1996 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1997 changed.first, changed.second, onCompleted);
1998 break;
1999 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2000 ar = (AsyncResult) msg.obj;
2001 request = (MainThreadRequest) ar.userObj;
2002 if (ar.exception == null) {
2003 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002004 // If the operation is successful, update the PIN storage
2005 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2006 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002007 UiccController.getInstance().getPinStorage()
2008 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002009 } else {
2010 request.result = msg.arg1;
2011 }
2012 notifyRequester(request);
2013 break;
2014
Michele Berionne5e411512020-11-13 02:36:59 +00002015 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002016 request = (MainThreadRequest) msg.obj;
2017 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2018 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2019 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2020 enabled.first, enabled.second, onCompleted);
2021 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002022 }
zoey chene02881a2019-12-30 16:11:23 +08002023 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2024 ar = (AsyncResult) msg.obj;
2025 request = (MainThreadRequest) ar.userObj;
2026 if (ar.exception == null) {
2027 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002028 // If the operation is successful, update the PIN storage
2029 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2030 int phoneId = getPhoneFromRequest(request).getPhoneId();
2031 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002032 UiccController.getInstance().getPinStorage()
2033 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002034 } else {
2035 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2036 }
zoey chene02881a2019-12-30 16:11:23 +08002037 } else {
2038 request.result = msg.arg1;
2039 }
Michele Berionne5e411512020-11-13 02:36:59 +00002040
2041
zoey chene02881a2019-12-30 16:11:23 +08002042 notifyRequester(request);
2043 break;
2044
Peter Wangdafb9ac2020-01-15 14:13:38 -08002045 case MSG_NOTIFY_USER_ACTIVITY:
2046 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002047 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002048 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2049 getDefaultPhone().getContext().sendBroadcastAsUser(
2050 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2051 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002052
2053 case CMD_SET_DATA_THROTTLING: {
2054 request = (MainThreadRequest) msg.obj;
2055 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2056 DataThrottlingRequest dataThrottlingRequest =
2057 (DataThrottlingRequest) request.argument;
2058 Phone phone = getPhoneFromRequest(request);
2059 if (phone != null) {
2060 phone.setDataThrottling(onCompleted,
2061 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2062 dataThrottlingRequest.getCompletionDurationMillis());
2063 } else {
2064 loge("setDataThrottling: No phone object");
2065 request.result =
2066 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2067 notifyRequester(request);
2068 }
2069
2070 break;
2071 }
2072 case EVENT_SET_DATA_THROTTLING_DONE:
2073 ar = (AsyncResult) msg.obj;
2074 request = (MainThreadRequest) ar.userObj;
2075
2076 if (ar.exception == null) {
2077 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2078 } else if (ar.exception instanceof CommandException) {
2079 loge("setDataThrottling: CommandException: " + ar.exception);
2080 CommandException.Error error =
2081 ((CommandException) (ar.exception)).getCommandError();
2082
2083 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2084 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002085 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002086 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2087 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002088 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2089 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002090 } else {
2091 request.result =
2092 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2093 }
2094 } else {
2095 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2096 }
2097 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2098 notifyRequester(request);
2099 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002100
2101 case CMD_SET_SIM_POWER: {
2102 request = (MainThreadRequest) msg.obj;
2103 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2104 request = (MainThreadRequest) msg.obj;
2105 int stateToSet =
2106 ((Pair<Integer, IIntegerConsumer>)
2107 request.argument).first;
2108 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2109 break;
2110 }
2111 case EVENT_SET_SIM_POWER_DONE: {
2112 ar = (AsyncResult) msg.obj;
2113 request = (MainThreadRequest) ar.userObj;
2114 IIntegerConsumer callback =
2115 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2116 if (ar.exception != null) {
2117 loge("setSimPower exception: " + ar.exception);
2118 int errorCode = TelephonyManager.CallForwardingInfoCallback
2119 .RESULT_ERROR_UNKNOWN;
2120 if (ar.exception instanceof CommandException) {
2121 CommandException.Error error =
2122 ((CommandException) (ar.exception)).getCommandError();
2123 if (error == CommandException.Error.SIM_ERR) {
2124 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2125 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2126 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2127 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2128 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2129 } else {
2130 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2131 }
2132 }
2133 try {
2134 callback.accept(errorCode);
2135 } catch (RemoteException e) {
2136 // Ignore if the remote process is no longer available to call back.
2137 Log.w(LOG_TAG, "setSimPower: callback not available.");
2138 }
2139 } else {
2140 try {
2141 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2142 } catch (RemoteException e) {
2143 // Ignore if the remote process is no longer available to call back.
2144 Log.w(LOG_TAG, "setSimPower: callback not available.");
2145 }
2146 }
2147 break;
2148 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002149 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2150 request = (MainThreadRequest) msg.obj;
2151
2152 final Phone phone = getPhoneFromRequest(request);
2153 if (phone == null || phone.getServiceStateTracker() == null) {
2154 request.result = new IllegalStateException("Phone or SST is null");
2155 notifyRequester(request);
2156 break;
2157 }
2158
2159 Pair<Integer, SignalStrengthUpdateRequest> pair =
2160 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2161 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2162 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002163 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002164 request.subId, pair.first /*callingUid*/,
2165 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002166 break;
2167 }
2168 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2169 ar = (AsyncResult) msg.obj;
2170 request = (MainThreadRequest) ar.userObj;
2171 // request.result will be the exception of ar if present, true otherwise.
2172 // Be cautious not to leave result null which will wait() forever
2173 request.result = ar.exception != null ? ar.exception : true;
2174 notifyRequester(request);
2175 break;
2176 }
2177 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2178 request = (MainThreadRequest) msg.obj;
2179
2180 Phone phone = getPhoneFromRequest(request);
2181 if (phone == null || phone.getServiceStateTracker() == null) {
2182 request.result = new IllegalStateException("Phone or SST is null");
2183 notifyRequester(request);
2184 break;
2185 }
2186
2187 Pair<Integer, SignalStrengthUpdateRequest> pair =
2188 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2189 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2190 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002191 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002192 request.subId, pair.first /*callingUid*/,
2193 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002194 break;
2195 }
2196 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2197 ar = (AsyncResult) msg.obj;
2198 request = (MainThreadRequest) ar.userObj;
2199 request.result = ar.exception != null ? ar.exception : true;
2200 notifyRequester(request);
2201 break;
2202 }
Jordan Liu109698e2020-11-24 14:50:34 -08002203
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002204 case CMD_GET_SLICING_CONFIG: {
2205 request = (MainThreadRequest) msg.obj;
2206 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2207 request.phone.getSlicingConfig(onCompleted);
2208 break;
2209 }
2210 case EVENT_GET_SLICING_CONFIG_DONE: {
2211 ar = (AsyncResult) msg.obj;
2212 request = (MainThreadRequest) ar.userObj;
2213 ResultReceiver result = (ResultReceiver) request.argument;
2214
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002215 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002216 Bundle bundle = new Bundle();
2217 int resultCode = 0;
2218 if (ar.exception != null) {
2219 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2220 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002221 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002222 } else if (ar.result == null) {
2223 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002224 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002225 } else {
2226 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002227 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2228 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002229 }
2230
2231 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002232 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002233 }
2234 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2235 result.send(resultCode, bundle);
2236 notifyRequester(request);
2237 break;
2238 }
2239
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241 request = (MainThreadRequest) msg.obj;
2242 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 PurchasePremiumCapabilityArgument arg =
2244 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002245 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2246 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002247 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002248 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002249
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251 ar = (AsyncResult) msg.obj;
2252 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002253 PurchasePremiumCapabilityArgument arg =
2254 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002255 try {
2256 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002257 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002258 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002259 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002260 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002261 + TelephonyManager.convertPurchaseResultToString(result));
2262 } catch (RemoteException e) {
2263 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002264 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002265 + " failed: " + e;
2266 if (DBG) log(logStr);
2267 AnomalyReporter.reportAnomaly(
2268 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2269 }
2270 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002271 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002272
Michele Berionne5e411512020-11-13 02:36:59 +00002273 case CMD_PREPARE_UNATTENDED_REBOOT:
2274 request = (MainThreadRequest) msg.obj;
2275 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002276 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002277 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002278 notifyRequester(request);
2279 break;
2280
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 default:
2282 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2283 break;
2284 }
2285 }
Jake Hambye994d462014-02-03 13:10:13 -08002286
Pengquan Menga1bb6272018-09-06 09:59:22 -07002287 private void notifyRequester(MainThreadRequest request) {
2288 synchronized (request) {
2289 request.notifyAll();
2290 }
2291 }
2292
Jake Hambye994d462014-02-03 13:10:13 -08002293 private void handleNullReturnEvent(Message msg, String command) {
2294 AsyncResult ar = (AsyncResult) msg.obj;
2295 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2296 if (ar.exception == null) {
2297 request.result = true;
2298 } else {
2299 request.result = false;
2300 if (ar.exception instanceof CommandException) {
2301 loge(command + ": CommandException: " + ar.exception);
2302 } else {
2303 loge(command + ": Unknown exception");
2304 }
2305 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002306 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 }
2309
2310 /**
2311 * Posts the specified command to be executed on the main thread,
2312 * waits for the request to complete, and returns the result.
2313 * @see #sendRequestAsync
2314 */
2315 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002316 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2317 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002318 }
2319
2320 /**
2321 * Posts the specified command to be executed on the main thread,
2322 * waits for the request to complete, and returns the result.
2323 * @see #sendRequestAsync
2324 */
2325 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2326 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002327 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002328 }
2329
2330 /**
2331 * Posts the specified command to be executed on the main thread,
2332 * waits for the request to complete, and returns the result.
2333 * @see #sendRequestAsync
2334 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002335 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002336 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2337 }
2338
2339 /**
2340 * Posts the specified command to be executed on the main thread,
2341 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2342 * if not timeout or null otherwise.
2343 * @see #sendRequestAsync
2344 */
2345 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2346 long timeoutInMs) {
2347 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002348 }
2349
2350 /**
2351 * Posts the specified command to be executed on the main thread,
2352 * waits for the request to complete, and returns the result.
2353 * @see #sendRequestAsync
2354 */
Nathan Harold92bed182018-10-12 18:16:49 -07002355 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002356 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002357 }
2358
2359 /**
2360 * Posts the specified command to be executed on the main thread,
2361 * waits for the request to complete, and returns the result.
2362 * @see #sendRequestAsync
2363 */
2364 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002365 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2366 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002367 }
2368
2369 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002370 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2371 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2372 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002373 * @see #sendRequestAsync
2374 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002375 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2376 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2378 throw new RuntimeException("This method will deadlock if called from the main thread.");
2379 }
2380
Nathan Harold92bed182018-10-12 18:16:49 -07002381 MainThreadRequest request = null;
2382 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2383 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2384 } else if (phone != null) {
2385 request = new MainThreadRequest(argument, phone, workSource);
2386 } else {
2387 request = new MainThreadRequest(argument, subId, workSource);
2388 }
2389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 Message msg = mMainThreadHandler.obtainMessage(command, request);
2391 msg.sendToTarget();
2392
Rambo Wang0f050d82021-02-12 11:43:36 -08002393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002395 if (timeoutInMs >= 0) {
2396 // Wait for at least timeoutInMs before returning null request result
2397 long now = SystemClock.elapsedRealtime();
2398 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002399 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002400 try {
2401 request.wait(deadline - now);
2402 } catch (InterruptedException e) {
2403 // Do nothing, go back and check if request is completed or timeout
2404 } finally {
2405 now = SystemClock.elapsedRealtime();
2406 }
2407 }
2408 } else {
2409 // Wait for the request to complete
2410 while (request.result == null) {
2411 try {
2412 request.wait();
2413 } catch (InterruptedException e) {
2414 // Do nothing, go back and wait until the request is complete
2415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 }
2417 }
2418 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002419 if (request.result == null) {
2420 Log.wtf(LOG_TAG,
2421 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 return request.result;
2424 }
2425
2426 /**
2427 * Asynchronous ("fire and forget") version of sendRequest():
2428 * Posts the specified command to be executed on the main thread, and
2429 * returns immediately.
2430 * @see #sendRequest
2431 */
2432 private void sendRequestAsync(int command) {
2433 mMainThreadHandler.sendEmptyMessage(command);
2434 }
2435
2436 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002437 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002438 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002439 */
2440 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002441 sendRequestAsync(command, argument, null, null);
2442 }
2443
2444 /**
2445 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2446 * @see {@link #sendRequest(int,Object)}
2447 */
2448 private void sendRequestAsync(
2449 int command, Object argument, Phone phone, WorkSource workSource) {
2450 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002451 Message msg = mMainThreadHandler.obtainMessage(command, request);
2452 msg.sendToTarget();
2453 }
2454
2455 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 * Initialize the singleton PhoneInterfaceManager instance.
2457 * This is only done once, at startup, from PhoneApp.onCreate().
2458 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002459 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 synchronized (PhoneInterfaceManager.class) {
2461 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002462 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 } else {
2464 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2465 }
2466 return sInstance;
2467 }
2468 }
2469
2470 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002471 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002473 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002474 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002476 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002477 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002478 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2480 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002481 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002482 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002483 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002484 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002485 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002486 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002487 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2488 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002489 mVendorApiLevel = SystemProperties.getInt(
2490 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2491
Tyler Gunn64144d92022-03-17 14:16:41 -07002492 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 publish();
arunvoddud7401012022-12-15 16:08:12 +00002494 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002495
2496 // Create the SatelliteEntitlementController singleton, for using the get the
2497 // entitlementStatus for satellite service.
2498 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 }
2500
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002501 @VisibleForTesting
2502 public SharedPreferences getSharedPreferences() {
2503 return mTelephonySharedPreferences;
2504 }
2505
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002506 /**
2507 * Get the default phone for this device.
2508 */
2509 @VisibleForTesting
2510 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002511 Phone thePhone = getPhone(getDefaultSubscription());
2512 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2513 }
2514
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 private void publish() {
2516 if (DBG) log("publish: " + this);
2517
Peter Wangc035ce42020-01-08 21:00:22 -08002518 TelephonyFrameworkInitializer
2519 .getTelephonyServiceManager()
2520 .getTelephonyServiceRegisterer()
2521 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 }
2523
Stuart Scott584921c2015-01-15 17:10:34 -08002524 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002525 if (request.phone != null) {
2526 return request.phone;
2527 } else {
2528 return getPhoneFromSubId(request.subId);
2529 }
2530 }
2531
2532 private Phone getPhoneFromSubId(int subId) {
2533 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2534 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002535 }
2536
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002537 /**
2538 * Get phone object associated with a subscription.
2539 * Return default phone if phone object associated with subscription is null
2540 * @param subId - subscriptionId
2541 * @return phone object associated with a subscription or default phone if null.
2542 */
Ling Mac28f0212023-03-24 16:07:15 -07002543 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002544 Phone phone = getPhoneFromSubId(subId);
2545 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002546 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002547 phone = getDefaultPhone();
2548 }
2549 return phone;
2550 }
2551
Rambo Wange53e07d2022-05-10 13:01:13 -07002552 @Nullable
2553 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002554 Phone phone = getPhoneFromRequest(request);
2555 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002556 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002557 }
2558
Ling Mac28f0212023-03-24 16:07:15 -07002559 /**
2560 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2561 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2562 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2563 * @return The Phone associated the sub Id
2564 */
2565 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002566 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568
Kai Shif70f46f2021-03-03 13:59:46 -08002569 private void sendEraseModemConfig(@NonNull Phone phone) {
2570 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2571 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2572 }
2573
2574 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2575 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2576 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002577 }
2578
Peter Wang44b186e2020-01-13 23:33:09 -08002579 private boolean isImsAvailableOnDevice() {
2580 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2581 if (pm == null) {
2582 // For some reason package manger is not available.. This will fail internally anyway,
2583 // so do not throw error and allow.
2584 return true;
2585 }
2586 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2587 }
2588
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002590 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2591 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2592
Wink Savilleadd7cc52014-09-08 14:23:09 -07002593 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002594 }
2595
Wink Savilleb564aae2014-10-23 10:18:09 -07002596 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597 if (DBG) log("dial: " + number);
2598 // No permission check needed here: This is just a wrapper around the
2599 // ACTION_DIAL intent, which is available to any app since it puts up
2600 // the UI before it does anything.
2601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 String url = createTelUrl(number);
2605 if (url == null) {
2606 return;
2607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 // PENDING: should we just silently fail if phone is offhook or ringing?
2610 PhoneConstants.State state = mCM.getState(subId);
2611 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2612 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2613 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2614 mApp.startActivity(intent);
2615 }
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619 }
2620
2621 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002622 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002623 }
2624
Wink Savilleb564aae2014-10-23 10:18:09 -07002625 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 if (DBG) log("call: " + number);
2627
2628 // This is just a wrapper around the ACTION_CALL intent, but we still
2629 // need to do a permission check since we're calling startActivity()
2630 // from the context of the phone app.
2631 enforceCallPermission();
2632
Jordan Liu1617b712019-07-10 15:06:26 -07002633 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 != AppOpsManager.MODE_ALLOWED) {
2635 return;
2636 }
2637
joonhunshin4ac60942023-11-15 15:23:39 +00002638 enforceTelephonyFeatureWithException(callingPackage,
2639 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 String url = createTelUrl(number);
2644 if (url == null) {
2645 return;
2646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 boolean isValid = false;
2649 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2650 if (slist != null) {
2651 for (SubscriptionInfo subInfoRecord : slist) {
2652 if (subInfoRecord.getSubscriptionId() == subId) {
2653 isValid = true;
2654 break;
2655 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002656 }
Wink Saville08874612014-08-31 19:19:58 -07002657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 if (!isValid) {
2659 return;
2660 }
Wink Saville08874612014-08-31 19:19:58 -07002661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2663 intent.putExtra(SUBSCRIPTION_KEY, subId);
2664 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2665 mApp.startActivity(intent);
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002669 }
2670
Wink Savilleb564aae2014-10-23 10:18:09 -07002671 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002672 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002673 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2674 }
2675
Wink Savilleb564aae2014-10-23 10:18:09 -07002676 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, 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 int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
joonhunshin4ac60942023-11-15 15:23:39 +00002684 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2685 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2686 "supplyPinReportResultForSubscriber");
2687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 final long identity = Binder.clearCallingIdentity();
2689 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002690 Phone phone = getPhone(subId);
2691 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 checkSimPin.start();
2693 return checkSimPin.unlockSim(null, pin);
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
2696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 }
2698
Wink Savilleb564aae2014-10-23 10:18:09 -07002699 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701
joonhunshin4ac60942023-11-15 15:23:39 +00002702 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2703 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002707 Phone phone = getPhone(subId);
2708 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709 checkSimPuk.start();
2710 return checkSimPuk.unlockSim(puk, pin);
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
2713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
2716 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002717 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 * a synchronous one.
2719 */
2720 private static class UnlockSim extends Thread {
2721
2722 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002723 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724
2725 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002726 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2727 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728
2729 // For replies from SimCard interface
2730 private Handler mHandler;
2731
2732 // For async handler to identify request type
2733 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002734 private static final int SUPPLY_PIN_DELAYED = 101;
2735 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2736 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2737 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738
Michele Berionne5e411512020-11-13 02:36:59 +00002739 UnlockSim(int phoneId, IccCard simCard) {
2740 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 mSimCard = simCard;
2742 }
2743
2744 @Override
2745 public void run() {
2746 Looper.prepare();
2747 synchronized (UnlockSim.this) {
2748 mHandler = new Handler() {
2749 @Override
2750 public void handleMessage(Message msg) {
2751 AsyncResult ar = (AsyncResult) msg.obj;
2752 switch (msg.what) {
2753 case SUPPLY_PIN_COMPLETE:
2754 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2755 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002756 mRetryCount = msg.arg1;
2757 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002758 CommandException.Error error = null;
2759 if (ar.exception instanceof CommandException) {
2760 error = ((CommandException) (ar.exception))
2761 .getCommandError();
2762 }
2763 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002764 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002765 } else if (error == CommandException.Error.ABORTED) {
2766 /* When UiccCardApp dispose, handle message and return
2767 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002768 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002769 } else {
2770 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2771 }
2772 } else {
2773 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002776 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 UnlockSim.this.notifyAll();
2778 }
2779 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002780 case SUPPLY_PIN_DELAYED:
2781 if(!mDone) {
2782 String logStr = "Delay in receiving SIM PIN response ";
2783 if (DBG) log(logStr);
2784 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2785 }
2786 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 }
2788 }
2789 };
2790 UnlockSim.this.notifyAll();
2791 }
2792 Looper.loop();
2793 }
2794
2795 /*
2796 * Use PIN or PUK to unlock SIM card
2797 *
2798 * If PUK is null, unlock SIM card with PIN
2799 *
2800 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302801 *
2802 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2803 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002804 */
Wink Saville9de0f752013-10-22 19:04:03 -07002805 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002806
2807 while (mHandler == null) {
2808 try {
2809 wait();
2810 } catch (InterruptedException e) {
2811 Thread.currentThread().interrupt();
2812 }
2813 }
2814 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2815
2816 if (puk == null) {
2817 mSimCard.supplyPin(pin, callback);
2818 } else {
2819 mSimCard.supplyPuk(puk, pin, callback);
2820 }
2821
2822 while (!mDone) {
2823 try {
2824 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002825 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2826 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 wait();
2828 } catch (InterruptedException e) {
2829 // Restore the interrupted status
2830 Thread.currentThread().interrupt();
2831 }
2832 }
2833 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002834 int[] resultArray = new int[2];
2835 resultArray[0] = mResult;
2836 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002837
2838 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002839 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002840 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302841 // This instance is no longer reused, so quit its thread's looper.
2842 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002843
Wink Saville9de0f752013-10-22 19:04:03 -07002844 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 }
2846 }
2847
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002848 /**
2849 * This method has been removed due to privacy and stability concerns.
2850 */
2851 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002853 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2854 return;
Wink Saville36469e72014-06-11 15:17:00 -07002855 }
2856
Nathan Harold1f889d82020-06-04 17:05:26 -07002857 @Override
2858 public void updateServiceLocationWithPackageName(String callingPackage) {
2859 mApp.getSystemService(AppOpsManager.class)
2860 .checkPackage(Binder.getCallingUid(), callingPackage);
2861
Nathan Haroldf096d982020-11-18 17:18:06 -08002862 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002863 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2864 // Callers targeting S have no business invoking this method.
2865 return;
2866 }
2867
2868 LocationAccessPolicy.LocationPermissionResult locationResult =
2869 LocationAccessPolicy.checkLocationPermission(mApp,
2870 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2871 .setCallingPackage(callingPackage)
2872 .setCallingFeatureId(null)
2873 .setCallingPid(Binder.getCallingPid())
2874 .setCallingUid(Binder.getCallingUid())
2875 .setMethod("updateServiceLocation")
2876 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2877 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2878 .build());
2879 // Apps that lack location permission have no business calling this method;
2880 // however, because no permission was declared in the public API, denials must
2881 // all be "soft".
2882 switch (locationResult) {
2883 case DENIED_HARD: /* fall through */
2884 case DENIED_SOFT:
2885 return;
2886 }
2887
2888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 final long identity = Binder.clearCallingIdentity();
2890 try {
Ling Mac28f0212023-03-24 16:07:15 -07002891 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 } finally {
2893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 }
2896
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002897 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002898 @Override
2899 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002900 return isRadioOnWithFeature(callingPackage, null);
2901 }
2902
2903
2904 @Override
2905 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2906 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2907 callingFeatureId);
2908 }
2909
2910 @Deprecated
2911 @Override
2912 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2913 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002914 }
2915
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002916 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002917 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2918 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002919 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002920 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002921 return false;
2922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923
joonhunshin4ac60942023-11-15 15:23:39 +00002924 enforceTelephonyFeatureWithException(callingPackage,
2925 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 return isRadioOnForSubscriber(subId);
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002933 }
2934
2935 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 final Phone phone = getPhone(subId);
2939 if (phone != null) {
2940 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2941 } else {
2942 return false;
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 }
2948
2949 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002950 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002951 }
Wink Saville36469e72014-06-11 15:17:00 -07002952
Wink Savilleb564aae2014-10-23 10:18:09 -07002953 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955
joonhunshin4ac60942023-11-15 15:23:39 +00002956 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2957 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 final Phone phone = getPhone(subId);
2962 if (phone != null) {
2963 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2964 }
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002967 }
Wink Saville36469e72014-06-11 15:17:00 -07002968 }
2969
2970 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002971 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002972 }
2973
Wink Savilleb564aae2014-10-23 10:18:09 -07002974 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002975 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976
2977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 final Phone phone = getPhone(subId);
2980 if (phone == null) {
2981 return false;
2982 }
2983 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2984 toggleRadioOnOffForSubscriber(subId);
2985 }
2986 return true;
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 }
Wink Saville36469e72014-06-11 15:17:00 -07002991
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002992 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002993 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002994
2995 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2996 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2997
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002998 /*
2999 * If any of the Radios are available, it will need to be
3000 * shutdown. So return true if any Radio is available.
3001 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3005 Phone phone = PhoneFactory.getPhone(i);
3006 if (phone != null && phone.isRadioAvailable()) return true;
3007 }
3008 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3009 return false;
3010 } finally {
3011 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003012 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003013 }
3014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003016 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017 enforceModifyPermission();
3018
joonhunshin4ac60942023-11-15 15:23:39 +00003019 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3020 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3025 logv("Shutting down Phone " + i);
3026 shutdownRadioUsingPhoneId(i);
3027 }
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003030 }
3031 }
3032
3033 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003034 Phone phone = PhoneFactory.getPhone(phoneId);
3035 if (phone != null && phone.isRadioAvailable()) {
3036 phone.shutdownRadio();
3037 }
3038 }
3039
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003040 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042
Ling Ma83dc5ea2023-01-12 15:06:04 -08003043 if (!turnOn) {
3044 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3045 }
3046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3050 if (defaultPhone != null) {
3051 defaultPhone.setRadioPower(turnOn);
3052 return true;
3053 } else {
3054 loge("There's no default phone.");
3055 return false;
3056 }
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003059 }
Wink Saville36469e72014-06-11 15:17:00 -07003060 }
3061
Wink Savilleb564aae2014-10-23 10:18:09 -07003062 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064
Ling Ma83dc5ea2023-01-12 15:06:04 -08003065 if (!turnOn) {
3066 log("setRadioPowerForSubscriber off: subId=" + subId
3067 + ",callingPackage=" + getCurrentPackageName());
3068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 final Phone phone = getPhone(subId);
3072 if (phone != null) {
3073 phone.setRadioPower(turnOn);
3074 return true;
3075 } else {
3076 return false;
3077 }
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081 }
3082
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003083 /**
3084 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3085 * no reason to power it off. When any of the voters want to power it off, it will be turned
3086 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3087 * powering it off, and these radio off votes will be cleared.
3088 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3089 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3090 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3091 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3092 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3093 * check its vote.
3094 *
3095 * @param subId The subscription ID.
3096 * @param reason The reason for powering off radio.
3097 * @return true on success and false on failure.
3098 */
3099 public boolean requestRadioPowerOffForReason(int subId,
3100 @TelephonyManager.RadioPowerReason int reason) {
3101 enforceModifyPermission();
3102
joonhunshin4ac60942023-11-15 15:23:39 +00003103 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3104 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3105
Ling Ma83dc5ea2023-01-12 15:06:04 -08003106 log("requestRadioPowerOffForReason: subId=" + subId
3107 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003108 final long identity = Binder.clearCallingIdentity();
3109 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003110 boolean result = false;
3111 for (Phone phone : PhoneFactory.getPhones()) {
3112 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003113 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003114 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003115 if (!result) {
3116 loge("requestRadioPowerOffForReason: no phone exists");
3117 }
3118 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
3124 /**
3125 * Remove the vote on powering off the radio for a reason, as requested by
3126 * {@link requestRadioPowerOffForReason}.
3127 *
3128 * @param subId The subscription ID.
3129 * @param reason The reason for powering off radio.
3130 * @return true on success and false on failure.
3131 */
3132 public boolean clearRadioPowerOffForReason(int subId,
3133 @TelephonyManager.RadioPowerReason int reason) {
3134 enforceModifyPermission();
3135
joonhunshin4ac60942023-11-15 15:23:39 +00003136 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3137 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3138
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003139 final long identity = Binder.clearCallingIdentity();
3140 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003141 boolean result = false;
3142 for (Phone phone : PhoneFactory.getPhones()) {
3143 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003144 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003145 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003146 if (!result) {
3147 loge("clearRadioPowerOffForReason: no phone exists");
3148 }
3149 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003150 } finally {
3151 Binder.restoreCallingIdentity(identity);
3152 }
3153 }
3154
3155 /**
3156 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3157 *
3158 * @param subId The subscription ID.
3159 * @param callingPackage The package making the call.
3160 * @param callingFeatureId The feature in the package.
3161 * @return List of reasons for powering off radio.
3162 */
3163 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3164 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3165
joonhunshin4ac60942023-11-15 15:23:39 +00003166 enforceTelephonyFeatureWithException(callingPackage,
3167 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3168
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003169 final long identity = Binder.clearCallingIdentity();
3170 List result = new ArrayList();
3171 try {
3172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3173 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3174 return result;
3175 }
3176
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003177 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003178 if (phone != null) {
3179 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003180 } else {
3181 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003182 }
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
3185 }
3186 return result;
3187 }
3188
Wink Saville36469e72014-06-11 15:17:00 -07003189 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003190 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003191 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193
joonhunshin4ac60942023-11-15 15:23:39 +00003194 enforceTelephonyFeatureWithException(callingPackage,
3195 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 final long identity = Binder.clearCallingIdentity();
3198 try {
Jack Yu285100e2022-12-02 22:48:35 -08003199 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003201 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003202 phone.getDataSettingsManager().setDataEnabled(
3203 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 return true;
3205 } else {
3206 return false;
3207 }
3208 } finally {
3209 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 }
3212
Wink Saville36469e72014-06-11 15:17:00 -07003213 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003214 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003215 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217
joonhunshin4ac60942023-11-15 15:23:39 +00003218 enforceTelephonyFeatureWithException(callingPackage,
3219 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 final long identity = Binder.clearCallingIdentity();
3222 try {
Jack Yu285100e2022-12-02 22:48:35 -08003223 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003225 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003226 phone.getDataSettingsManager().setDataEnabled(
3227 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228 return true;
3229 } else {
3230 return false;
3231 }
3232 } finally {
3233 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003235 }
3236
Sanket Padawe356d7632015-06-22 14:03:32 -07003237 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003238 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003239 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3240 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 final Phone phone = getPhone(subId);
3245 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003246 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247 } else {
3248 return false;
3249 }
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 }
3254
3255 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003256 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003257 }
3258
pkanwarae03a6b2016-11-06 20:37:09 -08003259 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003260 enforceCallPermission();
3261
joonhunshin4ac60942023-11-15 15:23:39 +00003262 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3263 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265 final long identity = Binder.clearCallingIdentity();
3266 try {
3267 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3268 return;
3269 }
3270 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3271 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3272 } finally {
3273 Binder.restoreCallingIdentity(identity);
3274 }
pkanwar32d516d2016-10-14 19:37:38 -07003275 };
3276
Wink Savilleb564aae2014-10-23 10:18:09 -07003277 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279
joonhunshin4ac60942023-11-15 15:23:39 +00003280 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3281 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3286 return false;
3287 }
3288 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3289 } finally {
3290 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003292 }
3293
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003294 /**
3295 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3296 * tag on getCallState Binder call.
3297 */
3298 @Deprecated
3299 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003301 if (CompatChanges.isChangeEnabled(
3302 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3303 Binder.getCallingUid())) {
3304 // Do not allow this API to be called on API version 31+, it should only be
3305 // called on old apps using this Binder call directly.
3306 throw new SecurityException("This method can only be used for applications "
3307 + "targeting API version 30 or less.");
3308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309 final long identity = Binder.clearCallingIdentity();
3310 try {
Ling Mac28f0212023-03-24 16:07:15 -07003311 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3312 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
3316 }
3317
3318 @Override
3319 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3320 if (CompatChanges.isChangeEnabled(
3321 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3322 Binder.getCallingUid())) {
3323 // Check READ_PHONE_STATE for API version 31+
3324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3325 featureId, "getCallStateForSubscription")) {
3326 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3327 + "targeting API level 31+.");
3328 }
3329 }
joonhunshin4ac60942023-11-15 15:23:39 +00003330
3331 enforceTelephonyFeatureWithException(callingPackage,
3332 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3333
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3338 PhoneConstantConversions.convertCallState(phone.getState());
3339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003342 }
3343
Sanket Padawe356d7632015-06-22 14:03:32 -07003344 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003345 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003346 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003347 }
3348
3349 @Override
3350 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003351 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3352 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354 final long identity = Binder.clearCallingIdentity();
3355 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003356 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003358 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359 } else {
3360 return PhoneConstantConversions.convertDataState(
3361 PhoneConstants.DataState.DISCONNECTED);
3362 }
3363 } finally {
3364 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003366 }
3367
Sanket Padawe356d7632015-06-22 14:03:32 -07003368 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003369 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003370 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003371 }
3372
3373 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003374 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003375 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3376 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 final long identity = Binder.clearCallingIdentity();
3379 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003380 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003382 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003383 } else {
3384 return TelephonyManager.DATA_ACTIVITY_NONE;
3385 }
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 }
3390
3391 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003392 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003393 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003394 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003395
3396 LocationAccessPolicy.LocationPermissionResult locationResult =
3397 LocationAccessPolicy.checkLocationPermission(mApp,
3398 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3399 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003400 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003401 .setCallingPid(Binder.getCallingPid())
3402 .setCallingUid(Binder.getCallingUid())
3403 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003404 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003405 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3406 .build());
3407 switch (locationResult) {
3408 case DENIED_HARD:
3409 throw new SecurityException("Not allowed to access cell location");
3410 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003411 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3412 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 }
3414
joonhunshin4ac60942023-11-15 15:23:39 +00003415 enforceTelephonyFeatureWithException(callingPackage,
3416 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3417
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003418 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003422 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003423 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
Svetoslav64fad262015-04-14 14:35:21 -07003427 }
3428
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003429 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003430 public String getNetworkCountryIsoForPhone(int phoneId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003431 if (!mApp.getResources().getBoolean(
3432 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3433 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3434 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3435 }
joonhunshin4ac60942023-11-15 15:23:39 +00003436
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003437 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3438 // registered cell info, so return a NULL country instead.
3439 final long identity = Binder.clearCallingIdentity();
3440 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003441 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3442 // Get default phone in this case.
3443 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3444 }
Jack Yu285100e2022-12-02 22:48:35 -08003445 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003447 if (phone == null) return "";
3448 ServiceStateTracker sst = phone.getServiceStateTracker();
3449 if (sst == null) return "";
3450 LocaleTracker lt = sst.getLocaleTracker();
3451 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003452 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003453 } finally {
3454 Binder.restoreCallingIdentity(identity);
3455 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003456 }
3457
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003458 /**
3459 * This method was removed due to potential issues caused by performing partial
3460 * updates of service state, and lack of a credible use case.
3461 *
3462 * This has the ability to break the telephony implementation by disabling notification of
3463 * changes in device connectivity. DO NOT USE THIS!
3464 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003465 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003466 public void enableLocationUpdates() {
3467 mApp.enforceCallingOrSelfPermission(
3468 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003469 }
3470
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003471 /**
3472 * This method was removed due to potential issues caused by performing partial
3473 * updates of service state, and lack of a credible use case.
3474 *
3475 * This has the ability to break the telephony implementation by disabling notification of
3476 * changes in device connectivity. DO NOT USE THIS!
3477 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478 @Override
3479 public void disableLocationUpdates() {
3480 mApp.enforceCallingOrSelfPermission(
3481 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003482 }
3483
3484 @Override
3485 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003486 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3487 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003488 try {
3489 mApp.getSystemService(AppOpsManager.class)
3490 .checkPackage(Binder.getCallingUid(), callingPackage);
3491 } catch (SecurityException e) {
3492 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3493 throw e;
3494 }
3495
Nathan Haroldf096d982020-11-18 17:18:06 -08003496 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003497 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3498 throw new SecurityException(
3499 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3500 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003501
Jordan Liu1617b712019-07-10 15:06:26 -07003502 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3504 return null;
3505 }
Svetoslav64fad262015-04-14 14:35:21 -07003506
joonhunshin4ac60942023-11-15 15:23:39 +00003507 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3508 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3509
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003510 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003512 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003513 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003514
Nathan Haroldf180aac2018-06-01 18:43:55 -07003515 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3516 for (CellInfo ci : info) {
3517 if (ci instanceof CellInfoGsm) {
3518 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3519 } else if (ci instanceof CellInfoWcdma) {
3520 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003522 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003523 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 }
3525
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003526 private List<CellInfo> getCachedCellInfo() {
3527 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3528 for (Phone phone : PhoneFactory.getPhones()) {
3529 List<CellInfo> info = phone.getAllCellInfo();
3530 if (info != null) cellInfos.addAll(info);
3531 }
3532 return cellInfos;
3533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003534
3535 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003536 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003537 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003538 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003539
3540 LocationAccessPolicy.LocationPermissionResult locationResult =
3541 LocationAccessPolicy.checkLocationPermission(mApp,
3542 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3543 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003544 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003545 .setCallingPid(Binder.getCallingPid())
3546 .setCallingUid(Binder.getCallingUid())
3547 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003548 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003549 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3550 .build());
3551 switch (locationResult) {
3552 case DENIED_HARD:
3553 throw new SecurityException("Not allowed to access cell info");
3554 case DENIED_SOFT:
3555 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003556 }
3557
Nathan Haroldf096d982020-11-18 17:18:06 -08003558 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003559 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3560 return getCachedCellInfo();
3561 }
3562
joonhunshin4ac60942023-11-15 15:23:39 +00003563 enforceTelephonyFeatureWithException(callingPackage,
3564 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3565
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003566 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003567 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3571 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003572 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003573 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003574 if (info != null) cellInfos.addAll(info);
3575 }
3576 return cellInfos;
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003579 }
3580 }
3581
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003582 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003583 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3584 String callingFeatureId) {
3585 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3586 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003587 }
3588
3589 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003590 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3591 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003592 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003593 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003594 }
3595
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003596 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3597 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003598 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003599 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003600
3601 LocationAccessPolicy.LocationPermissionResult locationResult =
3602 LocationAccessPolicy.checkLocationPermission(mApp,
3603 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3604 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003605 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003606 .setCallingPid(Binder.getCallingPid())
3607 .setCallingUid(Binder.getCallingUid())
3608 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003609 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3610 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003611 .build());
3612 switch (locationResult) {
3613 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003614 if (TelephonyPermissions
3615 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003616 // Safetynet logging for b/154934934
3617 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3618 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003619 throw new SecurityException("Not allowed to access cell info");
3620 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003621 if (TelephonyPermissions
3622 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003623 // Safetynet logging for b/154934934
3624 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3625 }
Nathan Harold5320c422019-05-09 10:26:08 -07003626 try {
3627 cb.onCellInfo(new ArrayList<CellInfo>());
3628 } catch (RemoteException re) {
3629 // Drop without consequences
3630 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003631 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003632 }
3633
joonhunshin4ac60942023-11-15 15:23:39 +00003634 enforceTelephonyFeatureWithException(callingPackage,
3635 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003636
3637 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003638 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3639
3640 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3641 }
3642
3643 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003644 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003645 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003646 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647
3648 final long identity = Binder.clearCallingIdentity();
3649 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003650 Phone phone = getPhone(subId);
3651 if (phone == null) {
3652 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3653 } else {
3654 phone.setCellInfoListRate(rateInMillis, workSource);
3655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003659 }
3660
Shishir Agrawala9f32182016-04-12 12:00:16 -07003661 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003662 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003663 Phone phone = PhoneFactory.getPhone(slotIndex);
3664 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003665 return null;
3666 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003667 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003668 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003669 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003670 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003671 return null;
3672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673
joonhunshin4ac60942023-11-15 15:23:39 +00003674 enforceTelephonyFeatureWithException(callingPackage,
3675 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 return phone.getImei();
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003683 }
3684
3685 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003686 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3687 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3688 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3689 callingFeatureId, "getPrimaryImei")) {
3690 throw new SecurityException("Caller does not have permission");
3691 }
joonhunshin4ac60942023-11-15 15:23:39 +00003692
3693 enforceTelephonyFeatureWithException(callingPackage,
3694 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3695
arunvoddud5c6ce02022-12-11 06:03:12 +00003696 final long identity = Binder.clearCallingIdentity();
3697 try {
3698 for (Phone phone : PhoneFactory.getPhones()) {
3699 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3700 return phone.getImei();
3701 }
3702 }
3703 throw new UnsupportedOperationException("Operation not supported");
3704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
3707 }
3708
3709 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003710 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003711 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3712 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3713
David Kelly5e06a7f2018-03-12 14:10:59 +00003714 Phone phone = PhoneFactory.getPhone(slotIndex);
3715 String tac = null;
3716 if (phone != null) {
3717 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003718 try {
3719 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3720 } catch (IndexOutOfBoundsException e) {
3721 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3722 return null;
3723 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003724 }
3725 return tac;
3726 }
3727
3728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003729 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003730 try {
3731 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3732 } catch (SecurityException se) {
3733 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3734 throw new SecurityException("Package " + callingPackage + " does not belong to "
3735 + Binder.getCallingUid());
3736 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003737 Phone phone = PhoneFactory.getPhone(slotIndex);
3738 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003739 return null;
3740 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003741
Jeff Davidson913390f2018-02-23 17:11:49 -08003742 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003743 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003744 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003745 return null;
3746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747
joonhunshin4ac60942023-11-15 15:23:39 +00003748 enforceTelephonyFeatureWithException(callingPackage,
3749 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 return phone.getMeid();
3754 } finally {
3755 Binder.restoreCallingIdentity(identity);
3756 }
Jack Yu2af8d712017-03-15 17:14:14 -07003757 }
3758
3759 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003760 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003761 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3762 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3763
David Kelly5e06a7f2018-03-12 14:10:59 +00003764 Phone phone = PhoneFactory.getPhone(slotIndex);
3765 String manufacturerCode = null;
3766 if (phone != null) {
3767 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003768 try {
3769 manufacturerCode =
3770 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3771 } catch (IndexOutOfBoundsException e) {
3772 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3773 return null;
3774 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003775 }
3776 return manufacturerCode;
3777 }
3778
3779 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003780 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3781 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003782 Phone phone = PhoneFactory.getPhone(slotIndex);
3783 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003784 return null;
3785 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003786 int subId = phone.getSubId();
3787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003788 mApp, subId, callingPackage, callingFeatureId,
3789 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003790 return null;
3791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792
joonhunshin4ac60942023-11-15 15:23:39 +00003793 enforceTelephonyFeatureWithException(callingPackage,
3794 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 return phone.getDeviceSvn();
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
3801 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003802 }
3803
fionaxu43304da2017-11-27 22:51:16 -08003804 @Override
3805 public int getSubscriptionCarrierId(int subId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003806 if (!mApp.getResources().getBoolean(
3807 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3808 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3809 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3810 }
joonhunshin4ac60942023-11-15 15:23:39 +00003811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 final Phone phone = getPhone(subId);
3815 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3816 } finally {
3817 Binder.restoreCallingIdentity(identity);
3818 }
fionaxu43304da2017-11-27 22:51:16 -08003819 }
3820
3821 @Override
3822 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003823 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3824 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 final Phone phone = getPhone(subId);
3829 return phone == null ? null : phone.getCarrierName();
3830 } finally {
3831 Binder.restoreCallingIdentity(identity);
3832 }
fionaxu43304da2017-11-27 22:51:16 -08003833 }
3834
calvinpanffe225e2018-11-01 19:43:06 +08003835 @Override
chen xu0026ca62019-03-06 15:28:50 -08003836 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003837 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3838 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3839
chen xu25637222018-11-04 17:17:00 -08003840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 final Phone phone = getPhone(subId);
3843 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003844 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003845 } finally {
3846 Binder.restoreCallingIdentity(identity);
3847 }
3848 }
3849
3850 @Override
chen xu0026ca62019-03-06 15:28:50 -08003851 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003852 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3853 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3854 "getSubscriptionSpecificCarrierName");
3855
chen xu25637222018-11-04 17:17:00 -08003856 final long identity = Binder.clearCallingIdentity();
3857 try {
3858 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003859 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003860 } finally {
3861 Binder.restoreCallingIdentity(identity);
3862 }
3863 }
3864
chen xu651eec72018-11-11 19:03:44 -08003865 @Override
chen xu864e11c2018-12-06 22:10:03 -08003866 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3867 if (!isSubscriptionMccMnc) {
3868 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3869 }
chen xu651eec72018-11-11 19:03:44 -08003870 final Phone phone = PhoneFactory.getPhone(slotIndex);
3871 if (phone == null) {
3872 return TelephonyManager.UNKNOWN_CARRIER_ID;
3873 }
joonhunshin4ac60942023-11-15 15:23:39 +00003874
3875 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3876 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3877
chen xu651eec72018-11-11 19:03:44 -08003878 final long identity = Binder.clearCallingIdentity();
3879 try {
3880 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3881 } finally {
3882 Binder.restoreCallingIdentity(identity);
3883 }
3884 }
3885
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003886 //
3887 // Internal helper methods.
3888 //
3889
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003890 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003891 * Make sure the caller is the calling package itself
3892 *
3893 * @throws SecurityException if the caller is not the calling package
3894 */
3895 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3896 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003897 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3898 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003899 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003900 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003901 } catch (PackageManager.NameNotFoundException e) {
3902 // packageUid is -1
3903 }
3904 if (packageUid != callingUid) {
3905 throw new SecurityException(message + ": Package " + callingPackage
3906 + " does not belong to " + callingUid);
3907 }
3908 }
3909
3910 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003911 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3912 *
3913 * @throws SecurityException if the caller does not have the required permission
3914 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003915 @VisibleForTesting
3916 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003917 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3918 }
3919
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003920 /**
arunvoddud7401012022-12-15 16:08:12 +00003921 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003922 *
3923 * @throws SecurityException if the caller does not have the required permission
3924 */
3925 @VisibleForTesting
3926 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003927 enforceReadPermission(null);
3928 }
3929
3930 /**
3931 * Make sure the caller has the READ_PHONE_STATE permissions.
3932 *
3933 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3934 */
3935 @VisibleForTesting
3936 public void enforceReadPermission(String msg) {
3937 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003938 }
3939
Shuo Qian3b6ee772019-11-13 17:43:31 -08003940 private void enforceActiveEmergencySessionPermission() {
3941 mApp.enforceCallingOrSelfPermission(
3942 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3943 }
3944
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003945 /**
3946 * Make sure the caller has the CALL_PHONE permission.
3947 *
3948 * @throws SecurityException if the caller does not have the required permission
3949 */
3950 private void enforceCallPermission() {
3951 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3952 }
3953
paulhu5a773602019-08-23 19:17:33 +08003954 private void enforceSettingsPermission() {
3955 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003956 }
3957
Michele Berionne5e411512020-11-13 02:36:59 +00003958 private void enforceRebootPermission() {
3959 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3960 }
3961
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003962 /**
3963 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3964 * @param message - log message to print.
3965 * @throws SecurityException if the caller does not have the required permission
3966 */
3967 private void enforceSatelliteCommunicationPermission(String message) {
3968 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3969 }
3970
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003971 /**
3972 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3973 * @param message - log message to print.
3974 * @throws SecurityException if the caller does not have the required permission
3975 */
3976 private void enforcePackageUsageStatsPermission(String message) {
3977 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3978 }
3979
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003980 private String createTelUrl(String number) {
3981 if (TextUtils.isEmpty(number)) {
3982 return null;
3983 }
3984
Jake Hambye994d462014-02-03 13:10:13 -08003985 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003986 }
3987
Ihab Awadf9e92732013-12-05 18:02:52 -08003988 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003989 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003990 }
3991
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003992 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003993 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003994 }
3995
Ihab Awadf9e92732013-12-05 18:02:52 -08003996 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003997 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003998 }
3999
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004000 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004001 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004002 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004003 }
4004
Sanket Padawe356d7632015-06-22 14:03:32 -07004005 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004006 public int getActivePhoneTypeForSlot(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07004007 if (!mApp.getResources().getBoolean(
4008 com.android.internal.R.bool.config_force_phone_globals_creation)) {
4009 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4010 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4011 }
joonhunshin4ac60942023-11-15 15:23:39 +00004012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 final long identity = Binder.clearCallingIdentity();
4014 try {
4015 final Phone phone = PhoneFactory.getPhone(slotIndex);
4016 if (phone == null) {
4017 return PhoneConstants.PHONE_TYPE_NONE;
4018 } else {
4019 return phone.getPhoneType();
4020 }
4021 } finally {
4022 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004023 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004024 }
4025
4026 /**
4027 * Returns the CDMA ERI icon index to display
4028 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004029 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004030 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4031 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4032 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004033 }
4034
Sanket Padawe356d7632015-06-22 14:03:32 -07004035 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004036 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4037 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004039 mApp, subId, callingPackage, callingFeatureId,
4040 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004041 return -1;
4042 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004043
joonhunshin4ac60942023-11-15 15:23:39 +00004044 enforceTelephonyFeatureWithException(callingPackage,
4045 PackageManager.FEATURE_TELEPHONY_CDMA,
4046 "getCdmaEriIconIndexForSubscriber");
4047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048 final long identity = Binder.clearCallingIdentity();
4049 try {
4050 final Phone phone = getPhone(subId);
4051 if (phone != null) {
4052 return phone.getCdmaEriIconIndex();
4053 } else {
4054 return -1;
4055 }
4056 } finally {
4057 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004059 }
4060
4061 /**
4062 * Returns the CDMA ERI icon mode,
4063 * 0 - ON
4064 * 1 - FLASHING
4065 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004067 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4068 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4069 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004070 }
4071
Sanket Padawe356d7632015-06-22 14:03:32 -07004072 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004073 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4074 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004076 mApp, subId, callingPackage, callingFeatureId,
4077 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004078 return -1;
4079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080
4081 final long identity = Binder.clearCallingIdentity();
4082 try {
4083 final Phone phone = getPhone(subId);
4084 if (phone != null) {
4085 return phone.getCdmaEriIconMode();
4086 } else {
4087 return -1;
4088 }
4089 } finally {
4090 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004092 }
4093
4094 /**
4095 * Returns the CDMA ERI text,
4096 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004097 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004098 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4099 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4100 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004101 }
4102
Sanket Padawe356d7632015-06-22 14:03:32 -07004103 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004104 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4105 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004107 mApp, subId, callingPackage, callingFeatureId,
4108 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004109 return null;
4110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004111
4112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 final Phone phone = getPhone(subId);
4115 if (phone != null) {
4116 return phone.getCdmaEriText();
4117 } else {
4118 return null;
4119 }
4120 } finally {
4121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004123 }
4124
4125 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004126 * Returns the CDMA MDN.
4127 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004128 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004129 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4131 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132
joonhunshin4ac60942023-11-15 15:23:39 +00004133 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4134 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4135
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004136 final long identity = Binder.clearCallingIdentity();
4137 try {
4138 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004139 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140 return phone.getLine1Number();
4141 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004142 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 return null;
4144 }
4145 } finally {
4146 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004147 }
4148 }
4149
4150 /**
4151 * Returns the CDMA MIN.
4152 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004153 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004154 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4156 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157
joonhunshin4ac60942023-11-15 15:23:39 +00004158 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4159 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 final Phone phone = getPhone(subId);
4164 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4165 return phone.getCdmaMin();
4166 } else {
4167 return null;
4168 }
4169 } finally {
4170 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004171 }
4172 }
4173
Hall Liud892bec2018-11-30 14:51:45 -08004174 @Override
4175 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4176 INumberVerificationCallback callback, String callingPackage) {
4177 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4178 != PERMISSION_GRANTED) {
4179 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4180 }
4181 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4182
4183 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4184 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004185 throw new SecurityException("Calling package must be configured in the device config: "
4186 + "calling package: " + callingPackage
4187 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004188 }
4189
joonhunshin4ac60942023-11-15 15:23:39 +00004190 enforceTelephonyFeatureWithException(callingPackage,
4191 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4192
Hall Liud892bec2018-11-30 14:51:45 -08004193 if (range == null) {
4194 throw new NullPointerException("Range must be non-null");
4195 }
4196
4197 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004198 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004199
4200 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4201 }
4202
Junda Liuca05d5d2014-08-14 22:36:34 -07004203 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004204 * Returns true if CDMA provisioning needs to run.
4205 */
4206 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004207 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4208 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004210 final long identity = Binder.clearCallingIdentity();
4211 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004212 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 } finally {
4214 Binder.restoreCallingIdentity(identity);
4215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004216 }
4217
4218 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004219 * Sets the voice mail number of a given subId.
4220 */
4221 @Override
4222 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004223 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4224 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004225
joonhunshin4ac60942023-11-15 15:23:39 +00004226 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4227 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229 final long identity = Binder.clearCallingIdentity();
4230 try {
4231 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4232 new Pair<String, String>(alphaTag, number), new Integer(subId));
4233 return success;
4234 } finally {
4235 Binder.restoreCallingIdentity(identity);
4236 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004237 }
4238
Ta-wei Yen87c49842016-05-13 21:19:52 -07004239 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004240 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4241 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004242 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4243 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004244 if (!TextUtils.equals(callingPackage, systemDialer)) {
4245 throw new SecurityException("caller must be system dialer");
4246 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247
joonhunshin4ac60942023-11-15 15:23:39 +00004248 enforceTelephonyFeatureWithException(callingPackage,
4249 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004251 final long identity = Binder.clearCallingIdentity();
4252 try {
4253 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4254 if (phoneAccountHandle == null) {
4255 return null;
4256 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004257 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258 } finally {
4259 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004260 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004261 }
4262
4263 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004264 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4265 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004266 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004268 mApp, subId, callingPackage, callingFeatureId,
4269 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004270 return null;
4271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004272
joonhunshin4ac60942023-11-15 15:23:39 +00004273 enforceTelephonyFeatureWithException(callingPackage,
4274 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4275
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004276 final long identity = Binder.clearCallingIdentity();
4277 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004278 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004282 }
4283
4284 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004285 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4286 VisualVoicemailSmsFilterSettings settings) {
4287 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004288 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004289 enforceTelephonyFeatureWithException(callingPackage,
4290 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291 final long identity = Binder.clearCallingIdentity();
4292 try {
4293 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004294 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295 } finally {
4296 Binder.restoreCallingIdentity(identity);
4297 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004298 }
4299
4300 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004301 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4302 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004303 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004304 enforceTelephonyFeatureWithException(callingPackage,
4305 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 final long identity = Binder.clearCallingIdentity();
4308 try {
4309 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004310 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004314 }
4315
4316 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004317 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4318 String callingPackage, int subId) {
4319 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004320
4321 final long identity = Binder.clearCallingIdentity();
4322 try {
4323 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004324 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325 } finally {
4326 Binder.restoreCallingIdentity(identity);
4327 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004328 }
4329
4330 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004331 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333
4334 final long identity = Binder.clearCallingIdentity();
4335 try {
4336 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004337 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004341 }
4342
4343 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004344 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4345 String callingAttributionTag, int subId, String number, int port, String text,
4346 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004347 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004348 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004349 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004350
4351 enforceTelephonyFeatureWithException(callingPackage,
4352 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4353
Amit Mahajandccb3f12019-05-13 13:48:32 -07004354 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004355 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4356 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004357 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004358
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004359 /**
fionaxu0152e512016-11-14 13:36:14 -08004360 * Sets the voice activation state of a given subId.
4361 */
4362 @Override
4363 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4365 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366
joonhunshin4ac60942023-11-15 15:23:39 +00004367 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4368 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4369
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370 final long identity = Binder.clearCallingIdentity();
4371 try {
4372 final Phone phone = getPhone(subId);
4373 if (phone != null) {
4374 phone.setVoiceActivationState(activationState);
4375 } else {
4376 loge("setVoiceActivationState fails with invalid subId: " + subId);
4377 }
4378 } finally {
4379 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004380 }
4381 }
4382
4383 /**
4384 * Sets the data activation state of a given subId.
4385 */
4386 @Override
4387 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4389 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004390
joonhunshin4ac60942023-11-15 15:23:39 +00004391 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4392 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4393
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004394 final long identity = Binder.clearCallingIdentity();
4395 try {
4396 final Phone phone = getPhone(subId);
4397 if (phone != null) {
4398 phone.setDataActivationState(activationState);
4399 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004400 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 }
4402 } finally {
4403 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004404 }
4405 }
4406
4407 /**
4408 * Returns the voice activation state of a given subId.
4409 */
4410 @Override
4411 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004412 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413
joonhunshin4ac60942023-11-15 15:23:39 +00004414 enforceTelephonyFeatureWithException(callingPackage,
4415 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4416
fionaxu0152e512016-11-14 13:36:14 -08004417 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004418 final long identity = Binder.clearCallingIdentity();
4419 try {
4420 if (phone != null) {
4421 return phone.getVoiceActivationState();
4422 } else {
4423 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4424 }
4425 } finally {
4426 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004427 }
4428 }
4429
4430 /**
4431 * Returns the data activation state of a given subId.
4432 */
4433 @Override
4434 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004435 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436
joonhunshin4ac60942023-11-15 15:23:39 +00004437 enforceTelephonyFeatureWithException(callingPackage,
4438 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4439
fionaxu0152e512016-11-14 13:36:14 -08004440 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441 final long identity = Binder.clearCallingIdentity();
4442 try {
4443 if (phone != null) {
4444 return phone.getDataActivationState();
4445 } else {
4446 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4447 }
4448 } finally {
4449 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004450 }
4451 }
4452
4453 /**
Wink Saville36469e72014-06-11 15:17:00 -07004454 * Returns the unread count of voicemails for a subId
4455 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004457 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4458 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004460 mApp, subId, callingPackage, callingFeatureId,
4461 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004462 return 0;
4463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004464 final long identity = Binder.clearCallingIdentity();
4465 try {
4466 final Phone phone = getPhone(subId);
4467 if (phone != null) {
4468 return phone.getVoiceMessageCount();
4469 } else {
4470 return 0;
4471 }
4472 } finally {
4473 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004475 }
4476
4477 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004478 * returns true, if the device is in a state where both voice and data
4479 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004480 */
4481 @Override
4482 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004483 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4484 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004486 final long identity = Binder.clearCallingIdentity();
4487 try {
Ling Mac28f0212023-03-24 16:07:15 -07004488 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004489 } finally {
4490 Binder.restoreCallingIdentity(identity);
4491 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004492 }
4493
4494 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004495 * Send the dialer code if called from the current default dialer or the caller has
4496 * carrier privilege.
4497 * @param inputCode The dialer code to send
4498 */
4499 @Override
4500 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004501 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004503 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4504 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004505 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004506 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004507 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004508 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509
joonhunshin4ac60942023-11-15 15:23:39 +00004510 enforceTelephonyFeatureWithException(callingPackage,
4511 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004513 final long identity = Binder.clearCallingIdentity();
4514 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004515 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 } finally {
4517 Binder.restoreCallingIdentity(identity);
4518 }
fionaxu235cc5e2017-03-06 22:25:57 -08004519 }
4520
Pengquan Menga1bb6272018-09-06 09:59:22 -07004521 @Override
4522 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004523 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004524 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4525 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004526
4527 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4528 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4529
shilufc958392020-01-20 11:36:01 -08004530 final long identity = Binder.clearCallingIdentity();
4531 try {
4532 if (!isActiveSubscription(subId)) {
4533 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4534 }
4535 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4536 } finally {
4537 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004538 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004539 }
4540
Brad Ebinger35c841c2018-10-01 10:40:55 -07004541 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004542 public boolean isInEmergencySmsMode() {
4543 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004544
4545 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4546 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4547
Brad Ebingerb2b65522019-03-15 13:48:47 -07004548 final long identity = Binder.clearCallingIdentity();
4549 try {
4550 for (Phone phone : PhoneFactory.getPhones()) {
4551 if (phone.isInEmergencySmsMode()) {
4552 return true;
4553 }
4554 }
4555 } finally {
4556 Binder.restoreCallingIdentity(identity);
4557 }
4558 return false;
4559 }
4560
shilu366312e2019-12-17 09:28:10 -08004561 /**
4562 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4563 * @param subId The subscription to use to check the configuration.
4564 * @param c The callback that will be used to send the result.
4565 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004566 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004567 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4568 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004569 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004570 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004571
4572 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4573 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4574 "IMS not available on device.");
4575 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004576 final long token = Binder.clearCallingIdentity();
4577 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004578 int slotId = getSlotIndexOrException(subId);
4579 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004580
4581 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4582 if (controller != null) {
4583 ImsManager imsManager = controller.getImsManager(subId);
4584 if (imsManager != null) {
4585 imsManager.addRegistrationCallbackForSubscription(c, subId);
4586 } else {
4587 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4588 }
4589 } else {
4590 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4591 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004592 } catch (ImsException e) {
4593 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004594 } finally {
4595 Binder.restoreCallingIdentity(token);
4596 }
4597 }
4598
shilu366312e2019-12-17 09:28:10 -08004599 /**
4600 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4601 * @param subId The subscription to use to check the configuration.
4602 * @param c The callback that will be used to send the result.
4603 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004604 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004605 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004606 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004607 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4609 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4610 }
Meng Wangafbc5852019-09-19 17:37:13 -07004611 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004612
Meng Wangafbc5852019-09-19 17:37:13 -07004613 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004614 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4615 if (controller != null) {
4616 ImsManager imsManager = controller.getImsManager(subId);
4617 if (imsManager != null) {
4618 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4619 } else {
4620 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4621 + "is inactive, ignoring unregister.");
4622 // If the ImsManager is not valid, just return, since the callback
4623 // will already have been removed internally.
4624 }
4625 }
Meng Wangafbc5852019-09-19 17:37:13 -07004626 } finally {
4627 Binder.restoreCallingIdentity(token);
4628 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004629 }
4630
Brad Ebingera34a6c22019-10-22 17:36:18 -07004631 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004632 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4633 * @param subId The subscription to use to check the configuration.
4634 * @param c The callback that will be used to send the result.
4635 */
4636 @Override
4637 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4638 throws RemoteException {
4639 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4640 mApp, subId, "registerImsEmergencyRegistrationCallback");
4641
4642 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4643 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4644 "IMS not available on device.");
4645 }
4646 final long token = Binder.clearCallingIdentity();
4647 try {
4648 int slotId = getSlotIndexOrException(subId);
4649 verifyImsMmTelConfiguredOrThrow(slotId);
4650
4651 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4652 if (controller != null) {
4653 ImsManager imsManager = controller.getImsManager(subId);
4654 if (imsManager != null) {
4655 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4656 } else {
4657 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4658 }
4659 } else {
4660 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4661 }
4662 } catch (ImsException e) {
4663 throw new ServiceSpecificException(e.getCode());
4664 } finally {
4665 Binder.restoreCallingIdentity(token);
4666 }
4667 }
4668
4669 /**
4670 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4671 * @param subId The subscription to use to check the configuration.
4672 * @param c The callback that will be used to send the result.
4673 */
4674 @Override
4675 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4676 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4677 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4678 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4679 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4680 }
4681 final long token = Binder.clearCallingIdentity();
4682
4683 try {
4684 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4685 if (controller != null) {
4686 ImsManager imsManager = controller.getImsManager(subId);
4687 if (imsManager != null) {
4688 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4689 } else {
4690 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4691 + "is inactive, ignoring unregister.");
4692 // If the ImsManager is not valid, just return, since the callback
4693 // will already have been removed internally.
4694 }
4695 }
4696 } finally {
4697 Binder.restoreCallingIdentity(token);
4698 }
4699 }
4700
4701 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004702 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4703 */
4704 @Override
4705 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4706 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4707 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4708 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4709 "IMS not available on device.");
4710 }
4711 final long token = Binder.clearCallingIdentity();
4712 try {
4713 Phone phone = getPhone(subId);
4714 if (phone == null) {
4715 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4716 + subId + "'");
4717 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4718 }
4719 phone.getImsRegistrationState(regState -> {
4720 try {
4721 consumer.accept((regState == null)
4722 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4723 } catch (RemoteException e) {
4724 // Ignore if the remote process is no longer available to call back.
4725 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4726 }
4727 });
4728 } finally {
4729 Binder.restoreCallingIdentity(token);
4730 }
4731 }
4732
4733 /**
4734 * Get the transport type for the IMS service registration state.
4735 */
4736 @Override
4737 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004738 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004739 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004740 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4741 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4742 "IMS not available on device.");
4743 }
4744 final long token = Binder.clearCallingIdentity();
4745 try {
4746 Phone phone = getPhone(subId);
4747 if (phone == null) {
4748 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4749 + subId + "'");
4750 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4751 }
4752 phone.getImsRegistrationTech(regTech -> {
4753 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4754 int regTechConverted = (regTech == null)
4755 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4756 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4757 regTechConverted);
4758 try {
4759 consumer.accept(regTechConverted);
4760 } catch (RemoteException e) {
4761 // Ignore if the remote process is no longer available to call back.
4762 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4763 }
4764 });
4765 } finally {
4766 Binder.restoreCallingIdentity(token);
4767 }
4768 }
4769
shilu366312e2019-12-17 09:28:10 -08004770 /**
4771 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4772 * @param subId The subscription to use to check the configuration.
4773 * @param c The callback that will be used to send the result.
4774 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004775 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004776 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4777 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004778 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004779 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004780 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4781 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4782 "IMS not available on device.");
4783 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004784 final long token = Binder.clearCallingIdentity();
4785 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004786 int slotId = getSlotIndexOrException(subId);
4787 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004788
4789 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4790 if (controller != null) {
4791 ImsManager imsManager = controller.getImsManager(subId);
4792 if (imsManager != null) {
4793 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4794 } else {
4795 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4796 }
4797 } else {
4798 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4799 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004800 } catch (ImsException e) {
4801 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004802 } finally {
4803 Binder.restoreCallingIdentity(token);
4804 }
4805 }
4806
shilu366312e2019-12-17 09:28:10 -08004807 /**
4808 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4809 * @param subId The subscription to use to check the configuration.
4810 * @param c The callback that will be used to send the result.
4811 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004812 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004813 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004814 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004815 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004816 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4817 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4818 }
Meng Wangafbc5852019-09-19 17:37:13 -07004819
4820 final long token = Binder.clearCallingIdentity();
4821 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004822 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4823 if (controller != null) {
4824 ImsManager imsManager = controller.getImsManager(subId);
4825 if (imsManager != null) {
4826 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4827 } else {
4828 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4829 + " is inactive, ignoring unregister.");
4830 // If the ImsManager is not valid, just return, since the callback
4831 // will already have been removed internally.
4832 }
4833 }
Meng Wangafbc5852019-09-19 17:37:13 -07004834 } finally {
4835 Binder.restoreCallingIdentity(token);
4836 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004837 }
4838
4839 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004840 public boolean isCapable(int subId, int capability, int regTech) {
4841 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004842
4843 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4844 FEATURE_TELEPHONY_IMS, "isCapable");
4845
Brad Ebinger35c841c2018-10-01 10:40:55 -07004846 final long token = Binder.clearCallingIdentity();
4847 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004848 int slotId = getSlotIndexOrException(subId);
4849 verifyImsMmTelConfiguredOrThrow(slotId);
4850 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4851 } catch (com.android.ims.ImsException e) {
4852 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4853 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004854 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004855 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4856 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004857 } finally {
4858 Binder.restoreCallingIdentity(token);
4859 }
4860 }
4861
4862 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004863 public boolean isAvailable(int subId, int capability, int regTech) {
4864 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004865
4866 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4867 FEATURE_TELEPHONY_IMS, "isAvailable");
4868
Brad Ebinger35c841c2018-10-01 10:40:55 -07004869 final long token = Binder.clearCallingIdentity();
4870 try {
4871 Phone phone = getPhone(subId);
4872 if (phone == null) return false;
4873 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004874 } catch (com.android.ims.ImsException e) {
4875 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4876 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004877 } finally {
4878 Binder.restoreCallingIdentity(token);
4879 }
4880 }
4881
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004882 /**
4883 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4884 * subscription.
4885 * @param subId The subscription to use to check the configuration.
4886 * @param callback The callback that will be used to send the result.
4887 * @param capability The MmTelFeature capability that will be used to send the result.
4888 * @param transportType The transport type of the MmTelFeature capability.
4889 */
4890 @Override
4891 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4892 int transportType) {
4893 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004894 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4895 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4896 "IMS not available on device.");
4897 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004898 final long token = Binder.clearCallingIdentity();
4899 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004900 int slotId = getSlotIndex(subId);
4901 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4902 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4903 + subId + "'");
4904 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4905 }
4906 verifyImsMmTelConfiguredOrThrow(slotId);
4907 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4908 transportType, aBoolean -> {
4909 try {
4910 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4911 } catch (RemoteException e) {
4912 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4913 + "running. Ignore");
4914 }
4915 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004916 } catch (ImsException e) {
4917 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004918 } finally {
4919 Binder.restoreCallingIdentity(token);
4920 }
4921 }
4922
shilu366312e2019-12-17 09:28:10 -08004923 /**
4924 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4925 * @param subId The subscription to use to check the configuration.
4926 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004927 @Override
4928 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004929 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004930 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004931
joonhunshin4ac60942023-11-15 15:23:39 +00004932 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4933 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4934
Brad Ebinger35c841c2018-10-01 10:40:55 -07004935 final long token = Binder.clearCallingIdentity();
4936 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004937 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004938 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004939 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004940 } catch (ImsException e) {
4941 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004942 } finally {
4943 Binder.restoreCallingIdentity(token);
4944 }
4945 }
4946
4947 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004948 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004950 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004951
4952 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4953 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4954
Brad Ebinger35c841c2018-10-01 10:40:55 -07004955 final long identity = Binder.clearCallingIdentity();
4956 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004957 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004958 // This setting doesn't require an active ImsService connection, so do not verify. The
4959 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004960 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004961 } catch (ImsException e) {
4962 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004963 } finally {
4964 Binder.restoreCallingIdentity(identity);
4965 }
4966 }
4967
shilu366312e2019-12-17 09:28:10 -08004968 /**
4969 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4970 * @param subId The subscription to use to check the configuration.
4971 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004972 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004973 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004974 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004975 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004976
4977 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4978 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4979
Brad Ebinger35c841c2018-10-01 10:40:55 -07004980 final long identity = Binder.clearCallingIdentity();
4981 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004982 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004983 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004984 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004985 } catch (ImsException e) {
4986 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004987 } finally {
4988 Binder.restoreCallingIdentity(identity);
4989 }
4990 }
4991
4992 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004993 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004995 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004996
4997 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4998 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4999
Brad Ebinger35c841c2018-10-01 10:40:55 -07005000 final long identity = Binder.clearCallingIdentity();
5001 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005002 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005003 // This setting doesn't require an active ImsService connection, so do not verify. The
5004 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005005 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005006 } catch (ImsException e) {
5007 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005008 } finally {
5009 Binder.restoreCallingIdentity(identity);
5010 }
5011 }
5012
shilu366312e2019-12-17 09:28:10 -08005013 /**
5014 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5015 * @param subId The subscription to use to check the configuration.
5016 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005017 @Override
5018 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005019 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005020 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005021
5022 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5023 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5024
Brad Ebinger35c841c2018-10-01 10:40:55 -07005025 final long identity = Binder.clearCallingIdentity();
5026 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005027 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005028 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005029 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005030 } catch (ImsException e) {
5031 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005032 } finally {
5033 Binder.restoreCallingIdentity(identity);
5034 }
5035 }
5036
5037 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005038 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005040 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005041
5042 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5043 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5044
Brad Ebinger35c841c2018-10-01 10:40:55 -07005045 final long identity = Binder.clearCallingIdentity();
5046 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005047 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005048 // This setting doesn't require an active ImsService connection, so do not verify. The
5049 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005050 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005051 } catch (ImsException e) {
5052 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005053 } finally {
5054 Binder.restoreCallingIdentity(identity);
5055 }
5056 }
5057
shilu366312e2019-12-17 09:28:10 -08005058 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005059 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5060 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5061 * @param subId The subscription to use to check the configuration.
5062 */
5063 @Override
5064 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005065 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005066 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005067
5068 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5069 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5070
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005071 final long identity = Binder.clearCallingIdentity();
5072 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005073 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005074 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005075 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005076 } catch (ImsException e) {
5077 throw new ServiceSpecificException(e.getCode());
5078 } finally {
5079 Binder.restoreCallingIdentity(identity);
5080 }
5081 }
5082
5083 /**
5084 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5085 * Requires MODIFY_PHONE_STATE permission.
5086 * @param subId The subscription to use to check the configuration.
5087 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5088 * false otherwise
5089 */
5090 @Override
5091 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5093 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005094
5095 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5096 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5097
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005098 final long identity = Binder.clearCallingIdentity();
5099 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005100 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005101 // This setting doesn't require an active ImsService connection, so do not verify. The
5102 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005103 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005104 } catch (ImsException e) {
5105 throw new ServiceSpecificException(e.getCode());
5106 } finally {
5107 Binder.restoreCallingIdentity(identity);
5108 }
5109 }
5110
5111 /**
shilu366312e2019-12-17 09:28:10 -08005112 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5113 * @param subId The subscription to use to check the configuration.
5114 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005115 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005116
Brad Ebinger35c841c2018-10-01 10:40:55 -07005117 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005118 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005119 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005120
5121 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5122 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5123
Brad Ebinger35c841c2018-10-01 10:40:55 -07005124 final long identity = Binder.clearCallingIdentity();
5125 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005126 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005127 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005128 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005129 } catch (ImsException e) {
5130 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005131 } finally {
5132 Binder.restoreCallingIdentity(identity);
5133 }
5134 }
5135
5136 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005137 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005139 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005140
5141 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5142 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5143
Brad Ebinger35c841c2018-10-01 10:40:55 -07005144 final long identity = Binder.clearCallingIdentity();
5145 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005146 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005147 // This setting doesn't require an active ImsService connection, so do not verify. The
5148 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005149 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005150 } catch (ImsException e) {
5151 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
5155 }
5156
5157 @Override
5158 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5160 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005161
5162 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5163 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5164
Brad Ebinger35c841c2018-10-01 10:40:55 -07005165 final long identity = Binder.clearCallingIdentity();
5166 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005167 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005168 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005169 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005170 } catch (ImsException e) {
5171 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
5175 }
5176
shilu366312e2019-12-17 09:28:10 -08005177 /**
5178 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5179 * @param subId The subscription to use to check the configuration.
5180 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005181 @Override
5182 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005183 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005184 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005185
5186 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5187 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5188
Brad Ebinger35c841c2018-10-01 10:40:55 -07005189 final long identity = Binder.clearCallingIdentity();
5190 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005191 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005192 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005193 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005194 } catch (ImsException e) {
5195 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005196 } finally {
5197 Binder.restoreCallingIdentity(identity);
5198 }
5199 }
5200
5201 @Override
5202 public void setVoWiFiModeSetting(int subId, int mode) {
5203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5204 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005205
5206 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5207 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5208
Brad Ebinger35c841c2018-10-01 10:40:55 -07005209 final long identity = Binder.clearCallingIdentity();
5210 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005211 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005212 // This setting doesn't require an active ImsService connection, so do not verify. The
5213 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005214 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005215 } catch (ImsException e) {
5216 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005217 } finally {
5218 Binder.restoreCallingIdentity(identity);
5219 }
5220 }
5221
5222 @Override
5223 public int getVoWiFiRoamingModeSetting(int subId) {
5224 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005225
5226 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5227 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5228
Brad Ebinger35c841c2018-10-01 10:40:55 -07005229 final long identity = Binder.clearCallingIdentity();
5230 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005231 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005232 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005233 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005234 } catch (ImsException e) {
5235 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
5239 }
5240
5241 @Override
5242 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5244 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005245
5246 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5247 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5248
Brad Ebinger35c841c2018-10-01 10:40:55 -07005249 final long identity = Binder.clearCallingIdentity();
5250 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005251 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005252 // This setting doesn't require an active ImsService connection, so do not verify. The
5253 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005254 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005255 } catch (ImsException e) {
5256 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
5260 }
5261
5262 @Override
5263 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5265 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005266
5267 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5268 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5269
Brad Ebinger35c841c2018-10-01 10:40:55 -07005270 final long identity = Binder.clearCallingIdentity();
5271 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005272 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005273 // This setting doesn't require an active ImsService connection, so do not verify. The
5274 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005275 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005276 } catch (ImsException e) {
5277 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005278 } finally {
5279 Binder.restoreCallingIdentity(identity);
5280 }
5281 }
5282
shilu366312e2019-12-17 09:28:10 -08005283 /**
5284 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5285 * @param subId The subscription to use to check the configuration.
5286 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005287 @Override
5288 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005289 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005290 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005291
5292 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5293 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5294
Brad Ebinger35c841c2018-10-01 10:40:55 -07005295 final long identity = Binder.clearCallingIdentity();
5296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005298 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005299 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005300 } catch (ImsException e) {
5301 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
5305 }
5306
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005307 @Override
5308 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5309 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005310
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005311 final long identity = Binder.clearCallingIdentity();
5312 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005313 if (!isImsAvailableOnDevice()) {
5314 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5315 "IMS not available on device.");
5316 }
5317 int slotId = getSlotIndexOrException(subId);
5318 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005319
5320 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5321 if (controller != null) {
5322 ImsManager imsManager = controller.getImsManager(subId);
5323 if (imsManager != null) {
5324 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5325 } else {
5326 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5327 }
5328 } else {
5329 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5330 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005331 } catch (ImsException e) {
5332 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
5336 }
5337
5338 @Override
5339 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5340 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005341
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005342 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005343 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5344 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5345 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005346 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005347 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5348 if (controller != null) {
5349 ImsManager imsManager = controller.getImsManager(subId);
5350 if (imsManager != null) {
5351 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5352 } else {
5353 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5354 + " is inactive, ignoring unregister.");
5355 // If the ImsManager is not valid, just return, since the callback will already
5356 // have been removed internally.
5357 }
5358 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005359 } finally {
5360 Binder.restoreCallingIdentity(identity);
5361 }
5362 }
5363
joonhunshincffb7fc2021-11-28 07:32:01 +00005364 @Override
5365 public void registerFeatureProvisioningChangedCallback(int subId,
5366 IFeatureProvisioningCallback callback) {
5367 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5368 mApp, subId, "registerFeatureProvisioningChangedCallback");
5369
5370 final long identity = Binder.clearCallingIdentity();
5371 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5372 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5373 }
5374
joonhunshin91bc1952022-04-29 08:47:15 +00005375 try {
5376 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5377 if (controller == null) {
5378 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5379 "Device does not support IMS");
5380 }
5381 controller.addFeatureProvisioningChangedCallback(subId, callback);
5382 } finally {
5383 Binder.restoreCallingIdentity(identity);
5384 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005385 }
5386
5387 @Override
5388 public void unregisterFeatureProvisioningChangedCallback(int subId,
5389 IFeatureProvisioningCallback callback) {
5390 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5391 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5392
5393 final long identity = Binder.clearCallingIdentity();
5394 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5395 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5396 }
5397
joonhunshin91bc1952022-04-29 08:47:15 +00005398 try {
5399 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5400 if (controller == null) {
5401 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5402 return;
5403 }
5404 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5405 } finally {
5406 Binder.restoreCallingIdentity(identity);
5407 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005408 }
allenwtsu99c623b2020-01-03 18:24:23 +08005409
5410 private void checkModifyPhoneStatePermission(int subId, String message) {
5411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5412 message);
5413 }
5414
allenwtsu99c623b2020-01-03 18:24:23 +08005415 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005416 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005417 boolean isProvisioned) {
5418 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5419
joonhunshin4ac60942023-11-15 15:23:39 +00005420 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5421 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5422
allenwtsu99c623b2020-01-03 18:24:23 +08005423 final long identity = Binder.clearCallingIdentity();
5424 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005425 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5426 if (controller == null) {
5427 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5428 return;
5429 }
5430 controller.setRcsProvisioningStatusForCapability(
5431 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005432 } finally {
5433 Binder.restoreCallingIdentity(identity);
5434 }
allenwtsu99c623b2020-01-03 18:24:23 +08005435 }
5436
5437
5438 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005439 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5440 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5441 mApp, subId, "getRcsProvisioningStatusForCapability");
5442
joonhunshin4ac60942023-11-15 15:23:39 +00005443 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5444 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5445
allenwtsu99c623b2020-01-03 18:24:23 +08005446 final long identity = Binder.clearCallingIdentity();
5447 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005448 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5449 if (controller == null) {
5450 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5451
5452 // device does not support IMS, this method will return true always.
5453 return true;
5454 }
5455 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005456 } finally {
5457 Binder.restoreCallingIdentity(identity);
5458 }
5459 }
5460
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005461 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005462 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5463 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005464 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005465
joonhunshin4ac60942023-11-15 15:23:39 +00005466 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5467 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5468
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005469 final long identity = Binder.clearCallingIdentity();
5470 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005471 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5472 if (controller == null) {
5473 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5474 return;
5475 }
5476 controller.setImsProvisioningStatusForCapability(
5477 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005478 } finally {
5479 Binder.restoreCallingIdentity(identity);
5480 }
5481 }
5482
5483 @Override
5484 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005485 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5486 mApp, subId, "getProvisioningStatusForCapability");
5487
joonhunshin4ac60942023-11-15 15:23:39 +00005488 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5489 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5490
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005491 final long identity = Binder.clearCallingIdentity();
5492 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005493 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5494 if (controller == null) {
5495 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005496
joonhunshin91bc1952022-04-29 08:47:15 +00005497 // device does not support IMS, this method will return true always.
5498 return true;
5499 }
5500 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005501 } finally {
5502 Binder.restoreCallingIdentity(identity);
5503 }
5504 }
5505
5506 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005507 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5508 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5509 mApp, subId, "isProvisioningRequiredForCapability");
5510
joonhunshin4ac60942023-11-15 15:23:39 +00005511 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5512 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5513
joonhunshincffb7fc2021-11-28 07:32:01 +00005514 final long identity = Binder.clearCallingIdentity();
5515 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005516 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5517 if (controller == null) {
5518 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5519
5520 // device does not support IMS, this method will return false
5521 return false;
5522 }
5523 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005524 } finally {
5525 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005526 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005527 }
5528
5529 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005530 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5531 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5532 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005533
joonhunshin4ac60942023-11-15 15:23:39 +00005534 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5535 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5536
joonhunshincffb7fc2021-11-28 07:32:01 +00005537 final long identity = Binder.clearCallingIdentity();
5538 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005539 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5540 if (controller == null) {
5541 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5542
5543 // device does not support IMS, this method will return false
5544 return false;
5545 }
5546 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005547 } finally {
5548 Binder.restoreCallingIdentity(identity);
5549 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005550 }
5551
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005552 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005553 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005554 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5555 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5556 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005557 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5558 mApp, subId, "getImsProvisioningInt");
5559
joonhunshin4ac60942023-11-15 15:23:39 +00005560 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5561 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5562
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005563 final long identity = Binder.clearCallingIdentity();
5564 try {
5565 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005566 int slotId = getSlotIndex(subId);
5567 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5568 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5569 + subId + "' for key:" + key);
5570 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5571 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005572
joonhunshin91bc1952022-04-29 08:47:15 +00005573 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5574 if (controller == null) {
5575 loge("getImsProvisioningInt: Device does not support IMS");
5576
5577 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5578 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5579 }
5580 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005581 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5582 return retVal;
5583 }
5584
calvinpanb5a34062021-02-08 19:59:36 +08005585 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005586 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005587 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5588 + subId + "' for key:" + key);
5589 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
5593 }
5594
5595 @Override
5596 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005597 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5598 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5599 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005600 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5601 mApp, subId, "getImsProvisioningString");
5602
joonhunshin4ac60942023-11-15 15:23:39 +00005603 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5604 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5605
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005606 final long identity = Binder.clearCallingIdentity();
5607 try {
5608 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005609 int slotId = getSlotIndex(subId);
5610 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5611 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5612 + subId + "' for key:" + key);
5613 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5614 }
calvinpanb5a34062021-02-08 19:59:36 +08005615 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005616 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005617 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5618 + subId + "' for key:" + key);
5619 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
5623 }
5624
5625 @Override
5626 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005627 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5628 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5629 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5631 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005632
joonhunshin4ac60942023-11-15 15:23:39 +00005633 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5634 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5635
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005639 int slotId = getSlotIndex(subId);
5640 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5641 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5642 + subId + "' for key:" + key);
5643 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5644 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005645
joonhunshin91bc1952022-04-29 08:47:15 +00005646 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5647 if (controller == null) {
5648 loge("setImsProvisioningInt: Device does not support IMS");
5649
5650 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5651 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5652 }
5653 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005654 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5655 return retVal;
5656 }
5657
calvinpanb5a34062021-02-08 19:59:36 +08005658 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5659 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005660 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005661 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005662 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
5666 }
5667
5668 @Override
5669 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005670 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5671 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5672 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5674 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005675
5676 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5677 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5678
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005679 final long identity = Binder.clearCallingIdentity();
5680 try {
5681 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005682 int slotId = getSlotIndex(subId);
5683 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5684 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5685 + subId + "' for key:" + key);
5686 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5687 }
calvinpanb5a34062021-02-08 19:59:36 +08005688 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5689 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005690 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005691 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005692 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005693 } finally {
5694 Binder.restoreCallingIdentity(identity);
5695 }
5696 }
5697
Brad Ebinger919631e2021-06-02 17:46:35 -07005698 /**
5699 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5700 * for the given slot ID or no ImsResolver instance has been created.
5701 * @param slotId The slot ID that the IMS service is created for.
5702 * @throws ImsException If there is no ImsService configured for this slot.
5703 */
5704 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5705 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5706 ImsFeature.FEATURE_MMTEL)) {
5707 throw new ImsException("This subscription does not support MMTEL over IMS",
5708 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5709 }
5710 }
5711
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005712 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005713 int slotId = SubscriptionManager.getSlotIndex(subId);
5714 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005715 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5716 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005717 }
5718 return slotId;
5719 }
5720
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005721 private int getSlotIndex(int subId) {
5722 int slotId = SubscriptionManager.getSlotIndex(subId);
5723 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5724 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5725 }
5726 return slotId;
5727 }
5728
Wink Saville36469e72014-06-11 15:17:00 -07005729 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005730 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005731 */
5732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005733 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5734 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005735 try {
5736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5737 } catch (SecurityException se) {
5738 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5739 throw new SecurityException("Package " + callingPackage + " does not belong to "
5740 + Binder.getCallingUid());
5741 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005742 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005743 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005744 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005745 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005746 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005747 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005748 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005749 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5750 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005751
joonhunshin4ac60942023-11-15 15:23:39 +00005752 enforceTelephonyFeatureWithException(callingPackage,
5753 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5754
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755 final long identity = Binder.clearCallingIdentity();
5756 try {
5757 final Phone phone = getPhone(subId);
5758 if (phone != null) {
5759 return phone.getServiceState().getDataNetworkType();
5760 } else {
5761 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5762 }
5763 } finally {
5764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005766 }
5767
5768 /**
5769 * Returns the data network type
5770 */
5771 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005772 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005773 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005774 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005775 }
5776
5777 /**
5778 * Returns the data network type for a subId
5779 */
5780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005781 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5782 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005783 String functionName = "getDataNetworkTypeForSubscriber";
5784 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5785 mApp, functionName)) {
5786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5787 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5788 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5789 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005790 }
5791
joonhunshin4ac60942023-11-15 15:23:39 +00005792 enforceTelephonyFeatureWithException(callingPackage,
5793 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 final long identity = Binder.clearCallingIdentity();
5796 try {
5797 final Phone phone = getPhone(subId);
5798 if (phone != null) {
5799 return phone.getServiceState().getDataNetworkType();
5800 } else {
5801 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5802 }
5803 } finally {
5804 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005805 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005806 }
5807
5808 /**
Wink Saville36469e72014-06-11 15:17:00 -07005809 * Returns the Voice network type for a subId
5810 */
5811 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005812 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5813 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005814 String functionName = "getVoiceNetworkTypeForSubscriber";
5815 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5816 mApp, functionName)) {
5817 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5818 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5819 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5820 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005821 }
5822
joonhunshin4ac60942023-11-15 15:23:39 +00005823 enforceTelephonyFeatureWithException(callingPackage,
5824 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826 final long identity = Binder.clearCallingIdentity();
5827 try {
5828 final Phone phone = getPhone(subId);
5829 if (phone != null) {
5830 return phone.getServiceState().getVoiceNetworkType();
5831 } else {
5832 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5833 }
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005837 }
5838
5839 /**
5840 * @return true if a ICC card is present
5841 */
5842 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005843 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005844 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005845 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005846 }
5847
5848 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005849 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005850 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005851 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005852 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07005853 if (!mApp.getResources().getBoolean(
5854 com.android.internal.R.bool.config_force_phone_globals_creation)) {
5855 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5856 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5857 }
joonhunshin4ac60942023-11-15 15:23:39 +00005858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 final long identity = Binder.clearCallingIdentity();
5860 try {
5861 final Phone phone = PhoneFactory.getPhone(slotIndex);
5862 if (phone != null) {
5863 return phone.getIccCard().hasIccCard();
5864 } else {
5865 return false;
5866 }
5867 } finally {
5868 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005870 }
5871
5872 /**
5873 * Return if the current radio is LTE on CDMA. This
5874 * is a tri-state return value as for a period of time
5875 * the mode may be unknown.
5876 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005877 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005878 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005879 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005880 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005881 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005882 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5883 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5884 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005885 }
5886
Sanket Padawe356d7632015-06-22 14:03:32 -07005887 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005888 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5889 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005890 try {
5891 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5892 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005893 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5894 }
5895
joonhunshin4ac60942023-11-15 15:23:39 +00005896 enforceTelephonyFeatureWithException(callingPackage,
5897 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005899 final long identity = Binder.clearCallingIdentity();
5900 try {
5901 final Phone phone = getPhone(subId);
5902 if (phone == null) {
5903 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5904 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005905 return TelephonyProperties.lte_on_cdma_device()
5906 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907 }
5908 } finally {
5909 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005910 }
Wink Saville36469e72014-06-11 15:17:00 -07005911 }
5912
Wink Saville36469e72014-06-11 15:17:00 -07005913 /**
5914 * {@hide}
5915 * Returns Default subId, 0 in the case of single standby.
5916 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005917 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005918 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005919 }
5920
Shishir Agrawala9f32182016-04-12 12:00:16 -07005921 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005922 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005923 }
5924
Wink Savilleb564aae2014-10-23 10:18:09 -07005925 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005926 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005927 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005928
Pengquan Menge92a50d2018-09-21 15:54:48 -07005929 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005930 return getSubscriptionManagerService().isActiveSubId(subId,
5931 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005932 }
5933
Ihab Awadf2177b72013-11-25 13:33:23 -08005934 /**
5935 * @see android.telephony.TelephonyManager.WifiCallingChoices
5936 */
5937 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938 final long identity = Binder.clearCallingIdentity();
5939 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005940 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5942 getWhenToMakeWifiCallsDefaultPreference());
5943 } finally {
5944 Binder.restoreCallingIdentity(identity);
5945 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005946 }
5947
5948 /**
5949 * @see android.telephony.TelephonyManager.WifiCallingChoices
5950 */
5951 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 final long identity = Binder.clearCallingIdentity();
5953 try {
5954 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005955 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005960 }
5961
Sailesh Nepald1e68152013-12-12 19:08:02 -08005962 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005963 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005964 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005965 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005966
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005967 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5968 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5969 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005970 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005971 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005972 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005973 }
5974 return PhoneFactory.getPhone(phoneId);
5975 }
5976
Shishir Agrawal566b7612013-10-28 14:41:00 -07005977 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005978 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005979 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005980
Rambo Wanga1782702021-11-10 20:15:19 -08005981 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5982 /*message=*/ "iccOpenLogicalChannel");
5983
5984 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5985 // Verify that the callingPackage in the request belongs to the calling UID
5986 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5987
joonhunshin4ac60942023-11-15 15:23:39 +00005988 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5989 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5990
Rambo Wanga1782702021-11-10 20:15:19 -08005991 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005992 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005993
Rambo Wanga1782702021-11-10 20:15:19 -08005994 private Phone getPhoneFromValidIccLogicalChannelRequest(
5995 @NonNull IccLogicalChannelRequest request, String message) {
5996 Phone phone;
5997 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5999 mApp, request.subId, message);
6000 phone = getPhoneFromSubId(request.subId);
6001 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6002 enforceModifyPermission();
6003 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6004 } else {
6005 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006006 }
Rambo Wanga1782702021-11-10 20:15:19 -08006007 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006008 }
6009
6010 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006011 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 final long identity = Binder.clearCallingIdentity();
6013 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006014 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006016 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6017 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006018 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6019 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 loge("The calling package is not allowed to access ISD-R.");
6021 throw new SecurityException(
6022 "The calling package is not allowed to access ISD-R.");
6023 }
Derek Tan740e1672017-06-27 14:56:27 -07006024 }
Derek Tan740e1672017-06-27 14:56:27 -07006025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006027 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6028 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 return response;
6030 } finally {
6031 Binder.restoreCallingIdentity(identity);
6032 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006033 }
6034
6035 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006036 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006037 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6038 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6039
Rambo Wanga1782702021-11-10 20:15:19 -08006040 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6041 /*message=*/"iccCloseLogicalChannel");
6042
6043 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6044
6045 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006046 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006047
Rambo Wanga1782702021-11-10 20:15:19 -08006048 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6049 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006050 // before this feature is enabled, this API should only return false if
6051 // the operation fails instead of throwing runtime exception for
6052 // backward-compatibility.
6053 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6054 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 final long identity = Binder.clearCallingIdentity();
6056 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006057 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006058 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 }
Chen Xue9d737e2022-01-01 23:41:31 -08006060 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006061 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006062 Boolean success = false;
6063 if (result instanceof RuntimeException) {
6064 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006065 if (shouldThrowExceptionOnFailure) {
6066 throw (RuntimeException) result;
6067 } else {
6068 return false;
6069 }
Chen Xue9d737e2022-01-01 23:41:31 -08006070 } else if (result instanceof Boolean) {
6071 success = (Boolean) result;
6072 } else {
6073 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6074 }
Rambo Wanga1782702021-11-10 20:15:19 -08006075 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 return success;
6077 } finally {
6078 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006079 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006080 }
6081
6082 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006083 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006084 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6086 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006087
6088 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6089 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6090
Jordan Liu4c733742019-02-28 12:03:40 -08006091 if (DBG) {
6092 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6093 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6094 + p3 + " data=" + data);
6095 }
6096 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6097 command, p1, p2, p3, data);
6098 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006099
Jordan Liu4c733742019-02-28 12:03:40 -08006100 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006101 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006102 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006103 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006104
6105 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6106 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6107 "iccTransmitApduLogicalChannelBySlot");
6108
Jordan Liu4c733742019-02-28 12:03:40 -08006109 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006110 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006111 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6112 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006113 }
6114 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006115 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6116 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006117 }
6118
6119 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6120 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 final long identity = Binder.clearCallingIdentity();
6122 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006123 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124 return "";
6125 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006128 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6129 null /* workSource */);
6130 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 // Append the returned status code to the end of the response payload.
6133 String s = Integer.toHexString(
6134 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6135 if (response.payload != null) {
6136 s = IccUtils.bytesToHexString(response.payload) + s;
6137 }
6138 return s;
6139 } finally {
6140 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006141 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006142 }
Jake Hambye994d462014-02-03 13:10:13 -08006143
Evan Charltonc66da362014-05-16 14:06:40 -07006144 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006145 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6146 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6148 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006150
6151 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6152 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6153
Jordan Liu4c733742019-02-28 12:03:40 -08006154 if (DBG) {
6155 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6156 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6157 }
6158 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6159 cla, command, p1, p2, p3, data);
6160 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006161
Jordan Liu4c733742019-02-28 12:03:40 -08006162 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006163 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006164 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006165 enforceModifyPermission();
6166 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006167
6168 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6169 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6170
Jordan Liu4c733742019-02-28 12:03:40 -08006171 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006172 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006173 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6174 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006175 }
6176
6177 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006178 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6179 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006180 }
6181
6182 // open APDU basic channel assuming the caller has sufficient permissions
6183 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6184 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006185 final long identity = Binder.clearCallingIdentity();
6186 try {
6187 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6188 && TextUtils.equals(ISDR_AID, data)) {
6189 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006190 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6191 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 if (bestComponent == null
6193 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6194 loge("The calling package is not allowed to select ISD-R.");
6195 throw new SecurityException(
6196 "The calling package is not allowed to select ISD-R.");
6197 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006198 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006200 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006201 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6202 null /* workSource */);
6203 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006205 // Append the returned status code to the end of the response payload.
6206 String s = Integer.toHexString(
6207 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6208 if (response.payload != null) {
6209 s = IccUtils.bytesToHexString(response.payload) + s;
6210 }
6211 return s;
6212 } finally {
6213 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006214 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006215 }
6216
6217 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006218 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006219 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6221 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006222
joonhunshin4ac60942023-11-15 15:23:39 +00006223 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6224 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226 final long identity = Binder.clearCallingIdentity();
6227 try {
6228 if (DBG) {
6229 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6230 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6231 }
6232
6233 IccIoResult response =
6234 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6235 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6236 subId);
6237
6238 if (DBG) {
6239 log("Exchange SIM_IO [R]" + response);
6240 }
6241
6242 byte[] result = null;
6243 int length = 2;
6244 if (response.payload != null) {
6245 length = 2 + response.payload.length;
6246 result = new byte[length];
6247 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6248 } else {
6249 result = new byte[length];
6250 }
6251
6252 result[length - 1] = (byte) response.sw2;
6253 result[length - 2] = (byte) response.sw1;
6254 return result;
6255 } finally {
6256 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006257 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006258 }
6259
Nathan Haroldb3014052017-01-25 15:57:32 -08006260 /**
6261 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6262 * on a particular subscription
6263 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006264 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6265 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006267 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006268 return null;
6269 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270
joonhunshin4ac60942023-11-15 15:23:39 +00006271 enforceTelephonyFeatureWithException(callingPackage,
6272 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274 final long identity = Binder.clearCallingIdentity();
6275 try {
6276 if (appType != TelephonyManager.APPTYPE_USIM
6277 && appType != TelephonyManager.APPTYPE_SIM) {
6278 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6279 return null;
6280 }
6281 Object response = sendRequest(
6282 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6283 if (response instanceof String[]) {
6284 return (String[]) response;
6285 }
yincheng zhao2737e882019-09-06 17:06:54 -07006286 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006287 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006288 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 } finally {
6290 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006291 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006292 }
6293
yincheng zhao2737e882019-09-06 17:06:54 -07006294 /**
6295 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6296 * subscription.
6297 *
6298 * @param subId the id of the subscription.
6299 * @param appType the uicc app type, must be USIM or SIM.
6300 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6301 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006302 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006303 * @return number of fplmns that is successfully written to the SIM.
6304 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006305 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6306 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6308 mApp, subId, "setForbiddenPlmns");
6309
joonhunshin4ac60942023-11-15 15:23:39 +00006310 enforceTelephonyFeatureWithException(callingPackage,
6311 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6312
yincheng zhao2737e882019-09-06 17:06:54 -07006313 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6314 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6315 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6316 }
6317 if (fplmns == null) {
6318 throw new IllegalArgumentException("Fplmn List provided is null");
6319 }
6320 for (String fplmn : fplmns) {
6321 if (!CellIdentity.isValidPlmn(fplmn)) {
6322 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6323 }
6324 }
6325 final long identity = Binder.clearCallingIdentity();
6326 try {
6327 Object response = sendRequest(
6328 CMD_SET_FORBIDDEN_PLMNS,
6329 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6330 subId);
6331 return (int) response;
6332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
6335 }
6336
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006337 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006338 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6340 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006341
joonhunshin4ac60942023-11-15 15:23:39 +00006342 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6343 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 final long identity = Binder.clearCallingIdentity();
6346 try {
6347 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6348 if (response.payload == null) {
6349 return "";
6350 }
Evan Charltonc66da362014-05-16 14:06:40 -07006351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352 // Append the returned status code to the end of the response payload.
6353 String s = Integer.toHexString(
6354 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6355 s = IccUtils.bytesToHexString(response.payload) + s;
6356 return s;
6357 } finally {
6358 Binder.restoreCallingIdentity(identity);
6359 }
Evan Charltonc66da362014-05-16 14:06:40 -07006360 }
6361
Jake Hambye994d462014-02-03 13:10:13 -08006362 /**
6363 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6364 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6365 *
6366 * @param itemID the ID of the item to read
6367 * @return the NV item as a String, or null on error.
6368 */
6369 @Override
6370 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006371 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6373 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374
6375 final long identity = Binder.clearCallingIdentity();
6376 try {
6377 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006378 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6380 return value;
6381 } finally {
6382 Binder.restoreCallingIdentity(identity);
6383 }
Jake Hambye994d462014-02-03 13:10:13 -08006384 }
6385
6386 /**
6387 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6388 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6389 *
6390 * @param itemID the ID of the item to read
6391 * @param itemValue the value to write, as a String
6392 * @return true on success; false on any failure
6393 */
6394 @Override
6395 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006396 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6398 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399
6400 final long identity = Binder.clearCallingIdentity();
6401 try {
6402 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6403 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006404 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6406 return success;
6407 } finally {
6408 Binder.restoreCallingIdentity(identity);
6409 }
Jake Hambye994d462014-02-03 13:10:13 -08006410 }
6411
6412 /**
6413 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6414 * Used for device configuration by some CDMA operators.
6415 *
6416 * @param preferredRoamingList byte array containing the new PRL
6417 * @return true on success; false on any failure
6418 */
6419 @Override
6420 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6422 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423
6424 final long identity = Binder.clearCallingIdentity();
6425 try {
6426 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6427 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6428 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6429 return success;
6430 } finally {
6431 Binder.restoreCallingIdentity(identity);
6432 }
Jake Hambye994d462014-02-03 13:10:13 -08006433 }
6434
6435 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006436 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006437 * Used for device configuration by some CDMA operators.
6438 *
chen xu6dac5ab2018-10-26 17:39:23 -07006439 * @param slotIndex - device slot.
6440 *
Jake Hambye994d462014-02-03 13:10:13 -08006441 * @return true on success; false on any failure
6442 */
6443 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006444 public boolean resetModemConfig(int slotIndex) {
6445 Phone phone = PhoneFactory.getPhone(slotIndex);
6446 if (phone != null) {
6447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6448 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449
joonhunshin4ac60942023-11-15 15:23:39 +00006450 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6451 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6452
chen xu6dac5ab2018-10-26 17:39:23 -07006453 final long identity = Binder.clearCallingIdentity();
6454 try {
6455 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6456 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6457 return success;
6458 } finally {
6459 Binder.restoreCallingIdentity(identity);
6460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461 }
chen xu6dac5ab2018-10-26 17:39:23 -07006462 return false;
6463 }
6464
6465 /**
6466 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6467 *
6468 * @param slotIndex - device slot.
6469 *
6470 * @return true on success; false on any failure
6471 */
6472 @Override
6473 public boolean rebootModem(int slotIndex) {
6474 Phone phone = PhoneFactory.getPhone(slotIndex);
6475 if (phone != null) {
6476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6477 mApp, phone.getSubId(), "rebootModem");
6478
joonhunshin4ac60942023-11-15 15:23:39 +00006479 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6480 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6481
chen xu6dac5ab2018-10-26 17:39:23 -07006482 final long identity = Binder.clearCallingIdentity();
6483 try {
6484 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6485 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6486 return success;
6487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
6490 }
6491 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006492 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006493
Brad Ebinger51f743a2017-01-23 13:50:20 -08006494 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006495 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6496 * {@link #disableIms(int)}.
6497 * @param slotIndex device slot.
6498 */
6499 public void resetIms(int slotIndex) {
6500 enforceModifyPermission();
6501
joonhunshin4ac60942023-11-15 15:23:39 +00006502 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6503 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6504
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006505 final long identity = Binder.clearCallingIdentity();
6506 try {
6507 if (mImsResolver == null) {
6508 // may happen if the does not support IMS.
6509 return;
6510 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006511 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006512 } finally {
6513 Binder.restoreCallingIdentity(identity);
6514 }
6515 }
6516
6517 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006518 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6519 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006520 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006521 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006522 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006523
6524 final long identity = Binder.clearCallingIdentity();
6525 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006526 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006527 // may happen if the device does not support IMS.
6528 return;
6529 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006530 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531 } finally {
6532 Binder.restoreCallingIdentity(identity);
6533 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006534 }
6535
6536 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006537 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6538 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006539 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006540 public void disableIms(int slotId) {
6541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542
6543 final long identity = Binder.clearCallingIdentity();
6544 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006545 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006546 // may happen if the device does not support IMS.
6547 return;
6548 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006549 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550 } finally {
6551 Binder.restoreCallingIdentity(identity);
6552 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006553 }
6554
6555 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006556 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6557 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006558 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006559 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006560 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006561 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 Ebinger67b3e042020-09-11 12:45:11 -07006566 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6567 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006568 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006569 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 } finally {
6571 Binder.restoreCallingIdentity(identity);
6572 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006573 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006574 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006575 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6576 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006577 @Override
6578 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006579 enforceModifyPermission();
6580
6581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006584 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006585 } finally {
6586 Binder.restoreCallingIdentity(identity);
6587 }
6588 }
6589
6590 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006591 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006592 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006593 */
6594 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6595 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006596
6597 final long identity = Binder.clearCallingIdentity();
6598 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006599 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006600 // may happen if the device does not support IMS.
6601 return null;
6602 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006603 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 } finally {
6605 Binder.restoreCallingIdentity(identity);
6606 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006607 }
6608
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006609 /**
6610 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006611 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006612 */
6613 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6614 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615
6616 final long identity = Binder.clearCallingIdentity();
6617 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006618 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006619 // may happen if the device does not support IMS.
6620 return null;
6621 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006622 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 } finally {
6624 Binder.restoreCallingIdentity(identity);
6625 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006626 }
6627
Brad Ebinger884c07b2018-02-15 16:17:40 -08006628 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006629 * Sets the ImsService Package Name that Telephony will bind to.
6630 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006631 * @param slotIndex the slot ID that the ImsService should bind for.
6632 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006633 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006634 * @param featureTypes An integer array of feature types associated with a packageName.
6635 * @param packageName The name of the package that the current configuration will be replaced
6636 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006637 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006638 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006639 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6640 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006641 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006643 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645 final long identity = Binder.clearCallingIdentity();
6646 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006647 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006648 // may happen if the device does not support IMS.
6649 return false;
6650 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006651 Map<Integer, String> featureConfig = new HashMap<>();
6652 for (int featureType : featureTypes) {
6653 featureConfig.put(featureType, packageName);
6654 }
6655 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6656 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 } finally {
6658 Binder.restoreCallingIdentity(identity);
6659 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006660 }
6661
6662 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006663 * Clears any carrier ImsService overrides for the slot index specified that were previously
6664 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6665 *
6666 * This should only be used for testing.
6667 *
6668 * @param slotIndex the slot ID that the ImsService should bind for.
6669 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6670 */
6671 @Override
6672 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006673 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6674 "clearCarrierImsServiceOverride");
6675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006676 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006677
6678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 if (mImsResolver == null) {
6681 // may happen if the device does not support IMS.
6682 return false;
6683 }
6684 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
6688 }
6689
6690 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006691 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006692 *
6693 * @param slotId The slot that the ImsService is associated with.
6694 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6695 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006696 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006697 * @return the package name of the ImsService configuration.
6698 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006699 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6700 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006701 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006702 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6703 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 final long identity = Binder.clearCallingIdentity();
6706 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006707 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006708 // may happen if the device does not support IMS.
6709 return "";
6710 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006711 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006712 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6713 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 } finally {
6715 Binder.restoreCallingIdentity(identity);
6716 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006717 }
6718
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006719 /**
6720 * Get the MmTelFeature state associated with the requested subscription id.
6721 * @param subId The subscription that the MmTelFeature is associated with.
6722 * @param callback A callback with an integer containing the
6723 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6724 */
6725 @Override
6726 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6727 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006728 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6729 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6730 "IMS not available on device.");
6731 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006732 final long token = Binder.clearCallingIdentity();
6733 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006734 int slotId = getSlotIndex(subId);
6735 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6736 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6737 + subId + "'");
6738 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6739 }
6740 verifyImsMmTelConfiguredOrThrow(slotId);
6741 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6742 try {
6743 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6744 } catch (RemoteException e) {
6745 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6746 + "Ignore");
6747 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006748 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006749 } catch (ImsException e) {
6750 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006751 } finally {
6752 Binder.restoreCallingIdentity(token);
6753 }
6754 }
6755
Daniel Brightbb5840b2021-01-12 15:48:18 -08006756 /**
6757 * Sets the ims registration state on all valid {@link Phone}s.
6758 */
6759 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761
6762 final long identity = Binder.clearCallingIdentity();
6763 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006764 // NOTE: Before S, this method only set the default phone.
6765 for (final Phone phone : PhoneFactory.getPhones()) {
6766 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6767 phone.setImsRegistrationState(registered);
6768 }
6769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770 } finally {
6771 Binder.restoreCallingIdentity(identity);
6772 }
Wink Saville36469e72014-06-11 15:17:00 -07006773 }
6774
6775 /**
Stuart Scott54788802015-03-30 13:18:01 -07006776 * Set the network selection mode to automatic.
6777 *
6778 */
6779 @Override
6780 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6782 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783
joonhunshin4ac60942023-11-15 15:23:39 +00006784 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6785 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 final long identity = Binder.clearCallingIdentity();
6788 try {
shilufc958392020-01-20 11:36:01 -08006789 if (!isActiveSubscription(subId)) {
6790 return;
6791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006793 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6794 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795 } finally {
6796 Binder.restoreCallingIdentity(identity);
6797 }
Stuart Scott54788802015-03-30 13:18:01 -07006798 }
6799
Jack Yud10cdd42020-09-28 20:28:01 -07006800 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006801 * Ask the radio to connect to the input network and change selection mode to manual.
6802 *
6803 * @param subId the id of the subscription.
6804 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6805 * the operator to attach to.
6806 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6807 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6808 * normal network selection next time.
6809 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006810 */
6811 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006812 public boolean setNetworkSelectionModeManual(
6813 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6815 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006816
joonhunshin4ac60942023-11-15 15:23:39 +00006817 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6818 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6819
Jack Yu285100e2022-12-02 22:48:35 -08006820 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006821 if (!isActiveSubscription(subId)) {
6822 return false;
6823 }
6824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006826 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006827 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006828 if (DBG) {
6829 log("setNetworkSelectionModeManual: subId: " + subId
6830 + " operator: " + operatorInfo);
6831 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6833 } finally {
6834 Binder.restoreCallingIdentity(identity);
6835 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006836 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006837 /**
shilu84f6e8b2019-12-19 13:58:01 -08006838 * Get the manual network selection
6839 *
6840 * @param subId the id of the subscription.
6841 *
6842 * @return the previously saved user selected PLMN
6843 */
6844 @Override
6845 public String getManualNetworkSelectionPlmn(int subId) {
6846 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006847 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6848 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006849
joonhunshin4ac60942023-11-15 15:23:39 +00006850 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6851 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6852
shilu84f6e8b2019-12-19 13:58:01 -08006853 final long identity = Binder.clearCallingIdentity();
6854 try {
6855 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006856 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006857 }
6858
6859 final Phone phone = getPhone(subId);
6860 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006861 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006862 }
6863 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6864 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006865 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006866 } finally {
6867 Binder.restoreCallingIdentity(identity);
6868 }
6869 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006870
6871 /**
6872 * Scans for available networks.
6873 */
6874 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006875 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6876 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6878 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006879 LocationAccessPolicy.LocationPermissionResult locationResult =
6880 LocationAccessPolicy.checkLocationPermission(mApp,
6881 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6882 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006883 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006884 .setCallingPid(Binder.getCallingPid())
6885 .setCallingUid(Binder.getCallingUid())
6886 .setMethod("getCellNetworkScanResults")
6887 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006888 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6889 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006890 .build());
6891 switch (locationResult) {
6892 case DENIED_HARD:
6893 throw new SecurityException("Not allowed to access scan results -- location");
6894 case DENIED_SOFT:
6895 return null;
6896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897
Pengquan Menga1bb6272018-09-06 09:59:22 -07006898 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006899 try {
6900 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006901 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 } finally {
6904 Binder.restoreCallingIdentity(identity);
6905 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006906 }
6907
6908 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006909 * Get the call forwarding info, given the call forwarding reason.
6910 */
6911 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006912 public void getCallForwarding(int subId, int callForwardingReason,
6913 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006914 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006915
6916 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6917 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6918
Shuo Qian4a594052020-01-23 11:59:30 -08006919 long identity = Binder.clearCallingIdentity();
6920 try {
6921 if (DBG) {
6922 log("getCallForwarding: subId " + subId
6923 + " callForwardingReason" + callForwardingReason);
6924 }
Hall Liu27d24262020-09-18 19:04:59 -07006925
6926 Phone phone = getPhone(subId);
6927 if (phone == null) {
6928 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006929 callback.onError(
6930 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006931 } catch (RemoteException e) {
6932 // ignore
6933 }
6934 return;
6935 }
6936
6937 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6938 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6939 @Override
6940 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6941 try {
6942 callback.onCallForwardingInfoAvailable(info);
6943 } catch (RemoteException e) {
6944 // ignore
6945 }
6946 }
6947
6948 @Override
6949 public void onError(int error) {
6950 try {
6951 callback.onError(error);
6952 } catch (RemoteException e) {
6953 // ignore
6954 }
6955 }
6956 });
6957 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006958 } finally {
6959 Binder.restoreCallingIdentity(identity);
6960 }
6961 }
6962
6963 /**
6964 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6965 * reason, the number to forward, and the timeout before the forwarding is attempted.
6966 */
6967 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006968 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6969 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006970 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006971
6972 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6973 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6974
Shuo Qian4a594052020-01-23 11:59:30 -08006975 long identity = Binder.clearCallingIdentity();
6976 try {
6977 if (DBG) {
6978 log("setCallForwarding: subId " + subId
6979 + " callForwardingInfo" + callForwardingInfo);
6980 }
Hall Liu27d24262020-09-18 19:04:59 -07006981
6982 Phone phone = getPhone(subId);
6983 if (phone == null) {
6984 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006985 callback.accept(
6986 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006987 } catch (RemoteException e) {
6988 // ignore
6989 }
6990 return;
6991 }
6992
6993 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6994 FunctionalUtils.ignoreRemoteException(callback::accept));
6995
6996 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006997 } finally {
6998 Binder.restoreCallingIdentity(identity);
6999 }
7000 }
7001
7002 /**
Hall Liu27d24262020-09-18 19:04:59 -07007003 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007004 */
7005 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007006 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007007 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007008
7009 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7010 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7011
Shuo Qian4a594052020-01-23 11:59:30 -08007012 long identity = Binder.clearCallingIdentity();
7013 try {
Hall Liu27d24262020-09-18 19:04:59 -07007014 Phone phone = getPhone(subId);
7015 if (phone == null) {
7016 try {
7017 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7018 } catch (RemoteException e) {
7019 // ignore
7020 }
7021 return;
7022 }
SongFerngWang0e767992021-03-31 22:08:45 +08007023 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7024 PersistableBundle c = configManager.getConfigForSubId(subId);
7025 boolean requireUssd = c.getBoolean(
7026 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007027
Shuo Qian4a594052020-01-23 11:59:30 -08007028 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007029 if (requireUssd) {
7030 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7031 getSubscriptionCarrierId(subId));
7032 String newUssdCommand = "";
7033 try {
7034 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007035 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007036 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7037 } catch (NullPointerException e) {
7038 loge("Failed to generate USSD number" + e);
7039 }
7040 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7041 mMainThreadHandler, callback, carrierXmlParser,
7042 CarrierXmlParser.SsEntry.SSAction.QUERY);
7043 final String ussdCommand = newUssdCommand;
7044 Executors.newSingleThreadExecutor().execute(() -> {
7045 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7046 });
7047 } else {
7048 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7049 callback::accept);
7050 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7051 }
Shuo Qian4a594052020-01-23 11:59:30 -08007052 } finally {
7053 Binder.restoreCallingIdentity(identity);
7054 }
7055 }
7056
7057 /**
Hall Liu27d24262020-09-18 19:04:59 -07007058 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007059 */
7060 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007061 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007062 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007063
7064 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7065 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7066
Shuo Qian4a594052020-01-23 11:59:30 -08007067 long identity = Binder.clearCallingIdentity();
7068 try {
Hall Liu27d24262020-09-18 19:04:59 -07007069 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7070
7071 Phone phone = getPhone(subId);
7072 if (phone == null) {
7073 try {
7074 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7075 } catch (RemoteException e) {
7076 // ignore
7077 }
7078 return;
7079 }
7080
SongFerngWang0e767992021-03-31 22:08:45 +08007081 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7082 PersistableBundle c = configManager.getConfigForSubId(subId);
7083 boolean requireUssd = c.getBoolean(
7084 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007085
SongFerngWang0e767992021-03-31 22:08:45 +08007086 if (DBG) log("getCallWaitingStatus: subId " + subId);
7087 if (requireUssd) {
7088 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7089 getSubscriptionCarrierId(subId));
7090 CarrierXmlParser.SsEntry.SSAction ssAction =
7091 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7092 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7093 String newUssdCommand = "";
7094 try {
7095 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007096 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007097 .makeCommand(ssAction, null);
7098 } catch (NullPointerException e) {
7099 loge("Failed to generate USSD number" + e);
7100 }
7101 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7102 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7103 final String ussdCommand = newUssdCommand;
7104 Executors.newSingleThreadExecutor().execute(() -> {
7105 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7106 });
7107 } else {
7108 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7109 FunctionalUtils.ignoreRemoteException(callback::accept));
7110
7111 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7112 }
Shuo Qian4a594052020-01-23 11:59:30 -08007113 } finally {
7114 Binder.restoreCallingIdentity(identity);
7115 }
7116 }
7117
7118 /**
yinxub1bed742017-04-17 11:45:04 -07007119 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007120 *
yinxub1bed742017-04-17 11:45:04 -07007121 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007122 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7123 * location related information which will be sent if the caller already possess
7124 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007125 * @param request contains the radio access networks with bands/channels to scan
7126 * @param messenger callback messenger for scan results or errors
7127 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007128 * @return the id of the requested scan which can be used to stop the scan.
7129 */
7130 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007131 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7132 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007133 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7135 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007136 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007137 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7138 if (!renounceFineLocationAccess) {
7139 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007140 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7141 .setCallingPackage(callingPackage)
7142 .setCallingFeatureId(callingFeatureId)
7143 .setCallingPid(Binder.getCallingPid())
7144 .setCallingUid(Binder.getCallingUid())
7145 .setMethod("requestNetworkScan")
7146 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7147 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7148 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7149 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007150 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007151 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007152 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7153 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007154 if (e != null) {
7155 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7156 throw e;
7157 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007158 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007159 return TelephonyScanManager.INVALID_SCAN_ID;
7160 }
7161 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162 }
joonhunshin4ac60942023-11-15 15:23:39 +00007163
7164 enforceTelephonyFeatureWithException(callingPackage,
7165 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7166
Hall Liu912dfd32019-04-25 14:02:26 -07007167 int callingUid = Binder.getCallingUid();
7168 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007169 final long identity = Binder.clearCallingIdentity();
7170 try {
7171 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007172 renounceFineLocationAccess, request, messenger, binder,
7173 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007174 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007175 } finally {
7176 Binder.restoreCallingIdentity(identity);
7177 }
yinxu504e1392017-04-12 16:03:22 -07007178 }
7179
Hall Liub2ac8ef2019-02-28 15:56:23 -08007180 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007181 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007182 boolean hasCarrierPriv;
7183 final long identity = Binder.clearCallingIdentity();
7184 try {
7185 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7186 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7187 } finally {
7188 Binder.restoreCallingIdentity(identity);
7189 }
Hall Liu558027f2019-05-15 19:14:05 -07007190 boolean hasNetworkScanPermission =
7191 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007192 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007193
7194 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7195 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7196 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007197 }
7198
7199 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7200 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007201 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7202 return new SecurityException("Specific channels must not be"
7203 + " scanned without location access.");
7204 }
7205 }
7206 }
7207
Hall Liub2ac8ef2019-02-28 15:56:23 -08007208 return null;
7209 }
7210
yinxu504e1392017-04-12 16:03:22 -07007211 /**
7212 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007213 *
7214 * @param subId id of the subscription
7215 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007216 */
7217 @Override
7218 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7220 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007221
Hall Liu912dfd32019-04-25 14:02:26 -07007222 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007223 final long identity = Binder.clearCallingIdentity();
7224 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007225 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007226 } finally {
7227 Binder.restoreCallingIdentity(identity);
7228 }
yinxu504e1392017-04-12 16:03:22 -07007229 }
7230
7231 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007232 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007233 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007234 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007235 */
7236 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007237 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007238 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007239 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007240 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007241
joonhunshin4ac60942023-11-15 15:23:39 +00007242 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7243 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007245 final long identity = Binder.clearCallingIdentity();
7246 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007247 if (DBG) log("getAllowedNetworkTypesBitmask");
7248 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7249 int networkTypesBitmask = (result != null ? result[0] : -1);
7250 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7251 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007252 } finally {
7253 Binder.restoreCallingIdentity(identity);
7254 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007255 }
7256
7257 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007258 * Get the allowed network types for certain reason.
7259 *
7260 * @param subId the id of the subscription.
7261 * @param reason the reason the allowed network type change is taking place
7262 * @return the allowed network types.
7263 */
7264 @Override
7265 public long getAllowedNetworkTypesForReason(int subId,
7266 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007267 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007268 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007269
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007270 if (!mApp.getResources().getBoolean(
7271 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7272 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7273 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7274 "getAllowedNetworkTypesForReason");
7275 }
joonhunshin4ac60942023-11-15 15:23:39 +00007276
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007277 final long identity = Binder.clearCallingIdentity();
7278 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007279 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
7283 }
7284
7285 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007286 * Enable/Disable E-UTRA-NR Dual Connectivity
7287 * @param subId subscription id of the sim card
7288 * @param nrDualConnectivityState expected NR dual connectivity state
7289 * This can be passed following states
7290 * <ol>
7291 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7292 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7293 * <li>Disable NR dual connectivity and force secondary cell to be released
7294 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7295 * </ol>
7296 * @return operation result.
7297 */
7298 @Override
7299 public int setNrDualConnectivityState(int subId,
7300 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7302 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007303 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007304 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7305 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7306 }
7307
Sooraj Sasindran37444802020-08-11 10:40:43 -07007308 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7309 final long identity = Binder.clearCallingIdentity();
7310 try {
7311 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7312 nrDualConnectivityState, subId,
7313 workSource);
7314 if (DBG) log("enableNRDualConnectivity result: " + result);
7315 return result;
7316 } finally {
7317 Binder.restoreCallingIdentity(identity);
7318 }
7319 }
7320
7321 /**
7322 * Is E-UTRA-NR Dual Connectivity enabled
7323 * @return true if dual connectivity is enabled else false
7324 */
7325 @Override
7326 public boolean isNrDualConnectivityEnabled(int subId) {
7327 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007328 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007329 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007330 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007331 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7332 return false;
7333 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007334 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7335 final long identity = Binder.clearCallingIdentity();
7336 try {
7337 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7338 null, subId, workSource);
7339 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7340 return isEnabled;
7341 } finally {
7342 Binder.restoreCallingIdentity(identity);
7343 }
7344 }
7345
7346 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007347 * Set the allowed network types of the device and
7348 * provide the reason triggering the allowed network change.
7349 *
7350 * @param subId the id of the subscription.
7351 * @param reason the reason the allowed network type change is taking place
7352 * @param allowedNetworkTypes the allowed network types.
7353 * @return true on success; false on any failure.
7354 */
7355 @Override
7356 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007357 @TelephonyManager.AllowedNetworkTypesReason int reason,
7358 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7360 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007361 // If the caller only has carrier privileges, then they should not be able to override
7362 // any network types which were set for security reasons.
7363 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7364 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007365 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007366 throw new SecurityException(
7367 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007368 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007369 }
joonhunshin4ac60942023-11-15 15:23:39 +00007370
7371 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7372 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7373
SongFerngWang3ef3e072020-12-21 16:41:52 +08007374 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007375 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007376 return false;
7377 }
7378 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7379 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007380 return false;
7381 }
7382
Jack Yu5b494332023-01-23 18:18:04 +00007383 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7384 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007385
Jack Yue37dd262022-12-16 11:53:37 -08007386 Phone phone = getPhone(subId);
7387 if (phone == null) {
7388 return false;
7389 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007390
Jack Yue37dd262022-12-16 11:53:37 -08007391 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007392 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007393 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007394 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007395
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007396 final long identity = Binder.clearCallingIdentity();
7397 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007398 Boolean success = (Boolean) sendRequest(
7399 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7400 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7401
7402 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7403 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007404 } finally {
7405 Binder.restoreCallingIdentity(identity);
7406 }
7407 }
7408
7409 /**
Miaoa84611c2019-03-15 09:21:10 +08007410 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007411 *
Miaoa84611c2019-03-15 09:21:10 +08007412 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007413 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007414 * @hide
7415 */
7416 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007417 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007418 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007419
7420 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7421 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007424 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425 try {
Miaoa84611c2019-03-15 09:21:10 +08007426 if (phone != null) {
7427 return phone.hasMatchedTetherApnSetting();
7428 } else {
7429 return false;
7430 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 } finally {
7432 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007433 }
Junda Liu475951f2014-11-07 16:45:03 -08007434 }
7435
7436 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007437 * Get the user enabled state of Mobile Data.
7438 *
7439 * TODO: remove and use isUserDataEnabled.
7440 * This can't be removed now because some vendor codes
7441 * calls through ITelephony directly while they should
7442 * use TelephonyManager.
7443 *
7444 * @return true on enabled
7445 */
7446 @Override
7447 public boolean getDataEnabled(int subId) {
7448 return isUserDataEnabled(subId);
7449 }
7450
7451 /**
7452 * Get whether mobile data is enabled per user setting.
7453 *
7454 * There are other factors deciding whether mobile data is actually enabled, but they are
7455 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007456 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007457 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7458 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007459 *
7460 * @return {@code true} if data is enabled else {@code false}
7461 */
7462 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007463 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007464 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007465 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007466 try {
7467 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7468 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007469 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007470 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7471 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007472 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007474 mApp, subId, functionName);
7475
Robert Greenwalt646120a2014-05-23 11:54:03 -07007476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477
7478 final long identity = Binder.clearCallingIdentity();
7479 try {
Jack Yu285100e2022-12-02 22:48:35 -08007480 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7482 Phone phone = PhoneFactory.getPhone(phoneId);
7483 if (phone != null) {
7484 boolean retVal = phone.isUserDataEnabled();
7485 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7486 return retVal;
7487 } else {
7488 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7489 return false;
7490 }
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007493 }
7494 }
7495
7496 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007497 * Checks if the device is capable of mobile data by considering whether whether the
7498 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7499 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007500 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007501 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007502 */
7503 @Override
7504 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007505 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007506 try {
7507 try {
7508 mApp.enforceCallingOrSelfPermission(
7509 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007510 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007511 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007512 try {
7513 mApp.enforceCallingOrSelfPermission(
7514 android.Manifest.permission.READ_PHONE_STATE,
7515 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007516 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007517 mApp.enforceCallingOrSelfPermission(
7518 permission.READ_BASIC_PHONE_STATE, functionName);
7519 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007520 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007521 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007522 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524
joonhunshin4ac60942023-11-15 15:23:39 +00007525 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7526 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7527
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 final long identity = Binder.clearCallingIdentity();
7529 try {
Jack Yu285100e2022-12-02 22:48:35 -08007530 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007532 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007533 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007534 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 return retVal;
7536 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007537 if (DBG) {
7538 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7539 + subId + " retVal=false");
7540 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 return false;
7542 }
7543 } finally {
7544 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007545 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007546 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007547
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007548 /**
7549 * Check if data is enabled for a specific reason
7550 * @param subId Subscription index
7551 * @param reason the reason the data enable change is taking place
7552 * @return {@code true} if the overall data is enabled; {@code false} if not.
7553 */
7554 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007555 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007556 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007557 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007558 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007559 try {
7560 mApp.enforceCallingOrSelfPermission(
7561 android.Manifest.permission.ACCESS_NETWORK_STATE,
7562 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007563 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007564 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7565 functionName);
7566 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007567 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007568 try {
7569 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007570 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007571 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007573 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007574 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007575 }
7576
joonhunshin4ac60942023-11-15 15:23:39 +00007577 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7578 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007579
7580 final long identity = Binder.clearCallingIdentity();
7581 try {
Jack Yu285100e2022-12-02 22:48:35 -08007582 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007583 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007584 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007585 + " reason=" + reason);
7586 }
7587 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007588 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007589 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007590 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007591 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007592 return retVal;
7593 } else {
7594 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007595 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007596 + subId + " retVal=false");
7597 }
7598 return false;
7599 }
7600 } finally {
7601 Binder.restoreCallingIdentity(identity);
7602 }
7603 }
7604
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007605 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007606 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007607 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7608 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7609
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007610 // No permission needed; this only lets the caller inspect their own status.
7611 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007612 }
Junda Liu29340342014-07-10 15:23:27 -07007613
7614 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007615 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007616 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007617
7618 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7619 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7620
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007621 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7622 }
7623
7624 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7625 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007626 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007627 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007628 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7629 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007630 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7631 if (cpt == null) {
7632 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007633 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7634 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007635 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007636 }
7637
7638 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007639 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007640 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007641
7642 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7643 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7644
chen xuf7e9fe82019-05-09 19:31:02 -07007645 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007646 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007647 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007648 Phone phone = getPhone(subId);
7649 if (phone == null) {
7650 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7651 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7652 }
7653 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7654 if (cpt == null) {
7655 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007656 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7657 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007658 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007659 }
7660
7661 @Override
7662 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007663 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007664
7665 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7666 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7667 "checkCarrierPrivilegesForPackageAnyPhone");
7668
Rambo Wange7209ce2022-02-23 13:41:02 -08007669 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7670 }
7671
7672 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007673 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007674 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007675 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007676 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007677 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7678 Phone phone = PhoneFactory.getPhone(phoneId);
7679 if (phone == null) {
7680 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007681 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007682 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7683 if (cpt == null) {
7684 continue;
7685 }
7686 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007687 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7688 break;
7689 }
7690 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007691 return result;
Junda Liu29340342014-07-10 15:23:27 -07007692 }
Derek Tan89e89d42014-07-08 17:00:10 -07007693
7694 @Override
Junda Liue64de782015-04-16 17:19:16 -07007695 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007696 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007697
7698 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7699 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7700 "getCarrierPackageNamesForIntentAndPhone");
7701
Rambo Wang8a247eb2022-02-08 21:11:18 +00007702 Phone phone = PhoneFactory.getPhone(phoneId);
7703 if (phone == null) {
7704 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007705 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007706 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7707 if (cpt == null) {
7708 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007709 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007710 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007711 }
7712
Amith Yamasani6e118872016-02-19 12:53:51 -08007713 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007714 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007715 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007716 Phone phone = PhoneFactory.getPhone(phoneId);
7717 if (phone == null) {
7718 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007719 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007720 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7721 if (cpt == null) {
7722 return Collections.emptyList();
7723 }
7724 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007725 }
7726
chen xuf7e9fe82019-05-09 19:31:02 -07007727 @Override
7728 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007729 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007730
7731 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7732 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7733 "getPackagesWithCarrierPrivilegesForAllPhones");
7734
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007735 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007736 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007737 try {
7738 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7739 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7740 }
7741 } finally {
7742 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007743 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007744 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007745 }
7746
Rambo Wang6812ffb2022-03-15 16:54:17 -07007747 @Override
7748 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7749 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7750
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007751 if (!mApp.getResources().getBoolean(
7752 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7753 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7754 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7755 "getCarrierServicePackageNameForLogicalSlot");
7756 }
joonhunshin4ac60942023-11-15 15:23:39 +00007757
Rambo Wang6812ffb2022-03-15 16:54:17 -07007758 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7759 if (phone == null) {
7760 return null;
7761 }
7762 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7763 if (cpt == null) {
7764 return null;
7765 }
7766 return cpt.getCarrierServicePackageName();
7767 }
7768
Wink Savilleb564aae2014-10-23 10:18:09 -07007769 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007770 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007771 UiccPort port = phone == null ? null : phone.getUiccPort();
7772 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007773 return null;
7774 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007775 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007776 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007777 return null;
7778 }
7779 return iccId;
7780 }
7781
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007782 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007783 public void setCallComposerStatus(int subId, int status) {
7784 enforceModifyPermission();
7785
joonhunshin4ac60942023-11-15 15:23:39 +00007786 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7787 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7788
Shuo Qiane4e11672020-12-15 22:15:33 -08007789 final long identity = Binder.clearCallingIdentity();
7790 try {
7791 Phone phone = getPhone(subId);
7792 if (phone != null) {
7793 Phone defaultPhone = phone.getImsPhone();
7794 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7795 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7796 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007797 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7798 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007799 }
7800 }
Shuo Qian284ae752020-12-22 19:10:14 -08007801 } catch (ImsException e) {
7802 throw new ServiceSpecificException(e.getCode());
7803 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007804 Binder.restoreCallingIdentity(identity);
7805 }
7806 }
7807
7808 @Override
7809 public int getCallComposerStatus(int subId) {
7810 enforceReadPrivilegedPermission("getCallComposerStatus");
7811
joonhunshin4ac60942023-11-15 15:23:39 +00007812 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7813 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7814
Shuo Qiane4e11672020-12-15 22:15:33 -08007815 final long identity = Binder.clearCallingIdentity();
7816 try {
7817 Phone phone = getPhone(subId);
7818 if (phone != null) {
7819 Phone defaultPhone = phone.getImsPhone();
7820 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7821 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7822 return imsPhone.getCallComposerStatus();
7823 }
7824 }
7825 } finally {
7826 Binder.restoreCallingIdentity(identity);
7827 }
7828 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7829 }
7830
7831 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007832 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7833 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007834 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007835 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007836
joonhunshin4ac60942023-11-15 15:23:39 +00007837 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7838 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7839 "setLine1NumberForDisplayForSubscriber");
7840
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007841 final long identity = Binder.clearCallingIdentity();
7842 try {
7843 final String iccId = getIccId(subId);
7844 final Phone phone = getPhone(subId);
7845 if (phone == null) {
7846 return false;
7847 }
7848 final String subscriberId = phone.getSubscriberId();
7849
7850 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007851 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007852 + subscriberId + " to " + number);
7853 }
7854
7855 if (TextUtils.isEmpty(iccId)) {
7856 return false;
7857 }
7858
7859 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7860
7861 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7862 if (alphaTag == null) {
7863 editor.remove(alphaTagPrefKey);
7864 } else {
7865 editor.putString(alphaTagPrefKey, alphaTag);
7866 }
7867
7868 // Record both the line number and IMSI for this ICCID, since we need to
7869 // track all merged IMSIs based on line number
7870 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7871 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7872 if (number == null) {
7873 editor.remove(numberPrefKey);
7874 editor.remove(subscriberPrefKey);
7875 } else {
7876 editor.putString(numberPrefKey, number);
7877 editor.putString(subscriberPrefKey, subscriberId);
7878 }
7879
7880 editor.commit();
7881 return true;
7882 } finally {
7883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007884 }
Derek Tan7226c842014-07-02 17:42:23 -07007885 }
7886
7887 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007888 public String getLine1NumberForDisplay(int subId, String callingPackage,
7889 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007890 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007892 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007893 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007894 return null;
7895 }
Derek Tan97ebb422014-09-05 16:55:38 -07007896
joonhunshin4ac60942023-11-15 15:23:39 +00007897 enforceTelephonyFeatureWithException(callingPackage,
7898 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 final long identity = Binder.clearCallingIdentity();
7901 try {
7902 String iccId = getIccId(subId);
7903 if (iccId != null) {
7904 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7905 if (DBG_MERGE) {
7906 log("getLine1NumberForDisplay returning "
7907 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7908 }
7909 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7912 return null;
7913 } finally {
7914 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007915 }
Derek Tan7226c842014-07-02 17:42:23 -07007916 }
7917
7918 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007919 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7920 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007922 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007923 return null;
7924 }
Derek Tan97ebb422014-09-05 16:55:38 -07007925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 final long identity = Binder.clearCallingIdentity();
7927 try {
7928 String iccId = getIccId(subId);
7929 if (iccId != null) {
7930 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7931 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7932 }
7933 return null;
7934 } finally {
7935 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007936 }
Derek Tan7226c842014-07-02 17:42:23 -07007937 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007938
7939 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007940 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7941 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007942 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7943 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007945 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007946 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007947 return null;
7948 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007949
Jordan Liub49b04b2019-05-06 14:45:15 -07007950 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7951 // the process, where TelephonyManager was instantiated.
7952 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007953 final long identity = Binder.clearCallingIdentity();
7954 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007955 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007956 final TelephonyManager tele = TelephonyManager.from(context);
7957 final SubscriptionManager sub = SubscriptionManager.from(context);
7958
7959 // Figure out what subscribers are currently active
7960 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961
Jordan Liub49b04b2019-05-06 14:45:15 -07007962 // Only consider subs which match the current subId
7963 // This logic can be simplified. See b/131189269 for progress.
7964 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007965 activeSubscriberIds.add(tele.getSubscriberId(subId));
7966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967
7968 // First pass, find a number override for an active subscriber
7969 String mergeNumber = null;
7970 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7971 for (String key : prefs.keySet()) {
7972 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7973 final String subscriberId = (String) prefs.get(key);
7974 if (activeSubscriberIds.contains(subscriberId)) {
7975 final String iccId = key.substring(
7976 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7977 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7978 mergeNumber = (String) prefs.get(numberKey);
7979 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007980 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981 + " for active subscriber " + subscriberId);
7982 }
7983 if (!TextUtils.isEmpty(mergeNumber)) {
7984 break;
7985 }
7986 }
7987 }
7988 }
7989
7990 // Shortcut when no active merged subscribers
7991 if (TextUtils.isEmpty(mergeNumber)) {
7992 return null;
7993 }
7994
7995 // Second pass, find all subscribers under that line override
7996 final ArraySet<String> result = new ArraySet<>();
7997 for (String key : prefs.keySet()) {
7998 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7999 final String number = (String) prefs.get(key);
8000 if (mergeNumber.equals(number)) {
8001 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8002 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8003 final String subscriberId = (String) prefs.get(subscriberKey);
8004 if (!TextUtils.isEmpty(subscriberId)) {
8005 result.add(subscriberId);
8006 }
8007 }
8008 }
8009 }
8010
8011 final String[] resultArray = result.toArray(new String[result.size()]);
8012 Arrays.sort(resultArray);
8013 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008014 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008015 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8016 }
8017 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008018 } finally {
8019 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008020 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008021 }
8022
8023 @Override
zoey chen38003472019-12-13 17:16:31 +08008024 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8025 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008026
joonhunshin4ac60942023-11-15 15:23:39 +00008027 enforceTelephonyFeatureWithException(callingPackage,
8028 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8029
Malcolm Chen6ca97372019-07-01 16:28:21 -07008030 final long identity = Binder.clearCallingIdentity();
8031 try {
8032 final TelephonyManager telephonyManager = mApp.getSystemService(
8033 TelephonyManager.class);
8034 String subscriberId = telephonyManager.getSubscriberId(subId);
8035 if (subscriberId == null) {
8036 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008037 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008038 + subId);
8039 }
8040 return null;
8041 }
8042
Jack Yu3beaf9d2023-04-14 09:17:27 -07008043 final SubscriptionInfo info = getSubscriptionManagerService()
8044 .getSubscriptionInfo(subId);
8045 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008046 // If it doesn't belong to any group, return just subscriberId of itself.
8047 if (groupUuid == null) {
8048 return new String[]{subscriberId};
8049 }
8050
8051 // Get all subscriberIds from the group.
8052 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008053 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8054 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8055 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008056 for (SubscriptionInfo subInfo : groupInfos) {
8057 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8058 if (subscriberId != null) {
8059 mergedSubscriberIds.add(subscriberId);
8060 }
8061 }
8062
8063 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8064 } finally {
8065 Binder.restoreCallingIdentity(identity);
8066
8067 }
8068 }
8069
8070 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008071 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008072 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008073 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074
joonhunshin4ac60942023-11-15 15:23:39 +00008075 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8076 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078 final long identity = Binder.clearCallingIdentity();
8079 try {
8080 final Phone phone = getPhone(subId);
8081 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8082 } finally {
8083 Binder.restoreCallingIdentity(identity);
8084 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008085 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008086
8087 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008088 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008089 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8090 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008091 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8092 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093
8094 final long identity = Binder.clearCallingIdentity();
8095 try {
8096 final Phone phone = getPhone(subId);
8097 if (phone == null) {
8098 return false;
8099 }
8100 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8101 cdmaNonRoamingList);
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008104 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008105 }
8106
8107 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008108 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008109 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008110 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008111 if (phone == null) {
8112 return raf;
8113 }
8114
Shuo Qiandee53402020-05-29 14:08:15 -07008115 try {
8116 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008117 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008118 mApp, phone.getSubId(), "getRadioAccessFamily");
8119 } catch (SecurityException e) {
8120 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8121 throw e;
8122 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008123
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008124 if (!mApp.getResources().getBoolean(
8125 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8126 enforceTelephonyFeatureWithException(callingPackage,
8127 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8128 }
joonhunshin4ac60942023-11-15 15:23:39 +00008129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008130 final long identity = Binder.clearCallingIdentity();
8131 try {
chen xub97461a2018-10-26 14:17:57 -07008132 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133 } finally {
8134 Binder.restoreCallingIdentity(identity);
8135 }
chen xub97461a2018-10-26 14:17:57 -07008136 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008137 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008138
8139 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008140 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008141 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Rambo Wang7eb26962024-07-11 19:48:30 +00008142 if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) {
8143 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8144 "Invalid package:" + callingPackage);
8145 } else {
8146 try {
8147 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8148 Binder.getCallingUid())) {
8149 throw new SecurityException("Invalid package:" + callingPackage);
8150 }
8151 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008152 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008153 }
Hall Liu82694d52020-12-11 18:22:04 -08008154 }
joonhunshin4ac60942023-11-15 15:23:39 +00008155
8156 enforceTelephonyFeatureWithException(callingPackage,
8157 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8158
Hall Liu82694d52020-12-11 18:22:04 -08008159 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008160 List<String> dialerRoleHolders;
8161 if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) {
8162 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8163 UserHandle.of(ActivityManager.getCurrentUser()));
8164 } else {
8165 dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8166 }
Hall Liu82694d52020-12-11 18:22:04 -08008167 if (!dialerRoleHolders.contains(callingPackage)) {
8168 throw new SecurityException("App must be the dialer role holder to"
8169 + " upload a call composer pic");
8170 }
8171
8172 Executors.newSingleThreadExecutor().execute(() -> {
8173 ByteArrayOutputStream output = new ByteArrayOutputStream(
8174 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8175 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8176 boolean readUntilEnd = false;
8177 int totalBytesRead = 0;
8178 byte[] buffer = new byte[16 * 1024];
8179 while (true) {
8180 int numRead;
8181 try {
8182 numRead = input.read(buffer);
8183 } catch (IOException e) {
8184 try {
8185 fd.checkError();
8186 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8187 null);
8188 } catch (IOException e1) {
8189 // This means that the other side closed explicitly with an error. If this
8190 // happens, log and ignore.
8191 loge("Remote end of call composer picture pipe closed: " + e1);
8192 }
8193 break;
8194 }
8195 if (numRead == -1) {
8196 readUntilEnd = true;
8197 break;
8198 }
8199 totalBytesRead += numRead;
8200 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8201 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8202 try {
8203 input.close();
8204 } catch (IOException e) {
8205 // ignore
8206 }
8207 break;
8208 }
8209 output.write(buffer, 0, numRead);
8210 }
8211 // Generally, the remote end will close the file descriptors. The only case where we
8212 // close is above, where the picture size is too big.
8213
8214 try {
8215 fd.checkError();
8216 } catch (IOException e) {
8217 loge("Remote end for call composer closed with an error: " + e);
8218 return;
8219 }
8220
Hall Liuaa4211e2021-01-20 15:43:39 -08008221 if (!readUntilEnd) {
8222 loge("Did not finish reading entire image; aborting");
8223 return;
8224 }
Hall Liu82694d52020-12-11 18:22:04 -08008225
Hall Liuaa4211e2021-01-20 15:43:39 -08008226 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8227 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8228 new CallComposerPictureTransfer.Factory() {},
8229 imageData,
8230 (result) -> {
8231 if (result.first != null) {
8232 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8233 Bundle outputResult = new Bundle();
8234 outputResult.putParcelable(
8235 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8236 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8237 outputResult);
8238 } else {
8239 callback.send(result.second, null);
8240 }
8241 }
8242 );
Hall Liu82694d52020-12-11 18:22:04 -08008243 });
8244 }
8245
8246 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008247 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008248 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008249 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250
joonhunshin4ac60942023-11-15 15:23:39 +00008251 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8252 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254 final long identity = Binder.clearCallingIdentity();
8255 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008256 ImsManager.getInstance(defaultPhone.getContext(),
8257 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 } finally {
8259 Binder.restoreCallingIdentity(identity);
8260 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008261 }
8262
8263 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008264 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008265 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8267 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008268 return false;
8269 }
Svet Ganovb320e182015-04-16 12:30:10 -07008270
joonhunshin4ac60942023-11-15 15:23:39 +00008271 enforceTelephonyFeatureWithException(callingPackage,
8272 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274 final long identity = Binder.clearCallingIdentity();
8275 try {
8276 // Check the user preference and the system-level IMS setting. Even if the user has
8277 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8278 // In the long run, we may instead need to check if there exists a connection service
8279 // which can support video calling.
8280 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008281 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282 return imsManager.isVtEnabledByPlatform()
8283 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8284 && imsManager.isVtEnabledByUser();
8285 } finally {
8286 Binder.restoreCallingIdentity(identity);
8287 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008288 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008289
Andrew Leea1239f22015-03-02 17:44:07 -08008290 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008291 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8292 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008294 mApp, subId, callingPackage, callingFeatureId,
8295 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296 return false;
8297 }
8298
joonhunshin4ac60942023-11-15 15:23:39 +00008299 enforceTelephonyFeatureWithException(callingPackage,
8300 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 final long identity = Binder.clearCallingIdentity();
8303 try {
8304 CarrierConfigManager configManager =
8305 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008306 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
8310 }
Andrew Leea1239f22015-03-02 17:44:07 -08008311 }
8312
8313 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008314 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008316 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008317 return false;
8318 }
8319
joonhunshin4ac60942023-11-15 15:23:39 +00008320 enforceTelephonyFeatureWithException(callingPackage,
8321 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008323 final long identity = Binder.clearCallingIdentity();
8324 try {
8325 CarrierConfigManager configManager =
8326 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008327 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8329 } finally {
8330 Binder.restoreCallingIdentity(identity);
8331 }
Andrew Leea1239f22015-03-02 17:44:07 -08008332 }
8333
Andrew Lee9431b832015-03-09 18:46:45 -07008334 @Override
8335 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008336 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008337 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008338 }
8339
8340 @Override
8341 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008342 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8343 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008345 final long identity = Binder.clearCallingIdentity();
8346 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008347 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008348 } finally {
8349 Binder.restoreCallingIdentity(identity);
8350 }
Andrew Lee9431b832015-03-09 18:46:45 -07008351 }
8352
Hall Liuf6668912018-10-31 17:05:23 -07008353 /**
8354 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8355 * support for the feature and device firmware support.
8356 *
8357 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8358 */
8359 @Override
8360 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008361 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8362 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008364 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008365 final Phone phone = getPhone(subscriptionId);
8366 if (phone == null) {
8367 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8368 return false;
8369 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008370 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008371 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008373 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8374 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8375 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376 return isCarrierSupported && isDeviceSupported;
8377 } finally {
8378 Binder.restoreCallingIdentity(identity);
8379 }
Hall Liu98187582018-01-22 19:15:32 -08008380 }
8381
Hall Liuf6668912018-10-31 17:05:23 -07008382 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008383 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8384 * RTT setting, will return true if the device and carrier both support RTT.
8385 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008386 */
8387 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008388 final long identity = Binder.clearCallingIdentity();
8389 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008390 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8391 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8392 return false;
8393 }
8394 }
8395
Hall Liu5bab75c2019-12-11 23:58:20 +00008396 boolean isRttSupported = isRttSupported(subscriptionId);
8397 boolean isUserRttSettingOn = Settings.Secure.getInt(
8398 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8399 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8400 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8401 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008402 } finally {
8403 Binder.restoreCallingIdentity(identity);
8404 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008405 }
8406
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008407 @Deprecated
8408 @Override
8409 public String getDeviceId(String callingPackage) {
8410 return getDeviceIdWithFeature(callingPackage, null);
8411 }
8412
Sanket Padawe7310cc72015-01-14 09:53:20 -08008413 /**
8414 * Returns the unique device ID of phone, for example, the IMEI for
8415 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8416 *
8417 * <p>Requires Permission:
8418 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8419 */
8420 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008421 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008422 try {
8423 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8424 } catch (SecurityException se) {
8425 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8426 throw new SecurityException("Package " + callingPackage + " does not belong to "
8427 + Binder.getCallingUid());
8428 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008429 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008430 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008431 return null;
8432 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008433 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008434 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008435 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008436 return null;
8437 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438
8439 final long identity = Binder.clearCallingIdentity();
8440 try {
8441 return phone.getDeviceId();
8442 } finally {
8443 Binder.restoreCallingIdentity(identity);
8444 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008445 }
8446
Ping Sunc67b7c22016-03-02 19:16:45 +08008447 /**
8448 * {@hide}
8449 * Returns the IMS Registration Status on a particular subid
8450 *
8451 * @param subId
8452 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008453 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008454 Phone phone = getPhone(subId);
8455 if (phone != null) {
8456 return phone.isImsRegistered();
8457 } else {
8458 return false;
8459 }
8460 }
8461
Santos Cordon7a1885b2015-02-03 11:15:19 -08008462 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008463 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008464 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008466 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008467 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8468 }
8469 final long identity = Binder.clearCallingIdentity();
8470 try {
8471 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8472 } finally {
8473 Binder.restoreCallingIdentity(identity);
8474 }
8475 }
8476
8477 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008478 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008479 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008480 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008481 mApp,
8482 subscriptionId,
8483 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8484 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008485
8486 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8487 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8488
Tyler Gunnf70ed162019-04-03 15:28:53 -07008489 final long identity = Binder.clearCallingIdentity();
8490 try {
8491 Phone phone = getPhone(subscriptionId);
8492 if (phone == null) {
8493 return null;
8494 }
8495 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8496 } finally {
8497 Binder.restoreCallingIdentity(identity);
8498 }
8499 }
8500
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008501 /**
8502 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008503 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008504 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008505 final long identity = Binder.clearCallingIdentity();
8506 try {
8507 Phone phone = getPhone(subId);
8508 if (phone != null) {
8509 return phone.isWifiCallingEnabled();
8510 } else {
8511 return false;
8512 }
8513 } finally {
8514 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008515 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008516 }
8517
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008518 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008519 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008520 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008521 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008522 final long identity = Binder.clearCallingIdentity();
8523 try {
8524 Phone phone = getPhone(subId);
8525 if (phone != null) {
8526 return phone.isVideoEnabled();
8527 } else {
8528 return false;
8529 }
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008532 }
8533 }
8534
8535 /**
8536 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8537 * defined in {@link ImsRegistrationImplBase}.
8538 */
8539 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008540 final long identity = Binder.clearCallingIdentity();
8541 try {
8542 Phone phone = getPhone(subId);
8543 if (phone != null) {
8544 return phone.getImsRegistrationTech();
8545 } else {
8546 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8547 }
8548 } finally {
8549 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008550 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008551 }
8552
Stuart Scott8eef64f2015-04-08 15:13:54 -07008553 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008554 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008555 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008556
8557 enforceTelephonyFeatureWithException(callingPackage,
8558 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8559
Stuart Scott981d8582015-04-21 14:09:50 -07008560 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8561 return;
8562 }
Kai Shif70f46f2021-03-03 13:59:46 -08008563 Phone defaultPhone = getDefaultPhone();
8564 if (defaultPhone != null) {
8565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8566 mApp, getDefaultPhone().getSubId(), "factoryReset");
8567 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008568 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008569
Svet Ganovcc087f82015-05-12 20:35:54 -07008570 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008571 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8572 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008573 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008574 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008575 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008576 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008577 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008578 setDataRoamingEnabled(subId, phone == null ? false
8579 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008580 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008581 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008582 // There has been issues when Sms raw table somehow stores orphan
8583 // fragments. They lead to garbled message when new fragments come
8584 // in and combined with those stale ones. In case this happens again,
8585 // user can reset all network settings which will clean up this table.
8586 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008587 // Clean up IMS settings as well here.
8588 int slotId = getSlotIndex(subId);
8589 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8590 ImsManager.getInstance(mApp, slotId).factoryReset();
8591 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008592
Kai Shif70f46f2021-03-03 13:59:46 -08008593 if (defaultPhone == null) {
8594 return;
8595 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008596 // Erase modem config if erase modem on network setting is enabled.
8597 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8598 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8599 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008600 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008601 }
Kai Shif70f46f2021-03-03 13:59:46 -08008602
8603 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008604 } finally {
8605 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008606 }
8607 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008608
SongFerngWangfd89b102021-05-27 22:44:54 +08008609 @VisibleForTesting
8610 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8611 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8612 return;
8613 }
8614 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8615 RILConstants.PREFERRED_NETWORK_MODE);
8616 SubscriptionManager.setSubscriptionProperty(subId,
8617 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8618 "user=" + defaultNetworkType);
8619 phone.loadAllowedNetworksFromSubscriptionDatabase();
8620 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8621 defaultNetworkType, null);
8622 }
8623
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008624 private void cleanUpSmsRawTable(Context context) {
8625 ContentResolver resolver = context.getContentResolver();
8626 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8627 resolver.delete(uri, null, null);
8628 }
8629
Narayan Kamath1c496c22015-04-16 14:40:19 +01008630 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008631 public String getSimLocaleForSubscriber(int subId) {
8632 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008633
8634 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8635 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8636
chen xu5d3637b2019-01-21 23:31:38 -08008637 final Phone phone = getPhone(subId);
8638 if (phone == null) {
8639 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008640 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008642 final long identity = Binder.clearCallingIdentity();
8643 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008644 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8645 phone.getContext().getOpPackageName(),
8646 phone.getContext().getAttributionTag());
8647 if (info == null) {
8648 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8649 return null;
chen xu6291c472019-02-04 12:55:53 -08008650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008651 // Try and fetch the locale from the carrier properties or from the SIM language
8652 // preferences (EF-PL and EF-LI)...
8653 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008654 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008655 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8656 if (localeFromDefaultSim != null) {
8657 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8658 if (DBG) log("Using locale from subId: " + subId + " locale: "
8659 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008660 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008661 } else {
8662 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008663 }
8664 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008665
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008666 // The SIM language preferences only store a language (e.g. fr = French), not an
8667 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8668 // the SIM and carrier preferences does not include a country we add the country
8669 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008670 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008671 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008672 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008673 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008674 }
8675
8676 if (DBG) log("No locale found - returning null");
8677 return null;
8678 } finally {
8679 Binder.restoreCallingIdentity(identity);
8680 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008681 }
8682
tom hsu0b59d292022-09-29 23:49:21 +08008683 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008684 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008685 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008686 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008687 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008688 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8689 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008690 Locale.forLanguageTag(localeTag).getCountry())) {
8691 return localeTag;
8692 }
8693 }
8694 return inputLocale.toLanguageTag();
8695 }
8696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008697 /**
8698 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8699 */
8700 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008701 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008702 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008703 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008704
Gary Jian3aa9a762022-01-24 16:41:19 +08008705 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8706 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008707
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008708 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008709 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8710 * representing the state of the modem.
8711 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008712 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8713 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008714 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008715 */
8716 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008717 public void requestModemActivityInfo(ResultReceiver result) {
8718 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008719
8720 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8721 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8722
vagdeviaf9a5b92018-08-15 16:01:53 -07008723 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008724
8725 final long identity = Binder.clearCallingIdentity();
8726 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008727 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008728 } finally {
8729 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008730 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008731 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008732
Gary Jian76280a42022-12-07 16:18:33 +08008733 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008734 // less than total activity duration.
8735 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8736 if (info == null) {
8737 return false;
8738 }
8739 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008740 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008741 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8742
Hall Liu49656c02020-10-09 19:00:11 -07008743 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8744
Siddharth Rayb8114062018-06-17 15:02:38 -07008745 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008746 && (info.getSleepTimeMillis() <= activityDurationMs)
8747 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008748 }
8749
Gary Jian3aa9a762022-01-24 16:41:19 +08008750 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8751 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8752 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8753 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8754
8755 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8756 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8757 }
8758
8759 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8760 mLastModemActivityInfo.setReceiveTimeMillis(
8761 rat,
8762 freq,
8763 info.getReceiveTimeMillis(rat, freq)
8764 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8765 }
8766
8767 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8768 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8769 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8770 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8771
8772 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8773 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8774 }
8775 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8776 mLastModemActivityInfo.setReceiveTimeMillis(
8777 rat,
8778 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8779 }
8780
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008781 /**
8782 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8783 * @param info recent ModemActivityInfo
8784 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008785 private void mergeModemActivityInfo(ModemActivityInfo info) {
8786 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008787 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008788 boolean matched;
8789 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8790 matched = false;
8791 int rat = info.getSpecificInfoRat(i);
8792 int freq = info.getSpecificInfoFrequencyRange(i);
8793 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8794 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8795 //if it already exists
8796 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8797 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8798 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8799 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8800 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8801 updateLastModemActivityInfo(info, rat, freq);
8802 matched = true;
8803 }
8804 } else {
8805 updateLastModemActivityInfo(info, rat);
8806 matched = true;
8807 }
8808 }
8809 }
8810
8811 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008812 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008813 new ActivityStatsTechSpecificInfo(
8814 rat,
8815 freq,
8816 info.getTransmitTimeMillis(rat, freq),
8817 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008818 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008819 }
8820 }
8821 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8822 mLastModemActivitySpecificInfo =
8823 new ActivityStatsTechSpecificInfo[merged.size()];
8824 merged.toArray(mLastModemActivitySpecificInfo);
8825
8826 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8827 mLastModemActivityInfo.setSleepTimeMillis(
8828 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008829 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008830 mLastModemActivityInfo.setIdleTimeMillis(
8831 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008832 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008833
8834 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008835 new ModemActivityInfo(
8836 mLastModemActivityInfo.getTimestampMillis(),
8837 mLastModemActivityInfo.getSleepTimeMillis(),
8838 mLastModemActivityInfo.getIdleTimeMillis(),
8839 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008840 }
8841
8842 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8843 ActivityStatsTechSpecificInfo[] info) {
8844 int infoSize = info.length;
8845 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8846 for (int i = 0; i < infoSize; i++) {
8847 ret[i] = new ActivityStatsTechSpecificInfo(
8848 info[i].getRat(), info[i].getFrequencyRange(),
8849 info[i].getTransmitTimeMillis(),
8850 (int) info[i].getReceiveTimeMillis());
8851 }
8852 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008853 }
8854
Jack Yu85bd38a2015-11-09 11:34:32 -08008855 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008856 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008857 */
8858 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008859 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8860 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8861 Phone phone = PhoneFactory.getPhone(slotIndex);
8862 if (phone == null) {
8863 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8864 return null;
8865 }
8866
8867 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008868 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008869 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008870 return null;
8871 }
8872
joonhunshin4ac60942023-11-15 15:23:39 +00008873 enforceTelephonyFeatureWithException(callingPackage,
8874 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8875
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008876 boolean hasFinePermission = false;
8877 boolean hasCoarsePermission = false;
8878 if (!renounceFineLocationAccess) {
8879 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8880 LocationAccessPolicy.checkLocationPermission(mApp,
8881 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8882 .setCallingPackage(callingPackage)
8883 .setCallingFeatureId(callingFeatureId)
8884 .setCallingPid(Binder.getCallingPid())
8885 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008886 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008887 .setLogAsInfo(true)
8888 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8889 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8890 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8891 .build());
8892 hasFinePermission =
8893 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8894 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008895
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008896 if (!renounceCoarseLocationAccess) {
8897 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8898 LocationAccessPolicy.checkLocationPermission(mApp,
8899 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8900 .setCallingPackage(callingPackage)
8901 .setCallingFeatureId(callingFeatureId)
8902 .setCallingPid(Binder.getCallingPid())
8903 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008904 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008905 .setLogAsInfo(true)
8906 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8907 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8908 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8909 .build());
8910 hasCoarsePermission =
8911 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8912 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008913
Jordan Liu0f2bc442020-11-18 16:47:37 -08008914 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008915 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008916 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8917 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008918 if (subInfo != null && !subInfo.isActive()) {
8919 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008920 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008921 }
8922
Hall Liuf19c44f2018-11-27 14:38:17 -08008923 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008924 boolean isCallingPackageDataService = phone.getDataServicePackages()
8925 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008926
8927 // Scrub out the location info in ServiceState depending on what level of access
8928 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008929 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008930 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8931 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008932 } finally {
8933 Binder.restoreCallingIdentity(identity);
8934 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008935 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008936
8937 /**
8938 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8939 *
8940 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8941 * voicemail ringtone.
8942 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8943 * PhoneAccount.
8944 */
8945 @Override
8946 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008947 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8948 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950 final long identity = Binder.clearCallingIdentity();
8951 try {
8952 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8953 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008954 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008955 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008957 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8958 } finally {
8959 Binder.restoreCallingIdentity(identity);
8960 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008961 }
8962
8963 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008964 * Sets the per-account voicemail ringtone.
8965 *
8966 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8967 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8968 *
8969 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8970 * voicemail ringtone.
8971 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8972 * PhoneAccount.
8973 */
8974 @Override
8975 public void setVoicemailRingtoneUri(String callingPackage,
8976 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008977 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008978 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008979 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8980 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8982 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8983 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008985
joonhunshin4ac60942023-11-15 15:23:39 +00008986 enforceTelephonyFeatureWithException(callingPackage,
8987 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008989 final long identity = Binder.clearCallingIdentity();
8990 try {
8991 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8992 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008993 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008994 }
8995 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008998 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008999 }
9000
9001 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009002 * Returns whether vibration is set for voicemail notification in Phone settings.
9003 *
9004 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9005 * voicemail vibration setting.
9006 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9007 */
9008 @Override
9009 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009010 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9011 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009013 final long identity = Binder.clearCallingIdentity();
9014 try {
9015 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9016 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009017 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009018 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009020 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009024 }
9025
Youhan Wange64578a2016-05-02 15:32:42 -07009026 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009027 * Sets the per-account voicemail vibration.
9028 *
9029 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9030 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9031 *
9032 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9033 * voicemail vibration setting.
9034 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9035 * specific PhoneAccount.
9036 */
9037 @Override
9038 public void setVoicemailVibrationEnabled(String callingPackage,
9039 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009040 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009042 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9043 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9045 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9046 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009047 }
9048
joonhunshin4ac60942023-11-15 15:23:39 +00009049 enforceTelephonyFeatureWithException(callingPackage,
9050 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009052 final long identity = Binder.clearCallingIdentity();
9053 try {
9054 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9055 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009056 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009057 }
9058 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9059 } finally {
9060 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009061 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009062 }
9063
9064 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009065 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9066 *
9067 * @throws SecurityException if the caller does not have the required permission
9068 */
arunvoddud7401012022-12-15 16:08:12 +00009069 @VisibleForTesting
9070 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009071 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009072 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009073 }
9074
9075 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009076 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9077 * permission.
9078 *
9079 * @throws SecurityException if the caller does not have the required permission
9080 */
9081 private void enforceSendSmsPermission() {
9082 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9083 }
9084
9085 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009086 * Make sure either called from same process as self (phone) or IPC caller has interact across
9087 * users permission.
9088 *
9089 * @throws SecurityException if the caller does not have the required permission
9090 */
9091 private void enforceInteractAcrossUsersPermission(String message) {
9092 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9093 }
9094
9095 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009096 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009097 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009098 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009099 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009100 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009101 final long identity = Binder.clearCallingIdentity();
9102 try {
9103 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009104 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009105 if (componentName == null) {
9106 throw new SecurityException(
9107 "Caller not current active visual voicemail package[null]");
9108 }
9109 String vvmPackage = componentName.getPackageName();
9110 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009111 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009112 }
9113 } finally {
9114 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009115 }
9116 }
9117
9118 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009119 * Return the application ID for the app type.
9120 *
9121 * @param subId the subscription ID that this request applies to.
9122 * @param appType the uicc app type.
9123 * @return Application ID for specificied app type, or null if no uicc.
9124 */
9125 @Override
9126 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009127 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009128
9129 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9130 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9131
Youhan Wange64578a2016-05-02 15:32:42 -07009132 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009133
9134 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009135 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009136 if (phone == null) {
9137 return null;
9138 }
9139 String aid = null;
9140 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009141 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009142 .getApplicationByType(appType).getAid();
9143 } catch (Exception e) {
9144 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9145 }
9146 return aid;
9147 } finally {
9148 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009149 }
Youhan Wange64578a2016-05-02 15:32:42 -07009150 }
9151
Youhan Wang4001d252016-05-11 10:29:41 -07009152 /**
9153 * Return the Electronic Serial Number.
9154 *
9155 * @param subId the subscription ID that this request applies to.
9156 * @return ESN or null if error.
9157 */
9158 @Override
9159 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009160 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009161 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009162
9163 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009164 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009165 if (phone == null) {
9166 return null;
9167 }
9168 String esn = null;
9169 try {
9170 esn = phone.getEsn();
9171 } catch (Exception e) {
9172 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9173 }
9174 return esn;
9175 } finally {
9176 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009177 }
Youhan Wang4001d252016-05-11 10:29:41 -07009178 }
9179
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009180 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009181 * Return the Preferred Roaming List Version.
9182 *
9183 * @param subId the subscription ID that this request applies to.
9184 * @return PRLVersion or null if error.
9185 */
9186 @Override
9187 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009188 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009189
9190 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9191 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9192
Youhan Wang66ad5d72016-07-18 17:56:58 -07009193 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009194
9195 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009196 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009197 if (phone == null) {
9198 return null;
9199 }
9200 String cdmaPrlVersion = null;
9201 try {
9202 cdmaPrlVersion = phone.getCdmaPrlVersion();
9203 } catch (Exception e) {
9204 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9205 }
9206 return cdmaPrlVersion;
9207 } finally {
9208 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009209 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009210 }
9211
9212 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009213 * Get snapshot of Telephony histograms
9214 * @return List of Telephony histograms
9215 * @hide
9216 */
9217 @Override
9218 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9220 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009221
9222 final long identity = Binder.clearCallingIdentity();
9223 try {
9224 return RIL.getTelephonyRILTimingHistograms();
9225 } finally {
9226 Binder.restoreCallingIdentity(identity);
9227 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009228 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009229
9230 /**
9231 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009232 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9233 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009234 * Require system privileges. In the future we may add this to carrier APIs.
9235 *
Michele Berionne482f8202018-11-27 18:57:59 -08009236 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009237 */
9238 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009239 @TelephonyManager.SetCarrierRestrictionResult
9240 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009241 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009242
9243 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9244 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9245
vagdeviaf9a5b92018-08-15 16:01:53 -07009246 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009247
Michele Berionne482f8202018-11-27 18:57:59 -08009248 if (carrierRestrictionRules == null) {
9249 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009250 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009252 final long identity = Binder.clearCallingIdentity();
9253 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009254 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009255 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009256 } finally {
9257 Binder.restoreCallingIdentity(identity);
9258 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009259 }
9260
9261 /**
9262 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009263 * Get the allowed carrier list and the excluded carrier list, including the priority between
9264 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009265 * Require system privileges. In the future we may add this to carrier APIs.
9266 *
Michele Berionne482f8202018-11-27 18:57:59 -08009267 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009268 */
9269 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009270 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009271 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009272
9273 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9274 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9275
vagdeviaf9a5b92018-08-15 16:01:53 -07009276 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009277
9278 final long identity = Binder.clearCallingIdentity();
9279 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009280 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9281 if (response instanceof CarrierRestrictionRules) {
9282 return (CarrierRestrictionRules) response;
9283 }
9284 // Response is an Exception of some kind,
9285 // which is signalled to the user as a NULL retval
9286 return null;
9287 } catch (Exception e) {
9288 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9289 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009290 } finally {
9291 Binder.restoreCallingIdentity(identity);
9292 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009293 }
9294
fionaxu59545b42016-05-25 15:53:37 -07009295 /**
arunvoddud7401012022-12-15 16:08:12 +00009296 * Fetches the carrier restriction status of the device and sends the status to the caller
9297 * through the callback.
9298 *
9299 * @param callback The callback that will be used to send the result.
9300 * @throws SecurityException if the caller does not have the required permission/privileges or
9301 * the caller is not allowlisted.
9302 */
9303 @Override
9304 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9305 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009306
9307 enforceTelephonyFeatureWithException(packageName,
9308 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9309
Steve Statia28b7cb32024-03-11 23:58:50 +00009310 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9311 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009312 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9313 throw new SecurityException("Not an authorized caller");
9314 }
9315 final long identity = Binder.clearCallingIdentity();
9316 try {
9317 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009318 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009319 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9320 } finally {
9321 Binder.restoreCallingIdentity(identity);
9322 }
9323 }
9324
arunvoddu567f2b42023-04-25 17:22:00 +00009325 @Override
9326 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9327 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9328 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9329 return allowListInfo.getShaIdList(pkgName, carrierId);
9330 }
9331
arunvoddud7401012022-12-15 16:08:12 +00009332 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009333 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009334 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009335 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009336 }
9337
9338 /**
fionaxu59545b42016-05-25 15:53:37 -07009339 * Action set from carrier signalling broadcast receivers to enable/disable radio
9340 * @param subId the subscription ID that this action applies to.
9341 * @param enabled control enable or disable radio.
9342 * {@hide}
9343 */
9344 @Override
9345 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9346 enforceModifyPermission();
9347 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009348
9349 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009350 if (phone == null) {
9351 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9352 return;
9353 }
9354 try {
9355 phone.carrierActionSetRadioEnabled(enabled);
9356 } catch (Exception e) {
9357 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009358 } finally {
9359 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009360 }
9361 }
9362
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009363 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009364 * Enable or disable Voice over NR (VoNR)
9365 * @param subId the subscription ID that this action applies to.
9366 * @param enabled enable or disable VoNR.
9367 * @return operation result.
9368 */
9369 @Override
9370 public int setVoNrEnabled(int subId, boolean enabled) {
9371 enforceModifyPermission();
9372 final Phone phone = getPhone(subId);
9373
9374 final long identity = Binder.clearCallingIdentity();
9375 if (phone == null) {
9376 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9377 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9378 }
9379
9380 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9381 try {
9382 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9383 workSource);
9384 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009385
9386 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9387 if (DBG) {
9388 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9389 }
9390 SubscriptionManager.setSubscriptionProperty(
9391 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9392 (enabled ? "1" : "0"));
9393 }
9394
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009395 return result;
9396 } finally {
9397 Binder.restoreCallingIdentity(identity);
9398 }
9399 }
9400
9401 /**
9402 * Is voice over NR enabled
9403 * @return true if VoNR is enabled else false
9404 */
9405 @Override
9406 public boolean isVoNrEnabled(int subId) {
9407 enforceReadPrivilegedPermission("isVoNrEnabled");
9408 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9409 final long identity = Binder.clearCallingIdentity();
9410 try {
9411 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9412 null, subId, workSource);
9413 if (DBG) log("isVoNrEnabled: " + isEnabled);
9414 return isEnabled;
9415 } finally {
9416 Binder.restoreCallingIdentity(identity);
9417 }
9418 }
9419
9420 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009421 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9422 * network status based on which carrier apps could apply actions accordingly,
9423 * enable/disable default url handler for example.
9424 *
9425 * @param subId the subscription ID that this action applies to.
9426 * @param report control start/stop reporting the default network status.
9427 * {@hide}
9428 */
9429 @Override
9430 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9431 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009432
9433 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9434 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9435 "carrierActionReportDefaultNetworkStatus");
9436
fionaxu8da9cb12017-05-23 15:02:46 -07009437 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009438
9439 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009440 if (phone == null) {
9441 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9442 return;
9443 }
9444 try {
9445 phone.carrierActionReportDefaultNetworkStatus(report);
9446 } catch (Exception e) {
9447 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009448 } finally {
9449 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009450 }
9451 }
9452
9453 /**
fionaxud9622282017-07-17 17:51:30 -07009454 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9455 * @param subId the subscription ID that this action applies to.
9456 * {@hide}
9457 */
9458 @Override
9459 public void carrierActionResetAll(int subId) {
9460 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009461
9462 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9463 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9464
fionaxud9622282017-07-17 17:51:30 -07009465 final Phone phone = getPhone(subId);
9466 if (phone == null) {
9467 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9468 return;
9469 }
9470 try {
9471 phone.carrierActionResetAll();
9472 } catch (Exception e) {
9473 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9474 }
9475 }
9476
9477 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009478 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9479 * bug report is being generated.
9480 */
9481 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009482 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009483 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9484 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009485 writer.println("Permission Denial: can't dump Phone from pid="
9486 + Binder.getCallingPid()
9487 + ", uid=" + Binder.getCallingUid()
9488 + "without permission "
9489 + android.Manifest.permission.DUMP);
9490 return;
9491 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009492 try {
9493 DumpsysHandler.dump(mApp, fd, writer, args);
9494 } catch (Exception e) {
9495 writer.println("Failed to dump phone information: " + e);
9496 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009497 }
Jack Yueb89b242016-06-22 13:27:47 -07009498
Brad Ebingerdac2f002018-04-03 15:17:52 -07009499 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009500 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9501 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9502 @NonNull String[] args) {
9503 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9504 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009505 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009506 }
9507
Jack Yueb89b242016-06-22 13:27:47 -07009508 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009509 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009510 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009511 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009512 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009513 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009514 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009515 */
9516 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009517 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009518 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009519 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9520 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9521 try {
9522 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009523 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009524 } catch (SecurityException se) {
9525 enforceModifyPermission();
9526 }
9527 } else {
9528 enforceModifyPermission();
9529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009530
joonhunshin4ac60942023-11-15 15:23:39 +00009531 enforceTelephonyFeatureWithException(callingPackage,
9532 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9533
Nate Myren116695d2024-02-09 09:36:01 -08009534 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009535 final long identity = Binder.clearCallingIdentity();
9536 try {
Nate Myren116695d2024-02-09 09:36:01 -08009537 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9538 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009539 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009540 callingUid, callingPackage, null, null);
9541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009542 Phone phone = getPhone(subId);
9543 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009544 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9545 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009546 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009547 phone.getDataSettingsManager().setDataEnabled(
9548 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009549 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009550 }
9551 } finally {
9552 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009553 }
9554 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009555
9556 /**
9557 * Get Client request stats
9558 * @return List of Client Request Stats
9559 * @hide
9560 */
9561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009562 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9563 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009565 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009566 return null;
9567 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009568 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009570 final long identity = Binder.clearCallingIdentity();
9571 try {
9572 if (phone != null) {
9573 return phone.getClientRequestStats();
9574 }
9575
9576 return null;
9577 } finally {
9578 Binder.restoreCallingIdentity(identity);
9579 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009580 }
9581
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009582 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009583 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009584 if (uid == Process.ROOT_UID && packageName == null) {
9585 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9586 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9587 // exception. ROOT_UID seems not to have a valid package name returned by
9588 // PackageManager, so just fake it here to avoid issues when running telephony shell
9589 // commands that plumb through the RIL as root, like so:
9590 // $ adb root
9591 // $ adb shell cmd phone ...
9592 packageName = "root";
9593 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009594 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009595 }
Jack Yueb4124c2017-02-16 15:32:43 -08009596
9597 /**
Grace Chen70990072017-03-24 17:21:30 -07009598 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009599 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009600 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009601 * @param state State of SIM (power down, power up, pass through)
9602 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9603 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9604 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009605 *
9606 **/
9607 @Override
Grace Chen70990072017-03-24 17:21:30 -07009608 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009609 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009610
9611 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9612 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9613
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009614 Phone phone = PhoneFactory.getPhone(slotIndex);
9615
vagdeviaf9a5b92018-08-15 16:01:53 -07009616 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009618 final long identity = Binder.clearCallingIdentity();
9619 try {
9620 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009621 phone.setSimPowerState(state, null, workSource);
9622 }
9623 } finally {
9624 Binder.restoreCallingIdentity(identity);
9625 }
9626 }
9627
9628 /**
9629 * Set SIM card power state.
9630 *
9631 * @param slotIndex SIM slot id.
9632 * @param state State of SIM (power down, power up, pass through)
9633 * @param callback callback to trigger after success or failure
9634 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9635 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9636 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9637 *
9638 **/
9639 @Override
9640 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9641 IIntegerConsumer callback) {
9642 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009643
9644 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9645 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9646 "setSimPowerStateForSlotWithCallback");
9647
Jordan Liu109698e2020-11-24 14:50:34 -08009648 Phone phone = PhoneFactory.getPhone(slotIndex);
9649
9650 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9651
9652 final long identity = Binder.clearCallingIdentity();
9653 try {
9654 if (phone != null) {
9655 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9656 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009657 }
9658 } finally {
9659 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009660 }
9661 }
Shuo Qiandd210312017-04-12 22:11:33 +00009662
Tyler Gunn65d45c22017-06-05 11:22:26 -07009663 private boolean isUssdApiAllowed(int subId) {
9664 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009665 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009666 if (configManager == null) {
9667 return false;
9668 }
9669 PersistableBundle pb = configManager.getConfigForSubId(subId);
9670 if (pb == null) {
9671 return false;
9672 }
9673 return pb.getBoolean(
9674 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9675 }
9676
Shuo Qiandd210312017-04-12 22:11:33 +00009677 /**
Ling Mac28f0212023-03-24 16:07:15 -07009678 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009679 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009680 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009681 */
goneil9c5f4872017-12-05 14:07:56 -08009682 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009683 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009684 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009685
9686 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9687 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009689 final long identity = Binder.clearCallingIdentity();
9690 try {
Ling Mac28f0212023-03-24 16:07:15 -07009691 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009692 } finally {
9693 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009694 }
9695 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009696
9697 /**
9698 * Get the current signal strength information for the given subscription.
9699 * Because this information is not updated when the device is in a low power state
9700 * it should not be relied-upon to be current.
9701 * @param subId Subscription index
9702 * @return the most recent cached signal strength info from the modem
9703 */
9704 @Override
9705 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009706 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9707 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009709 final long identity = Binder.clearCallingIdentity();
9710 try {
9711 Phone p = getPhone(subId);
9712 if (p == null) {
9713 return null;
9714 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009716 return p.getSignalStrength();
9717 } finally {
9718 Binder.restoreCallingIdentity(identity);
9719 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009720 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009721
Pengquan Meng77b7f132018-08-22 14:49:57 -07009722 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009723 * Get the current modem radio state for the given slot.
9724 * @param slotIndex slot index.
9725 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009726 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009727 * @return the current radio power state from the modem
9728 */
9729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009730 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009731 Phone phone = PhoneFactory.getPhone(slotIndex);
9732 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9734 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009735 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9736 }
9737
joonhunshin4ac60942023-11-15 15:23:39 +00009738 enforceTelephonyFeatureWithException(callingPackage,
9739 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9740
Chen Xuf792fd62018-10-17 17:54:36 +00009741 final long identity = Binder.clearCallingIdentity();
9742 try {
9743 return phone.getRadioPowerState();
9744 } finally {
9745 Binder.restoreCallingIdentity(identity);
9746 }
9747 }
9748 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9749 }
9750
9751 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009752 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9753 *
9754 * <p>Requires one of the following permissions:
9755 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009756 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009757 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9758 * privileges.
9759 *
9760 * @param subId subscription id
9761 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9762 * {@code false}.
9763 */
9764 @Override
9765 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009766 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009767 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009768 try {
9769 mApp.enforceCallingOrSelfPermission(
9770 android.Manifest.permission.ACCESS_NETWORK_STATE,
9771 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009772 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009773 mApp.enforceCallingOrSelfPermission(
9774 permission.READ_BASIC_PHONE_STATE, functionName);
9775 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009776 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009777 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009778 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009779 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009780
joonhunshin4ac60942023-11-15 15:23:39 +00009781 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9782 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9783
Pengquan Menga1bb6272018-09-06 09:59:22 -07009784 boolean isEnabled = false;
9785 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009786 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009787 Phone phone = getPhone(subId);
9788 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009789 } finally {
9790 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009791 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009792 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009793 }
9794
9795
9796 /**
9797 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9798 *
9799 * <p> Requires permission:
9800 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9801 * privileges.
9802 *
9803 * @param subId subscription id
9804 * @param isEnabled {@code true} means enable, {@code false} means disable.
9805 */
9806 @Override
9807 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9809 mApp, subId, "setDataRoamingEnabled");
9810
joonhunshin4ac60942023-11-15 15:23:39 +00009811 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9812 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9813
Pengquan Menga1bb6272018-09-06 09:59:22 -07009814 final long identity = Binder.clearCallingIdentity();
9815 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009816 Phone phone = getPhone(subId);
9817 if (phone != null) {
9818 phone.setDataRoamingEnabled(isEnabled);
9819 }
9820 } finally {
9821 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009822 }
9823 }
9824
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009825 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009826 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009827 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009828 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009829 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009830
joonhunshin4ac60942023-11-15 15:23:39 +00009831 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9832 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9833
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009834 boolean isAllowed = true;
9835 final long identity = Binder.clearCallingIdentity();
9836 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009837 Phone phone = getPhone(subId);
9838 if (phone != null) {
9839 isAllowed = phone.isCspPlmnEnabled();
9840 }
9841 } finally {
9842 Binder.restoreCallingIdentity(identity);
9843 }
9844 return isAllowed;
9845 }
9846
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009847 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9848 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009849 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009850 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009851 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009852 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9853 if (phone == null) {
9854 return false;
9855 }
9856 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9857 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9858 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009859 }
9860
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009861 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009862 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009863 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009864 mApp.getSystemService(AppOpsManager.class)
9865 .checkPackage(Binder.getCallingUid(), callingPackage);
9866
Jordan Liu1e142fc2019-04-22 15:10:43 -07009867 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009868 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009869 try {
9870 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009871 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009872 } catch (SecurityException e) {
9873 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9874 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009875 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009876 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009877 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009878 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009879 }
joonhunshin4ac60942023-11-15 15:23:39 +00009880
9881 enforceTelephonyFeatureWithException(callingPackage,
9882 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9883
sandeepjsb6c87872021-09-27 15:34:44 +00009884 // checking compatibility, if calling app's target SDK is T and beyond.
9885 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9886 Binder.getCallingUid())) {
9887 isIccIdAccessRestricted = true;
9888 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009889 final long identity = Binder.clearCallingIdentity();
9890 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009891 UiccController uiccController = UiccController.getInstance();
9892 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009893 if (hasReadPermission) {
9894 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009895 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009896
9897 // Remove private info if the caller doesn't have access
9898 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9899 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009900 //setting the value after compatibility check
9901 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009902 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9903 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009904 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009905 if (card == null) {
9906 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009907 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009908 continue;
9909 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009910 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9911 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009912 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009913 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009914 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009915 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9916 for (UiccPortInfo portInfo : portInfos) {
9917 UiccPort port = uiccController.getUiccPortForSlot(
9918 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9919 if (port == null) {
9920 // assume no access if port is null
9921 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9922 continue;
9923 }
9924 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9925 uiccPortInfos.add(portInfo);
9926 } else {
9927 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9928 }
9929 }
9930 filteredInfos.add(new UiccCardInfo(
9931 cardInfo.isEuicc(),
9932 cardInfo.getCardId(),
9933 null,
9934 cardInfo.getPhysicalSlotIndex(),
9935 cardInfo.isRemovable(),
9936 cardInfo.isMultipleEnabledProfilesSupported(),
9937 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009938 }
9939 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009940 } finally {
9941 Binder.restoreCallingIdentity(identity);
9942 }
9943 }
9944
sandeepjsb6c87872021-09-27 15:34:44 +00009945 /**
9946 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9947 * generally private and require carrier privileges to view.
9948 *
9949 * @hide
9950 */
9951 @NonNull
9952 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9953 List<UiccPortInfo> portinfo = new ArrayList<>();
9954 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9955 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9956 }
9957 return new UiccCardInfo(
9958 cardInfo.isEuicc(),
9959 cardInfo.getCardId(),
9960 null,
9961 cardInfo.getPhysicalSlotIndex(),
9962 cardInfo.isRemovable(),
9963 cardInfo.isMultipleEnabledProfilesSupported(),
9964 portinfo
9965 );
9966 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009967
sandeepjsb6c87872021-09-27 15:34:44 +00009968 /**
9969 * @hide
9970 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9971 * These values are generally private and require carrier privileges to view.
9972 */
9973 @NonNull
9974 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9975 return new UiccPortInfo(
9976 UiccPortInfo.ICCID_REDACTED,
9977 portInfo.getPortIndex(),
9978 portInfo.getLogicalSlotIndex(),
9979 portInfo.isActive()
9980 );
9981 }
9982 @Override
9983 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009984 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009985 mApp.getSystemService(AppOpsManager.class)
9986 .checkPackage(Binder.getCallingUid(), callingPackage);
9987
sandeepjsb6c87872021-09-27 15:34:44 +00009988 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009989
Aman Guptaf3c90b32022-03-17 04:54:16 +00009990 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9991 // we are reading iccId which is PII data.
9992 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009993
joonhunshin4ac60942023-11-15 15:23:39 +00009994 enforceTelephonyFeatureWithException(callingPackage,
9995 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9996
sandeepjsb6c87872021-09-27 15:34:44 +00009997 // checking compatibility, if calling app's target SDK is T and beyond.
9998 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9999 Binder.getCallingUid())) {
10000 isLogicalSlotAccessRestricted = true;
10001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010002 final long identity = Binder.clearCallingIdentity();
10003 try {
10004 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010005 if (slots == null || slots.length == 0) {
10006 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010007 return null;
10008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010009 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10010 for (int i = 0; i < slots.length; i++) {
10011 UiccSlot slot = slots[i];
10012 if (slot == null) {
10013 continue;
10014 }
10015
Jordan Liu7be7e652019-05-06 18:55:02 +000010016 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010017 UiccCard card = slot.getUiccCard();
10018 if (card != null) {
10019 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010020 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010021 cardId = slot.getEid();
10022 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010023 // If cardId is null, use iccId of default port as cardId.
10024 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010025 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010026 }
10027
Jordan Liu857451f2019-05-09 16:35:35 -070010028 if (cardId != null) {
10029 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10030 // if cardId is an EID, it's all digits so this is fine
10031 cardId = IccUtils.stripTrailingFs(cardId);
10032 }
10033
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010034 int cardState = 0;
10035 switch (slot.getCardState()) {
10036 case CARDSTATE_ABSENT:
10037 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10038 break;
10039 case CARDSTATE_PRESENT:
10040 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10041 break;
10042 case CARDSTATE_ERROR:
10043 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10044 break;
10045 case CARDSTATE_RESTRICTED:
10046 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10047 break;
10048 default:
10049 break;
10050
10051 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010052 List<UiccPortInfo> portInfos = new ArrayList<>();
10053 int[] portIndexes = slot.getPortList();
10054 for (int portIdx : portIndexes) {
10055 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010056 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010057 portInfos.add(new UiccPortInfo(iccId, portIdx,
10058 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010060 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010061 slot.isEuicc(),
10062 cardId,
10063 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010064 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010065 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010066 //setting the value after compatibility check
10067 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010068 }
10069 return infos;
10070 } finally {
10071 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010072 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010073 }
10074
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010075 /* Returns null if doesn't have read permission or carrier privilege access. */
10076 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10077 boolean hasReadPermission) {
10078 String iccId = slot.getIccId(portIndex);
10079 if (hasReadPermission) { // if has read permission
10080 return iccId;
10081 } else {
10082 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10083 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10084 // if no read permission, checking carrier privilege access
10085 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10086 return iccId;
10087 }
10088 }
10089 }
10090 // No read permission or carrier privilege access.
10091 return UiccPortInfo.ICCID_REDACTED;
10092 }
10093
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010094 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010095 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010096 public boolean switchSlots(int[] physicalSlots) {
10097 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010098
joonhunshin4ac60942023-11-15 15:23:39 +000010099 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10100 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10101
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010102 final long identity = Binder.clearCallingIdentity();
10103 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010104 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10105 for (int i = 0; i < physicalSlots.length; i++) {
10106 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10107 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10108 physicalSlots[i], i));
10109 }
10110 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010111 } finally {
10112 Binder.restoreCallingIdentity(identity);
10113 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010114 }
Jack Yu4c988042018-02-27 15:30:01 -080010115
10116 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010117 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10118 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10119 enforceModifyPermission();
10120
joonhunshin4ac60942023-11-15 15:23:39 +000010121 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10122 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10123
sandeepjsb6c87872021-09-27 15:34:44 +000010124 final long identity = Binder.clearCallingIdentity();
10125 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010126 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010127 } finally {
10128 Binder.restoreCallingIdentity(identity);
10129 }
10130 }
10131
10132 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010133 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010134 enforceTelephonyFeatureWithException(callingPackage,
10135 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10136
Jordan Liu7de49fa2018-12-06 14:48:49 -080010137 final long identity = Binder.clearCallingIdentity();
10138 try {
10139 return UiccController.getInstance().getCardIdForDefaultEuicc();
10140 } finally {
10141 Binder.restoreCallingIdentity(identity);
10142 }
10143 }
10144
Pengquan Meng85728fb2018-03-12 16:31:21 -070010145 /**
goneil47ffb6e2018-04-06 15:40:58 -070010146 * A test API to reload the UICC profile.
10147 *
10148 * <p>Requires that the calling app has permission
10149 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10150 * @hide
10151 */
10152 @Override
10153 public void refreshUiccProfile(int subId) {
10154 enforceModifyPermission();
10155
10156 final long identity = Binder.clearCallingIdentity();
10157 try {
10158 Phone phone = getPhone(subId);
10159 if (phone == null) {
10160 return;
10161 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010162 UiccPort uiccPort = phone.getUiccPort();
10163 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010164 return;
10165 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010166 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010167 if (uiccProfile == null) {
10168 return;
10169 }
10170 uiccProfile.refresh();
10171 } finally {
10172 Binder.restoreCallingIdentity(identity);
10173 }
10174 }
10175
10176 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010177 * Returns false if the mobile data is disabled by default, otherwise return true.
10178 */
10179 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010180 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010181 }
10182
10183 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010184 * Returns the default network type for the given {@code subId}, if the default network type is
10185 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10186 */
10187 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010188 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010189 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010190 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10191 return list.get(phoneId);
10192 }
10193 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010194 }
fionaxua13278b2018-03-21 00:08:13 -070010195
10196 @Override
10197 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010198 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010199 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010200
10201 final long identity = Binder.clearCallingIdentity();
10202 try {
10203 final Phone phone = getPhone(subId);
10204 if (phone == null) {
10205 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10206 return;
10207 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010208 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10209 if (cpt != null) {
10210 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10211 }
10212 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010213 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10214 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010215 if (carrierPrivilegeRules == null) {
10216 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10217 } else {
10218 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10219 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010220 } finally {
10221 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010222 }
fionaxua13278b2018-03-21 00:08:13 -070010223 }
10224
10225 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010226 public void setCarrierServicePackageOverride(
10227 int subId, String carrierServicePackage, String callingPackage) {
10228 TelephonyPermissions.enforceShellOnly(
10229 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10230
Benedict Wong66477622023-02-03 23:30:57 +000010231 final long identity = Binder.clearCallingIdentity();
10232 try {
10233 final Phone phone = getPhone(subId);
10234 if (phone == null || phone.getSubId() != subId) {
10235 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10236 throw new IllegalArgumentException("No phone for subid");
10237 }
10238 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10239 if (cpt == null) {
10240 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10241 throw new IllegalStateException("No CPT for phone");
10242 }
10243 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10244 } finally {
10245 Binder.restoreCallingIdentity(identity);
10246 }
10247 }
10248
10249 @Override
fionaxua13278b2018-03-21 00:08:13 -070010250 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010251 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010252
10253 final long identity = Binder.clearCallingIdentity();
10254 try {
10255 final Phone phone = getPhone(subId);
10256 if (phone == null) {
10257 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10258 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10259 }
10260 return phone.getCarrierIdListVersion();
10261 } finally {
10262 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010263 }
fionaxua13278b2018-03-21 00:08:13 -070010264 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010265
10266 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010267 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10268 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010270 mApp, subId, callingPackage, callingFeatureId,
10271 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010272 return -1;
10273 }
10274
10275 final long identity = Binder.clearCallingIdentity();
10276 try {
10277 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10278 } finally {
10279 Binder.restoreCallingIdentity(identity);
10280 }
10281 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010282
10283 @Override
10284 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010285 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010286 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010287 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010288
joonhunshin4ac60942023-11-15 15:23:39 +000010289 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10290 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10291
Pengquan Menga1bb6272018-09-06 09:59:22 -070010292 final long identity = Binder.clearCallingIdentity();
10293 try {
10294 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10295 } finally {
10296 Binder.restoreCallingIdentity(identity);
10297 }
10298 }
10299
10300 @Override
10301 public boolean setCdmaRoamingMode(int subId, int mode) {
10302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10303 mApp, subId, "setCdmaRoamingMode");
10304
joonhunshin4ac60942023-11-15 15:23:39 +000010305 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10306 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10307
Pengquan Menga1bb6272018-09-06 09:59:22 -070010308 final long identity = Binder.clearCallingIdentity();
10309 try {
10310 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10311 } finally {
10312 Binder.restoreCallingIdentity(identity);
10313 }
10314 }
10315
10316 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010317 public int getCdmaSubscriptionMode(int subId) {
10318 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010319 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010320 mApp, subId, "getCdmaSubscriptionMode");
10321
joonhunshin4ac60942023-11-15 15:23:39 +000010322 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10323 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10324
Sarah Chinbaab1432020-10-28 13:46:24 -070010325 final long identity = Binder.clearCallingIdentity();
10326 try {
10327 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10328 } finally {
10329 Binder.restoreCallingIdentity(identity);
10330 }
10331 }
10332
10333 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010334 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10336 mApp, subId, "setCdmaSubscriptionMode");
10337
joonhunshin4ac60942023-11-15 15:23:39 +000010338 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10339 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10340
Pengquan Menga1bb6272018-09-06 09:59:22 -070010341 final long identity = Binder.clearCallingIdentity();
10342 try {
10343 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10344 } finally {
10345 Binder.restoreCallingIdentity(identity);
10346 }
10347 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010348
sqianc5eccab2018-10-19 18:46:41 -070010349 @Override
sqian8c685422019-02-22 15:55:18 -080010350 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010351 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010353 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10354 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010355 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10356 }
joonhunshin4ac60942023-11-15 15:23:39 +000010357
10358 enforceTelephonyFeatureWithException(callingPackage,
10359 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10360
sqian11b7a0e2018-12-05 18:48:28 -080010361 final long identity = Binder.clearCallingIdentity();
10362 try {
sqian854d44b2018-12-12 16:48:18 -080010363 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10364 for (Phone phone: PhoneFactory.getPhones()) {
10365 if (phone.getEmergencyNumberTracker() != null
10366 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10367 emergencyNumberListInternal.put(
10368 phone.getSubId(),
10369 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10370 }
sqian11b7a0e2018-12-05 18:48:28 -080010371 }
sqian854d44b2018-12-12 16:48:18 -080010372 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010373 } finally {
10374 Binder.restoreCallingIdentity(identity);
10375 }
sqianc5eccab2018-10-19 18:46:41 -070010376 }
10377
10378 @Override
sqian8c685422019-02-22 15:55:18 -080010379 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010380 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010381 if (!exactMatch) {
10382 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010383 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010384 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010385 }
joonhunshin4ac60942023-11-15 15:23:39 +000010386
10387 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10388 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10389
sqian11b7a0e2018-12-05 18:48:28 -080010390 final long identity = Binder.clearCallingIdentity();
10391 try {
sqian854d44b2018-12-12 16:48:18 -080010392 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010393 //Note: we ignore passed in param exactMatch. We can remove it once
10394 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010395 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010396 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010397 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010398 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010399 }
sqian11b7a0e2018-12-05 18:48:28 -080010400 }
10401 return false;
10402 } finally {
10403 Binder.restoreCallingIdentity(identity);
10404 }
10405 }
10406
sqianf4ca7ed2019-01-15 18:32:07 -080010407 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010408 * Start emergency callback mode for GsmCdmaPhone for testing.
10409 */
10410 @Override
10411 public void startEmergencyCallbackMode() {
10412 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10413 "startEmergencyCallbackMode");
10414 enforceModifyPermission();
10415 final long identity = Binder.clearCallingIdentity();
10416 try {
10417 for (Phone phone : PhoneFactory.getPhones()) {
10418 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10419 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10420 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10421 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10422 gsmCdmaPhone.obtainMessage(
10423 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10424 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10425 }
10426 }
10427 } finally {
10428 Binder.restoreCallingIdentity(identity);
10429 }
10430 }
10431
10432 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010433 * Update emergency number list for test mode.
10434 */
10435 @Override
10436 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10437 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10438 "updateEmergencyNumberListTestMode");
10439
10440 final long identity = Binder.clearCallingIdentity();
10441 try {
10442 for (Phone phone: PhoneFactory.getPhones()) {
10443 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10444 if (tracker != null) {
10445 tracker.executeEmergencyNumberTestModeCommand(action, num);
10446 }
10447 }
10448 } finally {
10449 Binder.restoreCallingIdentity(identity);
10450 }
10451 }
10452
10453 /**
10454 * Get the full emergency number list for test mode.
10455 */
10456 @Override
10457 public List<String> getEmergencyNumberListTestMode() {
10458 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10459 "getEmergencyNumberListTestMode");
10460
10461 final long identity = Binder.clearCallingIdentity();
10462 try {
10463 Set<String> emergencyNumbers = new HashSet<>();
10464 for (Phone phone: PhoneFactory.getPhones()) {
10465 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10466 if (tracker != null) {
10467 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10468 emergencyNumbers.add(num.getNumber());
10469 }
10470 }
10471 }
10472 return new ArrayList<>(emergencyNumbers);
10473 } finally {
10474 Binder.restoreCallingIdentity(identity);
10475 }
10476 }
10477
chen xud6b45bd2018-10-30 22:27:10 -070010478 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010479 public int getEmergencyNumberDbVersion(int subId) {
10480 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10481
joonhunshin4ac60942023-11-15 15:23:39 +000010482 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10483 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10484
Shuo Qian3b6ee772019-11-13 17:43:31 -080010485 final long identity = Binder.clearCallingIdentity();
10486 try {
10487 final Phone phone = getPhone(subId);
10488 if (phone == null) {
10489 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10490 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10491 }
10492 return phone.getEmergencyNumberDbVersion();
10493 } finally {
10494 Binder.restoreCallingIdentity(identity);
10495 }
10496 }
10497
10498 @Override
10499 public void notifyOtaEmergencyNumberDbInstalled() {
10500 enforceModifyPermission();
10501
joonhunshin4ac60942023-11-15 15:23:39 +000010502 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10503 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10504
Shuo Qian3b6ee772019-11-13 17:43:31 -080010505 final long identity = Binder.clearCallingIdentity();
10506 try {
10507 for (Phone phone: PhoneFactory.getPhones()) {
10508 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10509 if (tracker != null) {
10510 tracker.updateOtaEmergencyNumberDatabase();
10511 }
10512 }
10513 } finally {
10514 Binder.restoreCallingIdentity(identity);
10515 }
10516 }
10517
10518 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010519 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010520 enforceActiveEmergencySessionPermission();
10521
joonhunshin4ac60942023-11-15 15:23:39 +000010522 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10523 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10524
Shuo Qian3b6ee772019-11-13 17:43:31 -080010525 final long identity = Binder.clearCallingIdentity();
10526 try {
10527 for (Phone phone: PhoneFactory.getPhones()) {
10528 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10529 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010530 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10531 }
10532 }
10533 } finally {
10534 Binder.restoreCallingIdentity(identity);
10535 }
10536 }
10537
10538 @Override
10539 public void resetOtaEmergencyNumberDbFilePath() {
10540 enforceActiveEmergencySessionPermission();
10541
joonhunshin4ac60942023-11-15 15:23:39 +000010542 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10543 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10544
Shuo Qianc373f112020-03-05 17:55:34 -080010545 final long identity = Binder.clearCallingIdentity();
10546 try {
10547 for (Phone phone: PhoneFactory.getPhones()) {
10548 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10549 if (tracker != null) {
10550 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010551 }
10552 }
10553 } finally {
10554 Binder.restoreCallingIdentity(identity);
10555 }
10556 }
10557
10558 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010559 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10560 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10561 Phone phone = getPhone(subId);
10562 if (phone == null) {
10563 return null;
10564 }
10565 final long identity = Binder.clearCallingIdentity();
10566 try {
10567 UiccProfile profile = UiccController.getInstance()
10568 .getUiccProfileForPhone(phone.getPhoneId());
10569 if (profile != null) {
10570 return profile.getCertsFromCarrierPrivilegeAccessRules();
10571 }
10572 } finally {
10573 Binder.restoreCallingIdentity(identity);
10574 }
10575 return null;
10576 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010577
10578 /**
10579 * Enable or disable a modem stack.
10580 */
10581 @Override
10582 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10583 enforceModifyPermission();
10584
joonhunshin4ac60942023-11-15 15:23:39 +000010585 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10586 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10587
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010588 final long identity = Binder.clearCallingIdentity();
10589 try {
10590 Phone phone = PhoneFactory.getPhone(slotIndex);
10591 if (phone == null) {
10592 return false;
10593 } else {
10594 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10595 }
10596 } finally {
10597 Binder.restoreCallingIdentity(identity);
10598 }
10599 }
Michelecea4cf22018-12-21 15:00:11 -080010600
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010601 /**
10602 * Whether a modem stack is enabled or not.
10603 */
10604 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010605 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10606 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010607 Phone phone = PhoneFactory.getPhone(slotIndex);
10608 if (phone == null) return false;
10609
10610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010611 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10612 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010613 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10614 }
10615
joonhunshin4ac60942023-11-15 15:23:39 +000010616 enforceTelephonyFeatureWithException(callingPackage,
10617 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10618
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010619 final long identity = Binder.clearCallingIdentity();
10620 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010621 try {
10622 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10623 } catch (NoSuchElementException ex) {
10624 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10625 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010626 } finally {
10627 Binder.restoreCallingIdentity(identity);
10628 }
10629 }
10630
Michelecea4cf22018-12-21 15:00:11 -080010631 @Override
Michele0ea7d782019-03-19 14:58:42 -070010632 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010633 enforceModifyPermission();
10634
joonhunshin4ac60942023-11-15 15:23:39 +000010635 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10636 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10637
Michelecea4cf22018-12-21 15:00:11 -080010638 final long identity = Binder.clearCallingIdentity();
10639 try {
10640 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010641 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010642 .commit();
10643 } finally {
10644 Binder.restoreCallingIdentity(identity);
10645 }
10646 }
10647
10648 @Override
Michele0ea7d782019-03-19 14:58:42 -070010649 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010650 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010652 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10653 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010654 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010655 }
Michelecea4cf22018-12-21 15:00:11 -080010656
joonhunshin4ac60942023-11-15 15:23:39 +000010657 enforceTelephonyFeatureWithException(callingPackage,
10658 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10659
Michelecea4cf22018-12-21 15:00:11 -080010660 final long identity = Binder.clearCallingIdentity();
10661 try {
Michele0ea7d782019-03-19 14:58:42 -070010662 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010663 } finally {
10664 Binder.restoreCallingIdentity(identity);
10665 }
10666 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010667
Michele0ea7d782019-03-19 14:58:42 -070010668 @TelephonyManager.IsMultiSimSupportedResult
10669 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010670 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10671 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10672 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010673 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10674 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010675 }
10676 // Check if the hardware supports multisim functionality. If usage of multisim is not
10677 // supported by the modem, indicate that it is restricted.
10678 PhoneCapability staticCapability =
10679 mPhoneConfigurationManager.getStaticPhoneCapability();
10680 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010681 loge("isMultiSimSupportedInternal: no static configuration available");
10682 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010683 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010684 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010685 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10686 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010687 }
10688 // Check if support of multiple SIMs is restricted by carrier
10689 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010690 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010691 }
10692
Michele0ea7d782019-03-19 14:58:42 -070010693 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010694 }
10695
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010696 /**
10697 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010698 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10699 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10700 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010701 * @param numOfSims number of active sims we want to switch to
10702 */
10703 @Override
10704 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010705 if (numOfSims == 1) {
10706 enforceModifyPermission();
10707 } else {
10708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10709 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10710 }
joonhunshin4ac60942023-11-15 15:23:39 +000010711
10712 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10713 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10714
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010715 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010716
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010717 try {
Michele30b57b22019-03-01 12:01:14 -080010718 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010719 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010720 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10721 return;
10722 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010723 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10724 } finally {
10725 Binder.restoreCallingIdentity(identity);
10726 }
10727 }
10728
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010729 @Override
10730 public boolean isApplicationOnUicc(int subId, int appType) {
10731 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010732
10733 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10734 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10735
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010736 Phone phone = getPhone(subId);
10737 if (phone == null) {
10738 return false;
10739 }
10740 final long identity = Binder.clearCallingIdentity();
10741 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010742 UiccPort uiccPort = phone.getUiccPort();
10743 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010744 return false;
10745 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010746 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010747 if (uiccProfile == null) {
10748 return false;
10749 }
10750 if (TelephonyManager.APPTYPE_SIM <= appType
10751 && appType <= TelephonyManager.APPTYPE_ISIM) {
10752 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10753 }
10754 return false;
10755 } finally {
10756 Binder.restoreCallingIdentity(identity);
10757 }
10758 }
10759
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010760 /**
chen xub4baa772019-04-03 10:23:41 -070010761 * Get whether making changes to modem configurations will trigger reboot.
10762 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010763 */
10764 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010765 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10766 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010768 mApp, subId, callingPackage, callingFeatureId,
10769 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010770 return false;
10771 }
joonhunshin4ac60942023-11-15 15:23:39 +000010772
10773 enforceTelephonyFeatureWithException(callingPackage,
10774 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10775 "doesSwitchMultiSimConfigTriggerReboot");
10776
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010777 final long identity = Binder.clearCallingIdentity();
10778 try {
10779 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10780 } finally {
10781 Binder.restoreCallingIdentity(identity);
10782 }
10783 }
10784
Nathan Harold29f5f052019-02-15 13:41:57 -080010785 private void updateModemStateMetrics() {
10786 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10787 // TODO: check the state for each modem if the api is ready.
10788 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10789 }
10790
Pengquan Meng3889a572019-01-23 11:16:29 -080010791 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010792 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010793 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010794 // Verify that the callingPackage belongs to the calling UID
10795 mApp.getSystemService(AppOpsManager.class)
10796 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010797
10798 enforceTelephonyFeatureWithException(callingPackage,
10799 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10800
Pengquan Meng3889a572019-01-23 11:16:29 -080010801 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010802 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010803 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010804 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10805 if (slotInfos != null) {
10806 for (int i = 0; i < slotInfos.length; i++) {
10807 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10808 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10809 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10810 portInfo.getLogicalSlotIndex()));
10811 }
10812 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010813 }
10814 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010815 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010816 } finally {
10817 Binder.restoreCallingIdentity(identity);
10818 }
10819 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010820
10821 /**
10822 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010823 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010824 */
jimsunf9ec1622022-09-13 21:18:43 +080010825 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010826 @Override
10827 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010828 return getHalVersion(HAL_SERVICE_RADIO);
10829 }
10830
10831 /**
10832 * Get the HAL Version of a specific service
10833 */
10834 @Override
10835 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010836 Phone phone = getDefaultPhone();
10837 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010838 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010839 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10840 return hv.major * 100 + hv.minor;
10841 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010842
10843 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010844 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010845 *
10846 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010847 */
10848 @Override
sangyun097dcf72024-01-04 10:35:49 +090010849 public @Nullable String getCurrentPackageName() {
10850 PackageManager pm = mApp.getPackageManager();
10851 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10852 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010853 }
10854
10855 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010856 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10857 * corresponding network requests on a subId.
10858 *
10859 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010860 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010861 * 2) APN is un-metered for this subscription, or
10862 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010863 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010864 *
10865 * @return whether data is allowed for a apn type.
10866 *
10867 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010868 */
10869 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010870 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010871 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10872 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010873
joonhunshin4ac60942023-11-15 15:23:39 +000010874 enforceTelephonyFeatureWithException(callingPackage,
10875 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10876
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010877 // Now that all security checks passes, perform the operation as ourselves.
10878 final long identity = Binder.clearCallingIdentity();
10879 try {
10880 Phone phone = getPhone(subId);
10881 if (phone == null) return false;
10882
Jack Yu27422a52022-03-21 10:38:05 -070010883 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010884 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010885 isMetered = phone.getDataNetworkController().getDataConfigManager()
10886 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10887 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010888 isDataEnabled = (phone.getDataSettingsManager() != null)
10889 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010890 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010891 } finally {
10892 Binder.restoreCallingIdentity(identity);
10893 }
10894 }
10895
10896 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010897 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010898 enforceReadPrivilegedPermission("isApnMetered");
10899
joonhunshin4ac60942023-11-15 15:23:39 +000010900 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10901 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10902
Malcolm Chene5ad5792019-04-18 13:51:02 -070010903 // Now that all security checks passes, perform the operation as ourselves.
10904 final long identity = Binder.clearCallingIdentity();
10905 try {
10906 Phone phone = getPhone(subId);
10907 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010908 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10909 DataUtils.apnTypeToNetworkCapability(apnType),
10910 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010911 } finally {
10912 Binder.restoreCallingIdentity(identity);
10913 }
10914 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010915
10916 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010917 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10918 int subscriptionId, IBooleanConsumer resultCallback) {
10919 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010920
10921 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10922 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10923
Hall Liu73f5d362020-01-20 13:42:00 -080010924 long token = Binder.clearCallingIdentity();
10925 try {
10926 Phone phone = getPhone(subscriptionId);
10927 if (phone == null) {
10928 try {
10929 if (resultCallback != null) {
10930 resultCallback.accept(false);
10931 }
10932 } catch (RemoteException e) {
10933 // ignore
10934 }
10935 return;
10936 }
10937 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10938 Pair.create(specifiers, (x) -> {
10939 try {
10940 if (resultCallback != null) {
10941 resultCallback.accept(x);
10942 }
10943 } catch (RemoteException e) {
10944 // ignore
10945 }
10946 });
10947 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10948 } finally {
10949 Binder.restoreCallingIdentity(token);
10950 }
10951 }
10952
10953 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010954 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10955 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010956 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010957 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010958
10959 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10960 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10961
Sarah Chin679c08a2020-11-18 13:39:35 -080010962 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10963 final long identity = Binder.clearCallingIdentity();
10964 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010965 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10966 if (result instanceof IllegalStateException) {
10967 throw (IllegalStateException) result;
10968 }
10969 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010970 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10971 return specifiers;
10972 } finally {
10973 Binder.restoreCallingIdentity(identity);
10974 }
10975 }
10976
10977 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010978 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010979 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010980
10981 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10982 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10983
Jack Yu8b766fc2022-03-21 09:42:33 -070010984 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010985 }
10986
10987 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010988 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10989 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010990 if (callingPackage == null) {
10991 callingPackage = getCurrentPackageName();
10992 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010993 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10994 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010995 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10996 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010997 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10998 }
10999 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11000 Intent intent = new Intent();
11001 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11002 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11003 // Bring up choose default SMS subscription dialog right now
11004 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11005 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
11006 mApp.startActivity(intent);
11007 }
chen xud5ca2d52019-05-28 15:20:57 -070011008
11009 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011010 public void showSwitchToManagedProfileDialog() {
11011 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011012 try {
11013 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11014 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11015 // for work telephony.
11016 Intent intent = new Intent(Intent.ACTION_SENDTO);
11017 intent.setData(Uri.parse("smsto:"));
11018 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11019 mApp.startActivity(intent);
11020 } catch (ActivityNotFoundException e) {
11021 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11022 Intent intent = new Intent();
11023 intent.setClass(mApp, ErrorDialogActivity.class);
11024 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11025 mApp.startActivity(intent);
11026 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011027 }
11028
11029 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011030 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011031 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11032 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11033
chen xud5ca2d52019-05-28 15:20:57 -070011034 //TODO investigate if this API should require proper permission check in R b/133791609
11035 final long identity = Binder.clearCallingIdentity();
11036 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011037 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11038 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11039 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11040 return carrierUAProfUrl;
11041 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011042 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11043 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011044 } finally {
11045 Binder.restoreCallingIdentity(identity);
11046 }
11047 }
11048
11049 @Override
11050 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011051 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11052 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11053
chen xud5ca2d52019-05-28 15:20:57 -070011054 //TODO investigate if this API should require proper permission check in R b/133791609
11055 final long identity = Binder.clearCallingIdentity();
11056 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011057 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11058 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11059 if (!TextUtils.isEmpty(carrierUserAgent)) {
11060 return carrierUserAgent;
11061 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011062 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11063 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011064 } finally {
11065 Binder.restoreCallingIdentity(identity);
11066 }
11067 }
Jack Yub07d4972019-05-28 16:12:25 -070011068
11069 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011070 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11071 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011072
joonhunshin4ac60942023-11-15 15:23:39 +000011073 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11074 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11075
Jack Yub07d4972019-05-28 16:12:25 -070011076 final long identity = Binder.clearCallingIdentity();
11077 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011078 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011079 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011080
Ling Maf188d502022-09-16 15:22:36 -070011081 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011082 } finally {
11083 Binder.restoreCallingIdentity(identity);
11084 }
11085 }
11086
11087 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011088 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011089 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011090 enforceModifyPermission();
11091
joonhunshin4ac60942023-11-15 15:23:39 +000011092 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11093 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11094
changbettyd5c246e2019-12-24 15:40:37 +080011095 final long identity = Binder.clearCallingIdentity();
11096 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011097 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011098 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011099
Ling Maf188d502022-09-16 15:22:36 -070011100 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011101 } finally {
11102 Binder.restoreCallingIdentity(identity);
11103 }
11104 }
11105
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011106 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011107 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011108 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11109 * otherwise.
11110 */
11111 @Override
11112 public void setCepEnabled(boolean isCepEnabled) {
11113 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11114
11115 final long identity = Binder.clearCallingIdentity();
11116 try {
11117 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11118 for (Phone phone : PhoneFactory.getPhones()) {
11119 Phone defaultPhone = phone.getImsPhone();
11120 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11121 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11122 ImsPhoneCallTracker imsPhoneCallTracker =
11123 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11124 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11125 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11126 + imsPhone.getMsisdn());
11127 }
11128 }
11129 } finally {
11130 Binder.restoreCallingIdentity(identity);
11131 }
11132 }
allenwtsu46dcc572020-01-08 18:24:03 +080011133
11134 /**
11135 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11136 *
11137 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11138 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11139 * before being read.
11140 */
11141 @Override
11142 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11143 isCompressed) {
11144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11145 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011146 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11147 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11148 }
joonhunshin4ac60942023-11-15 15:23:39 +000011149
11150 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11151 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11152 Binder.getCallingUserHandle())) {
11153 if (!isImsAvailableOnDevice()) {
11154 // ProvisioningManager can not handle ServiceSpecificException.
11155 // Throw the IllegalStateException and annotate ProvisioningManager.
11156 throw new IllegalStateException("IMS not available on device.");
11157 }
11158 } else {
11159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11160 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11161 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011162 }
11163
11164 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011165 try {
Hui Wang761a6682020-10-31 05:12:53 +000011166 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11167 } finally {
11168 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011169 }
11170 }
zoey chene02881a2019-12-30 16:11:23 +080011171
11172 @Override
11173 public boolean isIccLockEnabled(int subId) {
11174 enforceReadPrivilegedPermission("isIccLockEnabled");
11175
joonhunshin4ac60942023-11-15 15:23:39 +000011176 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11177 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11178
zoey chene02881a2019-12-30 16:11:23 +080011179 // Now that all security checks passes, perform the operation as ourselves.
11180 final long identity = Binder.clearCallingIdentity();
11181 try {
11182 Phone phone = getPhone(subId);
11183 if (phone != null && phone.getIccCard() != null) {
11184 return phone.getIccCard().getIccLockEnabled();
11185 } else {
11186 return false;
11187 }
11188 } finally {
11189 Binder.restoreCallingIdentity(identity);
11190 }
11191 }
11192
11193 /**
11194 * Set the ICC pin lock enabled or disabled.
11195 *
11196 * @return an integer representing the status of IccLock enabled or disabled in the following
11197 * three cases:
11198 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11199 * successfully.
11200 * - Positive number and zero for remaining password attempts.
11201 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11202 *
11203 */
11204 @Override
11205 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11206 enforceModifyPermission();
11207
joonhunshin4ac60942023-11-15 15:23:39 +000011208 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11209 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11210
zoey chene02881a2019-12-30 16:11:23 +080011211 Phone phone = getPhone(subId);
11212 if (phone == null) {
11213 return 0;
11214 }
11215 // Now that all security checks passes, perform the operation as ourselves.
11216 final long identity = Binder.clearCallingIdentity();
11217 try {
11218 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11219 new Pair<Boolean, String>(enabled, password), phone, null);
11220 return attemptsRemaining;
11221
11222 } catch (Exception e) {
11223 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11224 } finally {
11225 Binder.restoreCallingIdentity(identity);
11226 }
11227 return 0;
11228 }
11229
11230 /**
11231 * Change the ICC password used in ICC pin lock.
11232 *
11233 * @return an integer representing the status of IccLock changed in the following three cases:
11234 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11235 * - Positive number and zero for remaining password attempts.
11236 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11237 *
11238 */
11239 @Override
11240 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11241 enforceModifyPermission();
11242
joonhunshin4ac60942023-11-15 15:23:39 +000011243 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11244 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11245
zoey chene02881a2019-12-30 16:11:23 +080011246 Phone phone = getPhone(subId);
11247 if (phone == null) {
11248 return 0;
11249 }
11250 // Now that all security checks passes, perform the operation as ourselves.
11251 final long identity = Binder.clearCallingIdentity();
11252 try {
11253 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11254 new Pair<String, String>(oldPassword, newPassword), phone, null);
11255 return attemptsRemaining;
11256
11257 } catch (Exception e) {
11258 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11259 } finally {
11260 Binder.restoreCallingIdentity(identity);
11261 }
11262 return 0;
11263 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011264
11265 /**
11266 * Request for receiving user activity notification
11267 */
11268 @Override
11269 public void requestUserActivityNotification() {
11270 if (!mNotifyUserActivity.get()
11271 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11272 mNotifyUserActivity.set(true);
11273 }
11274 }
11275
11276 /**
11277 * Called when userActivity is signalled in the power manager.
11278 * This is safe to call from any thread, with any window manager locks held or not.
11279 */
11280 @Override
11281 public void userActivity() {
11282 // ***************************************
11283 // * Inherited from PhoneWindowManager *
11284 // ***************************************
11285 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11286 // WITH ITS LOCKS HELD.
11287 //
11288 // This code must be VERY careful about the locks
11289 // it acquires.
11290 // In fact, the current code acquires way too many,
11291 // and probably has lurking deadlocks.
11292
11293 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11294 throw new SecurityException("Only the OS may call notifyUserActivity()");
11295 }
11296
11297 if (mNotifyUserActivity.getAndSet(false)) {
11298 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11299 USER_ACTIVITY_NOTIFICATION_DELAY);
11300 }
11301 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011302
11303 @Override
11304 public boolean canConnectTo5GInDsdsMode() {
11305 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11306 }
Jack Yud10cdd42020-09-28 20:28:01 -070011307
11308 @Override
11309 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11310 String callingFeatureId) {
11311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11312 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11313 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11314 }
11315
joonhunshin4ac60942023-11-15 15:23:39 +000011316 enforceTelephonyFeatureWithException(callingPackage,
11317 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11318
Jack Yud10cdd42020-09-28 20:28:01 -070011319 Phone phone = getPhone(subId);
11320 if (phone == null) {
11321 throw new RuntimeException("phone is not available");
11322 }
11323 // Now that all security checks passes, perform the operation as ourselves.
11324 final long identity = Binder.clearCallingIdentity();
11325 try {
11326 return phone.getEquivalentHomePlmns();
11327 } finally {
11328 Binder.restoreCallingIdentity(identity);
11329 }
11330 }
Daniel Bright59e67312020-11-13 11:49:37 -080011331
11332 @Override
11333 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011334 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011335 if (!mApp.getResources().getBoolean(
11336 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11337 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11338 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11339 "isRadioInterfaceCapabilitySupported");
11340 }
joonhunshin4ac60942023-11-15 15:23:39 +000011341
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011342 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011343 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011344 if (radioInterfaceCapabilities == null) {
11345 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011346 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011347 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011348 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011349
Hui Wang641e81c2020-10-12 12:14:23 -070011350 @Override
11351 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11352 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011353 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11354 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11355 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11356 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11357 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011358
11359 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11360 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11361
Hui Wang641e81c2020-10-12 12:14:23 -070011362 if (DBG) {
11363 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11364 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11365 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11366 }
11367
11368 if (!SubscriptionManager.isValidSubscriptionId(subId)
11369 || appType < TelephonyManager.APPTYPE_UNKNOWN
11370 || appType > TelephonyManager.APPTYPE_ISIM
11371 || nafUrl == null || securityProtocol == null || callback == null) {
11372 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11373 if (callback != null) {
11374 try {
11375 callback.onAuthenticationFailure(
11376 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11377 } catch (RemoteException exception) {
11378 log("Fail to notify onAuthenticationFailure due to " + exception);
11379 }
11380 return;
11381 }
11382 }
11383
11384 final long token = Binder.clearCallingIdentity();
11385 try {
11386 getGbaManager(subId).bootstrapAuthenticationRequest(
11387 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011388 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011389 } finally {
11390 Binder.restoreCallingIdentity(token);
11391 }
11392 }
11393
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011394 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011395 * Attempts to set the radio power state for all phones for thermal reason.
11396 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011397 * requested radio power state will actually be set. See {@link
11398 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11399 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011400 * @param enable {@code true} if trying to turn radio on.
11401 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11402 * false}.
11403 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011404 private boolean setRadioPowerForThermal(boolean enable) {
11405 boolean isPhoneAvailable = false;
11406 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11407 Phone phone = PhoneFactory.getPhone(i);
11408 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011409 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011410 isPhoneAvailable = true;
11411 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011412 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011413
11414 // return true if successfully informed the phone object about the thermal radio power
11415 // request.
11416 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011417 }
11418
11419 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011420 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011421 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11422 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11423 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11424 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11425 throw new IllegalArgumentException("modem does not support data throttling");
11426 }
11427
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011428 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11429 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011430 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011431 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11432 }
11433
Sarah Chinecc78c42022-03-31 21:16:48 -070011434 setDataEnabledForReason(
11435 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011436
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011437 if (isDataThrottlingSupported) {
11438 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011439 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011440 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11441 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11442 } else if (thermalMitigationResult
11443 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011444 log("Modem likely does not support data throttling on secondary carrier. Data " +
11445 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11446 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011447 }
11448 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011449 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011450
11451 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011452 }
11453
Jack Nudelman644b91a2021-03-12 14:09:48 -080011454 private static List<String> getThermalMitigationAllowlist(Context context) {
11455 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11456 for (String pckg : context.getResources()
11457 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11458 sThermalMitigationAllowlistedPackages.add(pckg);
11459 }
11460 }
11461
11462 return sThermalMitigationAllowlistedPackages;
11463 }
11464
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011465 private boolean isAnyPhoneInEmergencyState() {
11466 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11467 if (tm.isInEmergencyCall()) {
11468 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11469 return true;
11470 }
11471 for (Phone phone : PhoneFactory.getPhones()) {
11472 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11473 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011474 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11475 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011476 return true;
11477 }
11478 }
11479
11480 return false;
11481 }
11482
Jack Nudelman644b91a2021-03-12 14:09:48 -080011483 /**
11484 * Used by shell commands to add an authorized package name for thermal mitigation.
11485 * @param packageName name of package to be allowlisted
11486 * @param context
11487 */
11488 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11489 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11490 sThermalMitigationAllowlistedPackages.add(packageName);
11491 }
11492
11493 /**
11494 * Used by shell commands to remove an authorized package name for thermal mitigation.
11495 * @param packageName name of package to remove from allowlist
11496 * @param context
11497 */
11498 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11499 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11500 sThermalMitigationAllowlistedPackages.remove(packageName);
11501 }
11502
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011503 /**
11504 * Thermal mitigation request to control functionalities at modem.
11505 *
11506 * @param subId the id of the subscription.
11507 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011508 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011509 *
11510 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11511 */
11512 @Override
11513 @ThermalMitigationResult
11514 public int sendThermalMitigationRequest(
11515 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011516 ThermalMitigationRequest thermalMitigationRequest,
11517 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011518 enforceModifyPermission();
11519
Jack Nudelman644b91a2021-03-12 14:09:48 -080011520 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011521
11522 enforceTelephonyFeatureWithException(callingPackage,
11523 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11524
Jack Nudelman644b91a2021-03-12 14:09:48 -080011525 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11526 .contains(callingPackage)) {
11527 throw new SecurityException("Calling package must be configured in the device config. "
11528 + "calling package: " + callingPackage);
11529 }
11530
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011531 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11532 final long identity = Binder.clearCallingIdentity();
11533
11534 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11535 try {
11536 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11537 switch (thermalMitigationAction) {
11538 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11539 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011540 handleDataThrottlingRequest(subId,
11541 thermalMitigationRequest.getDataThrottlingRequest(),
11542 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011543 break;
11544 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11545 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11546 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11547 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11548 }
11549
11550 // Ensure that radio is on. If not able to power on due to phone being
11551 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011552 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011553 thermalMitigationResult =
11554 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11555 break;
11556 }
11557
11558 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011559 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011560 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11561 break;
11562 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11563 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11564 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11565 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11566 }
11567
11568 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11569 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011570 Phone phone = getPhone(subId);
11571 if (phone == null) {
11572 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011573 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011574 break;
11575 }
11576
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011577 TelephonyConnectionService service =
11578 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011579 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011580 Log.e(LOG_TAG, "An emergency call is pending");
11581 thermalMitigationResult =
11582 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11583 break;
11584 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011585 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011586 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011587 break;
11588 }
11589 } else {
11590 thermalMitigationResult =
11591 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11592 break;
11593 }
11594
11595 // Turn radio off. If not able to power off due to phone being unavailable,
11596 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011597 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011598 thermalMitigationResult =
11599 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11600 break;
11601 }
11602 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011603 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011604 break;
11605 default:
11606 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11607 + "not exist. Requested action: " + thermalMitigationAction);
11608 }
11609 } catch (IllegalArgumentException e) {
11610 throw e;
11611 } catch (Exception e) {
11612 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11613 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11614 } finally {
11615 Binder.restoreCallingIdentity(identity);
11616 }
11617
11618 if (DBG) {
11619 log("thermalMitigationRequest returning with thermalMitigationResult: "
11620 + thermalMitigationResult);
11621 }
11622
11623 return thermalMitigationResult;
11624 }
Hui Wang641e81c2020-10-12 12:14:23 -070011625
11626 /**
11627 * Set the GbaService Package Name that Telephony will bind to.
11628 *
11629 * @param subId The sim that the GbaService is associated with.
11630 * @param packageName The name of the package to be replaced with.
11631 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11632 */
11633 @Override
11634 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11635 enforceModifyPermission();
11636
11637 final long identity = Binder.clearCallingIdentity();
11638 try {
11639 return getGbaManager(subId).overrideServicePackage(packageName);
11640 } finally {
11641 Binder.restoreCallingIdentity(identity);
11642 }
11643 }
11644
11645 /**
11646 * Return the package name of the currently bound GbaService.
11647 *
11648 * @param subId The sim that the GbaService is associated with.
11649 * @return the package name of the GbaService configuration, null if GBA is not supported.
11650 */
11651 @Override
11652 public String getBoundGbaService(int subId) {
11653 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11654
11655 final long identity = Binder.clearCallingIdentity();
11656 try {
11657 return getGbaManager(subId).getServicePackage();
11658 } finally {
11659 Binder.restoreCallingIdentity(identity);
11660 }
11661 }
11662
11663 /**
11664 * Set the release time for telephony to unbind GbaService.
11665 *
11666 * @param subId The sim that the GbaService is associated with.
11667 * @param interval The release time to unbind GbaService by millisecond.
11668 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11669 */
11670 @Override
11671 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11672 enforceModifyPermission();
11673
11674 final long identity = Binder.clearCallingIdentity();
11675 try {
11676 return getGbaManager(subId).overrideReleaseTime(interval);
11677 } finally {
11678 Binder.restoreCallingIdentity(identity);
11679 }
11680 }
11681
11682 /**
11683 * Return the release time for telephony to unbind GbaService.
11684 *
11685 * @param subId The sim that the GbaService is associated with.
11686 * @return The release time to unbind GbaService by millisecond.
11687 */
11688 @Override
11689 public int getGbaReleaseTime(int subId) {
11690 enforceReadPrivilegedPermission("getGbaReleaseTime");
11691
11692 final long identity = Binder.clearCallingIdentity();
11693 try {
11694 return getGbaManager(subId).getReleaseTime();
11695 } finally {
11696 Binder.restoreCallingIdentity(identity);
11697 }
11698 }
11699
11700 private GbaManager getGbaManager(int subId) {
11701 GbaManager instance = GbaManager.getInstance(subId);
11702 if (instance == null) {
11703 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11704 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11705 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11706 }
11707 return instance;
11708 }
Hui Wang761a6682020-10-31 05:12:53 +000011709
11710 /**
11711 * indicate whether the device and the carrier can support
11712 * RCS VoLTE single registration.
11713 */
11714 @Override
11715 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011716 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11717 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11718 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11719 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011720
11721 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11722 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11723 }
11724
11725 final long identity = Binder.clearCallingIdentity();
11726 try {
11727 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11728 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011729 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11730 if (isCapable != null) {
11731 return isCapable;
11732 }
Hui Wang761a6682020-10-31 05:12:53 +000011733 }
Hui Wang67af90e2021-06-04 16:57:15 -070011734 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11735 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011736 } finally {
11737 Binder.restoreCallingIdentity(identity);
11738 }
11739 }
11740
11741 /**
11742 * Register RCS provisioning callback.
11743 */
11744 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011745 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011746 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011747 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011748 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011749 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11750 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011751
11752 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11753 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11754 }
joonhunshin4ac60942023-11-15 15:23:39 +000011755 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11756 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11757 Binder.getCallingUserHandle())) {
11758 if (!isImsAvailableOnDevice()) {
11759 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11760 "IMS not available on device.");
11761 }
11762 } else {
11763 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11764 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011765 }
11766
11767 final long identity = Binder.clearCallingIdentity();
11768 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011769 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011770 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011771 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11772 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011773 }
Hui Wang761a6682020-10-31 05:12:53 +000011774 } finally {
11775 Binder.restoreCallingIdentity(identity);
11776 }
11777 }
11778
11779 /**
11780 * Unregister RCS provisioning callback.
11781 */
11782 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011783 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011784 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011785 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011786 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011787 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11788 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011789
11790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11791 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11792 }
joonhunshin4ac60942023-11-15 15:23:39 +000011793
11794 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11795 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11796 Binder.getCallingUserHandle())) {
11797 if (!isImsAvailableOnDevice()) {
11798 // operation failed silently
11799 Rlog.w(LOG_TAG, "IMS not available on device.");
11800 return;
11801 }
11802 } else {
11803 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11804 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11805 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011806 }
11807
11808 final long identity = Binder.clearCallingIdentity();
11809 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011810 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011811 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011812 } finally {
11813 Binder.restoreCallingIdentity(identity);
11814 }
11815 }
11816
11817 /**
11818 * trigger RCS reconfiguration.
11819 */
11820 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011821 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11822 "triggerRcsReconfiguration",
11823 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011824
11825 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11826 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11827 }
joonhunshin4ac60942023-11-15 15:23:39 +000011828 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11829 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11830 Binder.getCallingUserHandle())) {
11831 if (!isImsAvailableOnDevice()) {
11832 // ProvisioningManager can not handle ServiceSpecificException.
11833 // Throw the IllegalStateException and annotate ProvisioningManager.
11834 throw new IllegalStateException("IMS not available on device.");
11835 }
11836 } else {
11837 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11838 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011839 }
11840
11841 final long identity = Binder.clearCallingIdentity();
11842 try {
11843 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11844 } finally {
11845 Binder.restoreCallingIdentity(identity);
11846 }
11847 }
11848
11849 /**
11850 * Provide the client configuration parameters of the RCS application.
11851 */
11852 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011853 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11854 "setRcsClientConfiguration",
11855 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011856
11857 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11858 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11859 }
joonhunshin4ac60942023-11-15 15:23:39 +000011860 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11861 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11862 Binder.getCallingUserHandle())) {
11863 if (!isImsAvailableOnDevice()) {
11864 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11865 "IMS not available on device.");
11866 }
11867 } else {
11868 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11869 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011870 }
11871
11872 final long identity = Binder.clearCallingIdentity();
11873
11874 try {
11875 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11876 if (configBinder == null) {
11877 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011878 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11879 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011880 } else {
11881 configBinder.setRcsClientConfiguration(rcc);
11882 }
joonhunshin3e154242021-09-17 06:33:39 +000011883
11884 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11885 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011886 } catch (RemoteException e) {
11887 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011888 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11889 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011890 } finally {
11891 Binder.restoreCallingIdentity(identity);
11892 }
11893 }
11894
11895 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011896 * Enables or disables the test mode for RCS VoLTE single registration.
11897 */
11898 @Override
11899 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11900 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11901 "setRcsSingleRegistrationTestModeEnabled");
11902
11903 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11904 }
11905
11906 /**
11907 * Gets the test mode for RCS VoLTE single registration.
11908 */
11909 @Override
11910 public boolean getRcsSingleRegistrationTestModeEnabled() {
11911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11912 "getRcsSingleRegistrationTestModeEnabled");
11913
11914 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11915 }
11916
11917 /**
Hui Wang761a6682020-10-31 05:12:53 +000011918 * Overrides the config of RCS VoLTE single registration enabled for the device.
11919 */
11920 @Override
11921 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11922 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11923 "setDeviceSingleRegistrationEnabledOverride");
11924 enforceModifyPermission();
11925
11926 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11927 : Boolean.parseBoolean(enabledStr);
11928 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011929 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011930 }
11931
11932 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011933 * Sends a device to device communication message. Only usable via shell.
11934 * @param message message to send.
11935 * @param value message value.
11936 */
11937 @Override
11938 public void sendDeviceToDeviceMessage(int message, int value) {
11939 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011940 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011941 enforceModifyPermission();
11942
11943 final long identity = Binder.clearCallingIdentity();
11944 try {
11945 TelephonyConnectionService service =
11946 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11947 if (service == null) {
11948 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11949 return;
11950 }
11951 service.sendTestDeviceToDeviceMessage(message, value);
11952 } finally {
11953 Binder.restoreCallingIdentity(identity);
11954 }
11955 }
11956
Tyler Gunnbabbda02021-02-10 11:05:02 -080011957 /**
11958 * Sets the specified device to device transport active.
11959 * @param transport The transport to set active.
11960 */
11961 @Override
11962 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11963 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11964 "setActiveDeviceToDeviceTransport");
11965 enforceModifyPermission();
11966
11967 final long identity = Binder.clearCallingIdentity();
11968 try {
11969 TelephonyConnectionService service =
11970 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11971 if (service == null) {
11972 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11973 return;
11974 }
11975 service.setActiveDeviceToDeviceTransport(transport);
11976 } finally {
11977 Binder.restoreCallingIdentity(identity);
11978 }
11979 }
Tyler Gunn92479152021-01-20 16:30:10 -080011980
Tyler Gunnd4339262021-05-03 14:46:49 -070011981 @Override
11982 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11983 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11984 "setDeviceToDeviceForceEnabled");
11985
11986 final long identity = Binder.clearCallingIdentity();
11987 try {
11988 Arrays.stream(PhoneFactory.getPhones()).forEach(
11989 p -> {
11990 Phone thePhone = p.getImsPhone();
11991 if (thePhone != null && thePhone instanceof ImsPhone) {
11992 ImsPhone imsPhone = (ImsPhone) thePhone;
11993 CallTracker tracker = imsPhone.getCallTracker();
11994 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11995 ImsPhoneCallTracker imsPhoneCallTracker =
11996 (ImsPhoneCallTracker) tracker;
11997 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11998 }
11999 }
12000 }
12001 );
12002 } finally {
12003 Binder.restoreCallingIdentity(identity);
12004 }
12005 }
12006
Tyler Gunn92479152021-01-20 16:30:10 -080012007 /**
Hui Wang761a6682020-10-31 05:12:53 +000012008 * Gets the config of RCS VoLTE single registration enabled for the device.
12009 */
12010 @Override
12011 public boolean getDeviceSingleRegistrationEnabled() {
12012 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12013 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12014 }
12015
12016 /**
12017 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12018 */
12019 @Override
12020 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12021 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12022 "setCarrierSingleRegistrationEnabledOverride");
12023 enforceModifyPermission();
12024
12025 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12026 : Boolean.parseBoolean(enabledStr);
12027 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12028 subId, enabled);
12029 }
12030
12031 /**
12032 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12033 */
12034 @Override
12035 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12036 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12037 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12038 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012039
12040 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012041 * Overrides the ims feature validation result
12042 */
12043 @Override
12044 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12045 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12046 "setImsFeatureValidationOverride");
12047
12048 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12049 : Boolean.parseBoolean(enabledStr);
12050 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12051 subId, enabled);
12052 }
12053
12054 /**
12055 * Gets the ims feature validation override value
12056 */
12057 @Override
12058 public boolean getImsFeatureValidationOverride(int subId) {
12059 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12060 "getImsFeatureValidationOverride");
12061 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12062 }
12063
12064 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012065 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12066 * their mobile plan.
12067 */
12068 @Override
12069 public String getMobileProvisioningUrl() {
12070 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12071 final long identity = Binder.clearCallingIdentity();
12072 try {
12073 return getDefaultPhone().getMobileProvisioningUrl();
12074 } finally {
12075 Binder.restoreCallingIdentity(identity);
12076 }
12077 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012078
James.cf Linbcdf8b32021-01-14 16:44:13 +080012079 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012080 * Get the EAB contact from the EAB database.
12081 */
12082 @Override
12083 public String getContactFromEab(String contact) {
12084 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12085 enforceModifyPermission();
12086 final long identity = Binder.clearCallingIdentity();
12087 try {
12088 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12089 } finally {
12090 Binder.restoreCallingIdentity(identity);
12091 }
12092 }
12093
12094 /**
Calvin Pana1434322021-07-01 19:27:01 +080012095 * Get the EAB capability from the EAB database.
12096 */
12097 @Override
12098 public String getCapabilityFromEab(String contact) {
12099 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12100 enforceModifyPermission();
12101 final long identity = Binder.clearCallingIdentity();
12102 try {
12103 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12104 } finally {
12105 Binder.restoreCallingIdentity(identity);
12106 }
12107 }
12108
12109 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012110 * Remove the EAB contacts from the EAB database.
12111 */
12112 @Override
12113 public int removeContactFromEab(int subId, String contacts) {
12114 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12115 enforceModifyPermission();
12116 final long identity = Binder.clearCallingIdentity();
12117 try {
12118 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12119 } finally {
12120 Binder.restoreCallingIdentity(identity);
12121 }
12122 }
12123
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012124 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012125 public boolean getDeviceUceEnabled() {
12126 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12127 final long identity = Binder.clearCallingIdentity();
12128 try {
12129 return mApp.getDeviceUceEnabled();
12130 } finally {
12131 Binder.restoreCallingIdentity(identity);
12132 }
12133 }
12134
12135 @Override
12136 public void setDeviceUceEnabled(boolean isEnabled) {
12137 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12138 final long identity = Binder.clearCallingIdentity();
12139 try {
12140 mApp.setDeviceUceEnabled(isEnabled);
12141 } finally {
12142 Binder.restoreCallingIdentity(identity);
12143 }
12144 }
12145
Brad Ebinger14d467f2021-02-12 06:18:28 +000012146 /**
12147 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12148 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12149 */
12150 // Used for SHELL command only right now.
12151 @Override
12152 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12153 List<String> featureTags) {
12154 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12155 "addUceRegistrationOverrideShell");
12156 final long identity = Binder.clearCallingIdentity();
12157 try {
12158 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12159 new ArraySet<>(featureTags));
12160 } catch (ImsException e) {
12161 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12162 } finally {
12163 Binder.restoreCallingIdentity(identity);
12164 }
12165 }
12166
12167 /**
12168 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12169 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12170 */
12171 // Used for SHELL command only right now.
12172 @Override
12173 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12174 List<String> featureTags) {
12175 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12176 "removeUceRegistrationOverrideShell");
12177 final long identity = Binder.clearCallingIdentity();
12178 try {
12179 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12180 new ArraySet<>(featureTags));
12181 } catch (ImsException e) {
12182 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12183 } finally {
12184 Binder.restoreCallingIdentity(identity);
12185 }
12186 }
12187
12188 /**
12189 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12190 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12191 */
12192 // Used for SHELL command only right now.
12193 @Override
12194 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12195 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12196 "clearUceRegistrationOverrideShell");
12197 final long identity = Binder.clearCallingIdentity();
12198 try {
12199 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12200 } catch (ImsException e) {
12201 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12202 } finally {
12203 Binder.restoreCallingIdentity(identity);
12204 }
12205 }
12206
12207 /**
12208 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12209 */
12210 // Used for SHELL command only right now.
12211 @Override
12212 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12213 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12214 "getLatestRcsContactUceCapabilityShell");
12215 final long identity = Binder.clearCallingIdentity();
12216 try {
12217 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12218 } catch (ImsException e) {
12219 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12220 } finally {
12221 Binder.restoreCallingIdentity(identity);
12222 }
12223 }
12224
12225 /**
12226 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12227 * device does not have an active PUBLISH.
12228 */
12229 // Used for SHELL command only right now.
12230 @Override
12231 public String getLastUcePidfXmlShell(int subId) {
12232 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12233 final long identity = Binder.clearCallingIdentity();
12234 try {
12235 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12236 } catch (ImsException e) {
12237 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12238 } finally {
12239 Binder.restoreCallingIdentity(identity);
12240 }
12241 }
12242
James.cf Line8713a42021-04-29 16:04:26 +080012243 /**
12244 * Remove UCE requests cannot be sent to the network status.
12245 */
12246 // Used for SHELL command only right now.
12247 @Override
12248 public boolean removeUceRequestDisallowedStatus(int subId) {
12249 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12250 final long identity = Binder.clearCallingIdentity();
12251 try {
12252 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12253 } catch (ImsException e) {
12254 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12255 } finally {
12256 Binder.restoreCallingIdentity(identity);
12257 }
12258 }
12259
James.cf Lin18bb9002021-05-25 01:37:38 +080012260 /**
12261 * Remove UCE requests cannot be sent to the network status.
12262 */
12263 // Used for SHELL command only.
12264 @Override
12265 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12266 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12267 final long identity = Binder.clearCallingIdentity();
12268 try {
12269 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12270 } catch (ImsException e) {
12271 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12272 } finally {
12273 Binder.restoreCallingIdentity(identity);
12274 }
12275 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012276
James.cf Lin4b784aa2021-01-31 03:25:15 +080012277 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012278 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12279 String callingPackage) {
12280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12281 mApp, subId, "setSignalStrengthUpdateRequest");
12282
joonhunshin4ac60942023-11-15 15:23:39 +000012283 enforceTelephonyFeatureWithException(callingPackage,
12284 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12285
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012286 final int callingUid = Binder.getCallingUid();
12287 // Verify that tha callingPackage belongs to the calling UID
12288 mApp.getSystemService(AppOpsManager.class)
12289 .checkPackage(callingUid, callingPackage);
12290
Rambo Wang3607f502021-02-01 21:51:40 -080012291 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012292
12293 final long identity = Binder.clearCallingIdentity();
12294 try {
12295 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12296 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12297
12298 if (result instanceof IllegalStateException) {
12299 throw (IllegalStateException) result;
12300 }
12301 } finally {
12302 Binder.restoreCallingIdentity(identity);
12303 }
12304 }
12305
12306 @Override
12307 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12308 String callingPackage) {
12309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12310 mApp, subId, "clearSignalStrengthUpdateRequest");
12311
joonhunshin4ac60942023-11-15 15:23:39 +000012312 enforceTelephonyFeatureWithException(callingPackage,
12313 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12314
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012315 final int callingUid = Binder.getCallingUid();
12316 // Verify that tha callingPackage belongs to the calling UID
12317 mApp.getSystemService(AppOpsManager.class)
12318 .checkPackage(callingUid, callingPackage);
12319
12320 final long identity = Binder.clearCallingIdentity();
12321 try {
12322 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12323 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12324
12325 if (result instanceof IllegalStateException) {
12326 throw (IllegalStateException) result;
12327 }
12328 } finally {
12329 Binder.restoreCallingIdentity(identity);
12330 }
12331 }
12332
Rambo Wang3607f502021-02-01 21:51:40 -080012333 private static void validateSignalStrengthUpdateRequest(Context context,
12334 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012335 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012336 // phone/system process do not have further restriction on request
12337 return;
12338 }
12339
12340 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012341 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012342 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012343 context.enforceCallingOrSelfPermission(
12344 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12345 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012346 }
12347
12348 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012349 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012350 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012351 || info.isEnabled()) {
12352 throw new IllegalArgumentException(
12353 "Only system can set hide fields in SignalThresholdInfo");
12354 }
12355
12356 // Thresholds length for each RAN need in range. This has been validated in
12357 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12358 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12359 final int[] thresholds = info.getThresholds();
12360 Objects.requireNonNull(thresholds);
12361 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12362 || thresholds.length
12363 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12364 throw new IllegalArgumentException(
12365 "thresholds length is out of range: " + thresholds.length);
12366 }
12367 }
12368 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012369
12370 /**
12371 * Gets the current phone capability.
12372 *
12373 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12374 * @return the PhoneCapability which describes the data connection capability of modem.
12375 * It's used to evaluate possible phone config change, for example from single
12376 * SIM device to multi-SIM device.
12377 */
12378 @Override
12379 public PhoneCapability getPhoneCapability() {
12380 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012381
12382 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12383 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12384
SongFerngWang8236caa2021-01-17 21:51:44 +080012385 final long identity = Binder.clearCallingIdentity();
12386 try {
12387 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12388 } finally {
12389 Binder.restoreCallingIdentity(identity);
12390 }
12391 }
Michele Berionne5e411512020-11-13 02:36:59 +000012392
12393 /**
12394 * Prepare TelephonyManager for an unattended reboot. The reboot is
12395 * required to be done shortly after the API is invoked.
12396 */
12397 @Override
12398 @TelephonyManager.PrepareUnattendedRebootResult
12399 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012400 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012401 enforceRebootPermission();
12402
joonhunshin4ac60942023-11-15 15:23:39 +000012403 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12404 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12405
Michele Berionne5e411512020-11-13 02:36:59 +000012406 final long identity = Binder.clearCallingIdentity();
12407 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012408 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012409 } finally {
12410 Binder.restoreCallingIdentity(identity);
12411 }
12412 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012413
12414 /**
12415 * Request to get the current slicing configuration including URSP rules and
12416 * NSSAIs (configured, allowed and rejected).
12417 *
12418 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12419 */
12420 @Override
12421 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012422 TelephonyPermissions
12423 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12424 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012425
joonhunshin4ac60942023-11-15 15:23:39 +000012426 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12427 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12428 "getSlicingConfig");
12429
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012430 final long identity = Binder.clearCallingIdentity();
12431 try {
12432 Phone phone = getDefaultPhone();
12433 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12434 } finally {
12435 Binder.restoreCallingIdentity(identity);
12436 }
12437 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012438
12439 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012440 * Check whether the given premium capability is available for purchase from the carrier.
12441 *
12442 * @param capability The premium capability to check.
12443 * @param subId The subId to check the premium capability for.
12444 *
12445 * @return Whether the given premium capability is available to purchase.
12446 */
12447 @Override
12448 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12449 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12450 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12451 log("Premium capability "
12452 + TelephonyManager.convertPremiumCapabilityToString(capability)
12453 + " is not available for purchase due to missing permissions.");
12454 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12455 + "permission READ_BASIC_PHONE_STATE.");
12456 }
12457
joonhunshin4ac60942023-11-15 15:23:39 +000012458 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12459 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12460
Sarah Chin2ec39f62022-08-31 17:03:26 -070012461 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012462 if (phone == null) {
12463 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12464 return false;
12465 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012466 final long identity = Binder.clearCallingIdentity();
12467 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012468 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012469 .isPremiumCapabilityAvailableForPurchase(capability);
12470 } finally {
12471 Binder.restoreCallingIdentity(identity);
12472 }
12473 }
12474
12475 /**
12476 * Purchase the given premium capability from the carrier.
12477 *
12478 * @param capability The premium capability to purchase.
12479 * @param callback The result of the purchase request.
12480 * @param subId The subId to purchase the premium capability for.
12481 */
12482 @Override
12483 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12484 log("purchasePremiumCapability: capability="
12485 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12486 + getCurrentPackageName());
12487
12488 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12489 mApp, "purchasePremiumCapability")) {
12490 log("purchasePremiumCapability "
12491 + TelephonyManager.convertPremiumCapabilityToString(capability)
12492 + " failed due to missing permissions.");
12493 throw new SecurityException("purchasePremiumCapability requires permission "
12494 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012495 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12496 mApp, "purchasePremiumCapability")) {
12497 log("purchasePremiumCapability "
12498 + TelephonyManager.convertPremiumCapabilityToString(capability)
12499 + " failed due to missing permissions.");
12500 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012501 }
12502
joonhunshin4ac60942023-11-15 15:23:39 +000012503 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12504 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12505
Sarah Chin2ec39f62022-08-31 17:03:26 -070012506 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012507 if (phone == null) {
12508 try {
12509 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12510 callback.accept(result);
12511 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12512 } catch (RemoteException e) {
12513 String logStr = "Purchase premium capability "
12514 + TelephonyManager.convertPremiumCapabilityToString(capability)
12515 + " failed due to RemoteException handling null phone: " + e;
12516 if (DBG) log(logStr);
12517 AnomalyReporter.reportAnomaly(
12518 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12519 }
12520 return;
12521 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012522
12523 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012524 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012525 callingProcess = mApp.getPackageManager().getApplicationInfo(
12526 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012527 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012528 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012529 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012530
12531 boolean isVisible = false;
12532 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12533 if (am != null) {
12534 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12535 if (processes != null) {
12536 for (ActivityManager.RunningAppProcessInfo process : processes) {
12537 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012538 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012539 if (process.processName.equals(callingProcess) && process.importance
12540 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12541 isVisible = true;
12542 break;
12543 }
12544 }
12545 }
12546 }
12547
12548 if (!isVisible) {
12549 try {
12550 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12551 callback.accept(result);
12552 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12553 } catch (RemoteException e) {
12554 String logStr = "Purchase premium capability "
12555 + TelephonyManager.convertPremiumCapabilityToString(capability)
12556 + " failed due to RemoteException handling background application: " + e;
12557 if (DBG) log(logStr);
12558 AnomalyReporter.reportAnomaly(
12559 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12560 }
12561 return;
12562 }
12563
Sarah Chin71b3a852022-09-28 15:54:19 -070012564 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012565 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012566 }
12567
12568 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012569 * Register an IMS connection state callback
12570 */
12571 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012572 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12573 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012574 if (feature == ImsFeature.FEATURE_MMTEL) {
12575 // ImsMmTelManager
12576 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12577 TelephonyPermissions
12578 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12579 mApp, subId, "registerImsStateCallback");
12580 } else if (feature == ImsFeature.FEATURE_RCS) {
12581 // ImsRcsManager or SipDelegateManager
12582 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12583 Binder.getCallingUid(), "registerImsStateCallback",
12584 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12585 Manifest.permission.READ_PRECISE_PHONE_STATE,
12586 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12587 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12588 }
12589
12590 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12591 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12592 "IMS not available on device.");
12593 }
12594
12595 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12596 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12597 }
12598
12599 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12600 if (controller == null) {
12601 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12602 "IMS not available on device.");
12603 }
12604
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012605 if (callingPackage == null) {
12606 callingPackage = getCurrentPackageName();
12607 }
12608
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012609 final long token = Binder.clearCallingIdentity();
12610 try {
12611 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012612 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012613 } catch (ImsException e) {
12614 throw new ServiceSpecificException(e.getCode());
12615 } finally {
12616 Binder.restoreCallingIdentity(token);
12617 }
12618 }
12619
12620 /**
12621 * Unregister an IMS connection state callback
12622 */
12623 @Override
12624 public void unregisterImsStateCallback(IImsStateCallback cb) {
12625 final long token = Binder.clearCallingIdentity();
12626 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12627 if (controller == null) {
12628 return;
12629 }
12630 try {
12631 controller.unregisterImsStateCallback(cb);
12632 } finally {
12633 Binder.restoreCallingIdentity(token);
12634 }
12635 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012636
12637 /**
12638 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12639 *
12640 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012641 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012642 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012643 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012644 * If there is current registered network this value will be same as the registered cell
12645 * identity. If the device goes out of service the previous cell identity is cached and
12646 * will be returned. If the cache age of the Cell identity is more than 24 hours
12647 * it will be cleared and null will be returned.
12648 *
12649 */
12650 @Override
12651 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12652 String callingFeatureId) {
12653 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12654 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12655 LocationAccessPolicy.checkLocationPermission(mApp,
12656 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12657 .setCallingPackage(callingPackage)
12658 .setCallingFeatureId(callingFeatureId)
12659 .setCallingPid(Binder.getCallingPid())
12660 .setCallingUid(Binder.getCallingUid())
12661 .setMethod("getLastKnownCellIdentity")
12662 .setLogAsInfo(true)
12663 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12664 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12665 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12666 .build());
12667
12668 boolean hasFinePermission =
12669 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12670 if (!hasFinePermission
12671 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12672 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012673 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012674 }
12675
12676 final long identity = Binder.clearCallingIdentity();
12677 try {
Ling Mac28f0212023-03-24 16:07:15 -070012678 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012679 if (sst == null) return null;
12680 return sst.getLastKnownCellIdentity();
12681 } finally {
12682 Binder.restoreCallingIdentity(identity);
12683 }
12684 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012685
jimsun3b9ccac2021-10-26 15:01:23 +080012686 /**
12687 * Sets the modem service class Name that Telephony will bind to.
12688 *
12689 * @param serviceName The class name of the modem service.
12690 * @return true if the operation is succeed, otherwise false.
12691 */
12692 public boolean setModemService(String serviceName) {
12693 Log.d(LOG_TAG, "setModemService - " + serviceName);
12694 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012696 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12697 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012698 return mPhoneConfigurationManager.setModemService(serviceName);
12699 }
12700
12701 /**
12702 * Return the class name of the currently bounded modem service.
12703 *
12704 * @return the class name of the modem service.
12705 */
12706 public String getModemService() {
12707 String result;
12708 Log.d(LOG_TAG, "getModemService");
12709 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12710 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012711 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012712 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12713 "getModemService");
12714 result = mPhoneConfigurationManager.getModemService();
12715 Log.d(LOG_TAG, "result = " + result);
12716 return result;
12717 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012718
Hakjun Choi3ee81112023-12-19 15:40:58 +000012719 /**
12720 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12721 * including carrier config, entitlement server, and config update.
12722 *
12723 * @param subId subId The subscription ID of the carrier.
12724 *
12725 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12726 * be returned.
12727 *
12728 * @throws SecurityException if the caller doesn't have the required permission.
12729 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012730 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12731 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012732 final long identity = Binder.clearCallingIdentity();
12733 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012734 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012735 } finally {
12736 Binder.restoreCallingIdentity(identity);
12737 }
12738 }
12739
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012740 @Override
12741 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12742 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12743 mApp.enforceCallingOrSelfPermission(
12744 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12745 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12746
12747 final long identity = Binder.clearCallingIdentity();
12748 try {
12749 Phone phone = getPhone(subId);
12750 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012751 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12752 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012753 phone.setVoiceServiceStateOverride(hasService);
12754 } finally {
12755 Binder.restoreCallingIdentity(identity);
12756 }
12757 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012758
12759 /**
12760 * set removable eSIM as default eUICC.
12761 *
12762 * @hide
12763 */
12764 @Override
12765 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12766 enforceModifyPermission();
12767 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12768
12769 final long identity = Binder.clearCallingIdentity();
12770 try {
12771 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12772 } finally {
12773 Binder.restoreCallingIdentity(identity);
12774 }
12775 }
12776
12777 /**
12778 * Returns whether the removable eSIM is default eUICC or not.
12779 *
12780 * @hide
12781 */
12782 @Override
12783 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12784 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12785 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12786
12787 final long identity = Binder.clearCallingIdentity();
12788 try {
12789 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12790 } finally {
12791 Binder.restoreCallingIdentity(identity);
12792 }
12793 }
12794
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012795 /**
12796 * Get the component name of the default app to direct respond-via-message intent for the
12797 * user associated with this subscription, update the cache if there is no respond-via-message
12798 * application currently configured for this user.
12799 * @return component name of the app and class to direct Respond Via Message intent to, or
12800 * {@code null} if the functionality is not supported.
12801 * @hide
12802 */
12803 @Override
12804 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12805 boolean updateIfNeeded) {
12806 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012807
joonhunshin4ac60942023-11-15 15:23:39 +000012808 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12809 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12810 "getDefaultRespondViaMessageApplication");
12811
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012812 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12813
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012814 UserHandle userHandle = null;
12815 final long identity = Binder.clearCallingIdentity();
12816 try {
12817 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12818 } finally {
12819 Binder.restoreCallingIdentity(identity);
12820 }
12821 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12822 updateIfNeeded, userHandle);
12823 }
Jack Yuf5badd92022-12-08 00:50:53 -080012824
12825 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012826 * Set whether the device is able to connect with null ciphering or integrity
12827 * algorithms. This is a global setting and will apply to all active subscriptions
12828 * and all new subscriptions after this.
12829 *
12830 * @param enabled when true, null cipher and integrity algorithms are allowed.
12831 * @hide
12832 */
12833 @Override
12834 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12835 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12836 enforceModifyPermission();
12837 checkForNullCipherAndIntegritySupport();
12838
12839 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12840 // for listening to these preference changes and applying them immediately.
12841 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12842 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12843 editor.apply();
12844
12845 for (Phone phone: PhoneFactory.getPhones()) {
12846 phone.handleNullCipherEnabledChange();
12847 }
12848 }
12849
12850
12851 /**
12852 * Get whether the device is able to connect with null ciphering or integrity
12853 * algorithms. Note that this retrieves the phone-global preference and not
12854 * the state of the radio.
12855 *
12856 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12857 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12858 * version for this feature.
12859 * @hide
12860 */
12861 @Override
12862 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12863 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12864 enforceReadPermission();
12865 checkForNullCipherAndIntegritySupport();
12866 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12867 }
12868
12869 private void checkForNullCipherAndIntegritySupport() {
12870 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12871 throw new UnsupportedOperationException(
12872 "Null cipher and integrity operations require HAL 2.1 or above");
12873 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012874 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12875 throw new UnsupportedOperationException(
12876 "Null cipher and integrity operations unsupported by modem");
12877 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012878 }
12879
Gil Cukierman06403e12023-11-29 16:33:03 +000012880 private void checkForIdentifierDisclosureNotificationSupport() {
12881 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12882 throw new UnsupportedOperationException(
12883 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12884 + "above");
12885 }
12886 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12887 throw new UnsupportedOperationException(
12888 "Cellular identifier disclosure transparency operations unsupported by modem");
12889 }
12890 }
12891
Michael Groover826b71d2023-12-21 22:08:06 -060012892 private void checkForNullCipherNotificationSupport() {
12893 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12894 throw new UnsupportedOperationException(
12895 "Null cipher notification operations require HAL 2.2 or above");
12896 }
12897 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12898 throw new UnsupportedOperationException(
12899 "Null cipher notification operations unsupported by modem");
12900 }
12901 }
12902
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012903 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012904 * Get the SIM state for the slot index.
12905 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12906 *
12907 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12908 */
12909 @Override
12910 @SimState
12911 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070012912 if (!mApp.getResources().getBoolean(
12913 com.android.internal.R.bool.config_force_phone_globals_creation)) {
12914 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12915 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12916 }
joonhunshin4ac60942023-11-15 15:23:39 +000012917
Jack Yuf5badd92022-12-08 00:50:53 -080012918 IccCardConstants.State simState;
12919 if (slotIndex < 0) {
12920 simState = IccCardConstants.State.UNKNOWN;
12921 } else {
12922 Phone phone = null;
12923 try {
12924 phone = PhoneFactory.getPhone(slotIndex);
12925 } catch (IllegalStateException e) {
12926 // ignore
12927 }
12928 if (phone == null) {
12929 simState = IccCardConstants.State.UNKNOWN;
12930 } else {
12931 IccCard icc = phone.getIccCard();
12932 if (icc == null) {
12933 simState = IccCardConstants.State.UNKNOWN;
12934 } else {
12935 simState = icc.getState();
12936 }
12937 }
12938 }
12939 return simState.ordinal();
12940 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012941
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012942 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12943 boolean enableLogcat,
12944 long logcatStartTimestampMillis, boolean enableTelecomDump,
12945 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012946 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012947 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12948 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12949 ecdDataBuilder
12950 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12951 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012952 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012953 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012954 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012955 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12956 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012957 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12958 Executors.newCachedThreadPool(), db,
12959 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012960 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012961 }
12962
12963 /**
12964 * Request telephony to persist state for debugging emergency call failures.
12965 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012966 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012967 * @param enableLogcat whether to collect logcat output
12968 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12969 * @param enableTelecomDump whether to collect telecom dumpsys
12970 * @param enableTelephonyDump whether to collect telephony dumpsys
12971 */
12972 @Override
12973 @RequiresPermission(android.Manifest.permission.DUMP)
12974 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12975 long logcatStartTimestampMillis, boolean enableTelecomDump,
12976 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012977 // Verify that the caller has READ_DROPBOX_DATA permission.
12978 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12979 && Flags.enableReadDropboxPermission()) {
12980 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12981 "persistEmergencyCallDiagnosticData");
12982 } else {
12983 // Otherwise, enforce legacy permission.
12984 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12985 "persistEmergencyCallDiagnosticData");
12986 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012987 final long identity = Binder.clearCallingIdentity();
12988 try {
12989 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12990 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12991
12992 } finally {
12993 Binder.restoreCallingIdentity(identity);
12994 }
12995 }
12996
Hui Wang9b5793a2022-12-05 14:38:06 -060012997 /**
12998 * Get current cell broadcast ranges.
12999 */
13000 @Override
13001 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13002 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13003 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13004 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013005
13006 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13007 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13008
Hui Wang9b5793a2022-12-05 14:38:06 -060013009 final long identity = Binder.clearCallingIdentity();
13010 try {
13011 return getPhone(subId).getCellBroadcastIdRanges();
13012 } finally {
13013 Binder.restoreCallingIdentity(identity);
13014 }
13015 }
13016
13017 /**
13018 * Set reception of cell broadcast messages with the list of the given ranges
13019 *
13020 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13021 */
13022 @Override
13023 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13024 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13025 @Nullable IIntegerConsumer callback) {
13026 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13027 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013028
13029 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13030 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13031
Hui Wang9b5793a2022-12-05 14:38:06 -060013032 final long identity = Binder.clearCallingIdentity();
13033 try {
13034 Phone phone = getPhoneFromSubId(subId);
13035 if (DBG) {
13036 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13037 }
13038 phone.setCellBroadcastIdRanges(ranges, result -> {
13039 if (callback != null) {
13040 try {
13041 callback.accept(result);
13042 } catch (RemoteException e) {
13043 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13044 }
13045 }
13046 });
13047 } finally {
13048 Binder.restoreCallingIdentity(identity);
13049 }
13050 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013051
13052 /**
13053 * Returns whether the device supports the domain selection service.
13054 *
13055 * @return {@code true} if the device supports the domain selection service.
13056 */
13057 @Override
13058 public boolean isDomainSelectionSupported() {
13059 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13060 "isDomainSelectionSupported");
13061
13062 final long identity = Binder.clearCallingIdentity();
13063 try {
13064 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13065 } finally {
13066 Binder.restoreCallingIdentity(identity);
13067 }
13068 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013069
13070 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013071 * Returns whether the AOSP domain selection service is supported.
13072 *
13073 * @return {@code true} if the AOSP domain selection service is supported,
13074 * {@code false} otherwise.
13075 */
13076 @Override
13077 public boolean isAospDomainSelectionService() {
13078 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13079 "isAospDomainSelectionService");
13080
13081 final long identity = Binder.clearCallingIdentity();
13082 try {
13083 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13084 String dssComponentName = mApp.getResources().getString(
13085 R.string.config_domain_selection_service_component_name);
13086 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13087 TelephonyDomainSelectionService.class.getName());
13088 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13089 + ", aosp=" + componentName.flattenToString());
13090 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13091 }
13092 } finally {
13093 Binder.restoreCallingIdentity(identity);
13094 }
13095 return false;
13096 }
13097
13098 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013099 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13100 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13101 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013102 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013103 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013104 * @param enableSatellite {@code true} to enable the satellite modem and
13105 * {@code false} to disable.
13106 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013107 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013108 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013109 *
13110 * @throws SecurityException if the caller doesn't have the required permission.
13111 */
13112 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013113 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013114 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013115 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013116 if (enableSatellite) {
13117 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13118 @Override
13119 protected void onReceiveResult(int resultCode, Bundle resultData) {
13120 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13121 + ", resultData=" + resultData);
13122 boolean isAllowed = false;
13123 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13124 callback::accept);
13125 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13126 if (resultData != null
13127 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13128 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13129 } else {
13130 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13131 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013132 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013133 result.accept(resultCode);
13134 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013135 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013136 if (isAllowed) {
13137 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013138 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013139 } else {
13140 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13141 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013142 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013143 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013144 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013145 subId, resultReceiver);
13146 } else {
13147 // No need to check if satellite is allowed at current location when disabling satellite
13148 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013149 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013150 }
Sarah Chin503828c2023-02-01 23:54:20 -080013151 }
13152
13153 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013154 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013155 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013156 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013157 * @param result The result receiver that returns whether the satellite modem is enabled
13158 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013159 *
13160 * @throws SecurityException if the caller doesn't have the required permission.
13161 */
13162 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013163 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13164 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013165 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013166 }
13167
13168 /**
Sarah Chin43457982023-02-15 17:50:38 -080013169 * Request to get whether the satellite service demo mode is enabled.
13170 *
13171 * @param subId The subId of the subscription to check whether the satellite demo mode
13172 * is enabled for.
13173 * @param result The result receiver that returns whether the satellite demo mode is enabled
13174 * if the request is successful or an error code if the request failed.
13175 *
13176 * @throws SecurityException if the caller doesn't have the required permission.
13177 */
13178 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013179 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13180 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13181 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013182 }
13183
13184 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013185 * Request to get whether the satellite service is enabled with emergency mode.
13186 *
13187 * @param subId The subId of the subscription to check whether the satellite demo mode
13188 * is enabled for.
13189 * @param result The result receiver that returns whether the satellite emergency mode is
13190 * enabled if the request is successful or an error code if the request failed.
13191 *
13192 * @throws SecurityException if the caller doesn't have the required permission.
13193 */
13194 @Override
13195 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13196 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
joonhunshinfd78fd52024-07-11 05:28:13 +000013197 mSatelliteController.requestIsEmergencyModeEnabled(subId, result);
Thomas Nguyena8062672024-02-05 14:18:19 -080013198 }
13199
13200 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013201 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013202 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013203 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013204 * @param result The result receiver that returns whether the satellite service is supported on
13205 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013206 */
13207 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013208 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013209 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013210 }
13211
13212 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013213 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013214 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013215 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013216 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13217 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013218 *
13219 * @throws SecurityException if the caller doesn't have required permission.
13220 */
13221 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013222 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13223 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013224 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013225 }
13226
13227 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013228 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013229 * This can be called by the pointing UI when the user starts pointing to the satellite.
13230 * Modem should continue to report the pointing input as the device or satellite moves.
13231 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013232 * @param subId The subId of the subscription to start satellite transmission updates for.
13233 * @param resultCallback The callback to get the result of the request.
13234 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013235 *
13236 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013237 */
13238 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013239 public void startSatelliteTransmissionUpdates(int subId,
13240 @NonNull IIntegerConsumer resultCallback,
13241 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13242 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13243 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013244 }
13245
13246 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013247 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013248 * This can be called by the pointing UI when the user stops pointing to the satellite.
13249 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013250 * @param subId The subId of the subscription to stop satellite transmission updates for.
13251 * @param resultCallback The callback to get the result of the request.
13252 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13253 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013254 *
13255 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013256 */
13257 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013258 public void stopSatelliteTransmissionUpdates(int subId,
13259 @NonNull IIntegerConsumer resultCallback,
13260 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13261 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13262 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013263 }
13264
13265 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013266 * Register the subscription with a satellite provider.
13267 * This is needed to register the subscription if the provider allows dynamic registration.
13268 *
13269 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013270 * @param token The token to be used as a unique identifier for provisioning with satellite
13271 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013272 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013273 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013274 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013275 * @return The signal transport used by the caller to cancel the provision request,
13276 * or {@code null} if the request failed.
13277 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013278 * @throws SecurityException if the caller doesn't have the required permission.
13279 */
13280 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013281 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013282 @NonNull String token, @NonNull byte[] provisionData,
13283 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013284 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013285 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13286 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013287 }
13288
13289 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013290 * Unregister the device/subscription with the satellite provider.
13291 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013292 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013293 * should report as deprovisioned.
13294 *
13295 * @param subId The subId of the subscription to be deprovisioned.
13296 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013297 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013298 *
13299 * @throws SecurityException if the caller doesn't have the required permission.
13300 */
13301 @Override
13302 public void deprovisionSatelliteService(int subId,
13303 @NonNull String token, @NonNull IIntegerConsumer callback) {
13304 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013305 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013306 }
13307
13308 /**
Sarah Chin43457982023-02-15 17:50:38 -080013309 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013310 *
Sarah Chin43457982023-02-15 17:50:38 -080013311 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013312 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013313 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013314 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013315 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013316 * @throws SecurityException if the caller doesn't have the required permission.
13317 */
13318 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013319 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13320 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013321 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013322 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013323 }
13324
13325 /**
Sarah Chin43457982023-02-15 17:50:38 -080013326 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013327 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013328 *
Sarah Chin43457982023-02-15 17:50:38 -080013329 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013330 * @param callback The callback that was passed to
13331 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013332 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013333 * @throws SecurityException if the caller doesn't have the required permission.
13334 */
13335 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013336 public void unregisterForSatelliteProvisionStateChanged(
13337 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013338 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013339 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013340 }
13341
13342 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013343 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013344 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013345 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013346 * @param result The result receiver that returns whether the device is provisioned with a
13347 * satellite provider if the request is successful or an error code if the
13348 * request failed.
13349 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013350 * @throws SecurityException if the caller doesn't have the required permission.
13351 */
13352 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013353 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13354 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013355 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013356 }
13357
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013358 /**
Sarah Chin43457982023-02-15 17:50:38 -080013359 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013360 *
Sarah Chin43457982023-02-15 17:50:38 -080013361 * @param subId The subId of the subscription to register for satellite modem state changed.
13362 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013363 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013364 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013365 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013366 * @throws SecurityException if the caller doesn't have the required permission.
13367 */
13368 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013369 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013370 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013371 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013372 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013373 }
13374
13375 /**
Sarah Chin43457982023-02-15 17:50:38 -080013376 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013377 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013378 *
Sarah Chin43457982023-02-15 17:50:38 -080013379 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013380 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013381 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013382 *
13383 * @throws SecurityException if the caller doesn't have the required permission.
13384 */
13385 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013386 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013387 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013388 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13389 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013390 }
13391
13392 /**
13393 * Register to receive incoming datagrams over satellite.
13394 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013395 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013396 * @param callback The callback to handle incoming datagrams over satellite.
13397 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013398 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013399 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013400 * @throws SecurityException if the caller doesn't have the required permission.
13401 */
13402 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013403 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013404 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013405 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13406 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013407 }
13408
13409 /**
13410 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013411 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013412 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013413 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13414 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013415 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013416 *
13417 * @throws SecurityException if the caller doesn't have the required permission.
13418 */
13419 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013420 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013421 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013422 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13423 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013424 }
13425
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013426 /**
13427 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013428 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013429 * This method requests modem to check if there are any pending datagrams to be received over
13430 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013431 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013432 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013433 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013434 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013435 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013436 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013437 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013438 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13439 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13440 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013441 }
13442
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013443 /**
13444 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013445 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013446 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13447 * input to this method. Datagram received here will be passed down to modem without any
13448 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013449 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013450 * @param subId The subId of the subscription to send satellite datagrams for.
13451 * @param datagramType datagram type indicating whether the datagram is of type
13452 * SOS_SMS or LOCATION_SHARING.
13453 * @param datagram encoded gateway datagram which is encrypted by the caller.
13454 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013455 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13456 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013457 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013458 *
13459 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013460 */
13461 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013462 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013463 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13464 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013465 enforceSatelliteCommunicationPermission("sendDatagram");
13466 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13467 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013468 }
13469
Sarah Chindf715ec2023-02-13 13:46:24 -080013470 /**
13471 * Request to get whether satellite communication is allowed for the current location.
13472 *
13473 * @param subId The subId of the subscription to check whether satellite communication is
13474 * allowed for the current location for.
13475 * @param result The result receiver that returns whether satellite communication is allowed
13476 * for the current location if the request is successful or an error code
13477 * if the request failed.
13478 *
13479 * @throws SecurityException if the caller doesn't have the required permission.
13480 */
13481 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013482 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013483 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013484 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13485 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13486 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013487 }
13488
13489 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013490 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013491 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013492 * @param subId The subId to get the time after which the satellite will be visible for.
13493 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013494 * be visible if the request is successful or an error code if the request failed.
13495 *
13496 * @throws SecurityException if the caller doesn't have the required permission.
13497 */
13498 @Override
13499 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13500 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013501 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013502 }
13503
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013504 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013505 * Inform that Device is aligned to satellite for demo mode.
13506 *
13507 * @param subId The subId to get the time after which the satellite will be visible for.
13508 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13509 * {@code false} Device fails to align with the satellite for demo mode.
13510 *
13511 * @throws SecurityException if the caller doesn't have required permission.
13512 */
13513 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13514
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013515 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013516 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013517 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013518 }
13519
13520 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013521 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13522 * by modem.
13523 *
13524 * @param subId The subId of the subscription to request for.
13525 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013526 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013527 * operation.
13528 *
13529 * @throws SecurityException if the caller doesn't have required permission.
13530 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013531 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013532 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13533 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013534 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013535 final long identity = Binder.clearCallingIdentity();
13536 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013537 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013538 } finally {
13539 Binder.restoreCallingIdentity(identity);
13540 }
13541 }
13542
13543 /**
13544 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13545 * by modem.
13546 *
13547 * @param subId The subId of the subscription to request for.
13548 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013549 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013550 * operation.
13551 *
13552 * @throws SecurityException if the caller doesn't have required permission.
13553 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013554 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013555 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13556 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013557 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013558 final long identity = Binder.clearCallingIdentity();
13559 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013560 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013561 } finally {
13562 Binder.restoreCallingIdentity(identity);
13563 }
13564 }
13565
13566 /**
13567 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013568 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013569 *
13570 * @param subId The subId of the subscription to request for.
13571 *
13572 * @return Integer array of reasons for disallowing satellite communication.
13573 *
13574 * @throws SecurityException if the caller doesn't have the required permission.
13575 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013576 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013577 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013578 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013579 final long identity = Binder.clearCallingIdentity();
13580 try {
13581 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013582 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013583 return reasonSet.stream().mapToInt(i->i).toArray();
13584 } finally {
13585 Binder.restoreCallingIdentity(identity);
13586 }
13587 }
13588
13589 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013590 * Request to get the signal strength of the satellite connection.
13591 *
13592 * @param subId The subId of the subscription to request for.
13593 * @param result Result receiver to get the error code of the request and the current signal
13594 * strength of the satellite connection.
13595 *
13596 * @throws SecurityException if the caller doesn't have required permission.
13597 */
13598 @Override
13599 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13600 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13601 final long identity = Binder.clearCallingIdentity();
13602 try {
13603 mSatelliteController.requestNtnSignalStrength(subId, result);
13604 } finally {
13605 Binder.restoreCallingIdentity(identity);
13606 }
13607 }
13608
13609 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013610 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13611 * is not successful, a {@link ServiceSpecificException} that contains
13612 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013613 *
13614 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013615 * @param callback The callback to handle the NTN signal strength changed event. If the
13616 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13617 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13618 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13619 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013620 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013621 * @throws SecurityException If the caller doesn't have the required permission.
13622 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013623 */
13624 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013625 public void registerForNtnSignalStrengthChanged(int subId,
13626 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013627 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13628 final long identity = Binder.clearCallingIdentity();
13629 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013630 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013631 } finally {
13632 Binder.restoreCallingIdentity(identity);
13633 }
13634 }
13635
13636 /**
13637 * Unregisters for NTN signal strength changed from satellite modem.
13638 * If callback was not registered before, the request will be ignored.
13639 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013640 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13641 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013642 * @param callback The callback that was passed to
13643 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13644 *
13645 * @throws SecurityException if the caller doesn't have the required permission.
13646 */
13647 @Override
13648 public void unregisterForNtnSignalStrengthChanged(
13649 int subId, @NonNull INtnSignalStrengthCallback callback) {
13650 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13651 final long identity = Binder.clearCallingIdentity();
13652 try {
13653 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13654 } finally {
13655 Binder.restoreCallingIdentity(identity);
13656 }
13657 }
13658
13659 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013660 * Registers for satellite capabilities change event from the satellite service.
13661 *
13662 * @param subId The subId of the subscription to request for.
13663 * @param callback The callback to handle the satellite capabilities changed event.
13664 *
13665 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13666 *
13667 * @throws SecurityException if the caller doesn't have required permission.
13668 */
13669 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013670 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013671 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013672 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013673 final long identity = Binder.clearCallingIdentity();
13674 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013675 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013676 } finally {
13677 Binder.restoreCallingIdentity(identity);
13678 }
13679 }
13680
13681 /**
13682 * Unregisters for satellite capabilities change event from the satellite service.
13683 * If callback was not registered before, the request will be ignored.
13684 *
13685 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13686 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013687 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013688 *
13689 * @throws SecurityException if the caller doesn't have required permission.
13690 */
13691 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013692 public void unregisterForCapabilitiesChanged(int subId,
13693 @NonNull ISatelliteCapabilitiesCallback callback) {
13694 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013695 final long identity = Binder.clearCallingIdentity();
13696 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013697 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013698 } finally {
13699 Binder.restoreCallingIdentity(identity);
13700 }
13701 }
13702
13703 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013704 * Registers for the satellite supported state changed.
13705 *
13706 * @param subId The subId of the subscription to register for supported state changed.
13707 * @param callback The callback to handle the satellite supported state changed event.
13708 *
13709 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13710 *
13711 * @throws SecurityException if the caller doesn't have the required permission.
13712 */
13713 @Override
13714 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13715 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13716 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13717 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13718 }
13719
13720 /**
13721 * Unregisters for the satellite supported state changed.
13722 * If callback was not registered before, the request will be ignored.
13723 *
13724 * @param subId The subId of the subscription to unregister for supported state changed.
13725 * @param callback The callback that was passed to
13726 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13727 *
13728 * @throws SecurityException if the caller doesn't have the required permission.
13729 */
13730 @Override
13731 public void unregisterForSatelliteSupportedStateChanged(
13732 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13733 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13734 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13735 }
13736
13737 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013738 * This API can be used by only CTS to update satellite vendor service package name.
13739 *
13740 * @param servicePackageName The package name of the satellite vendor service.
13741 * @return {@code true} if the satellite vendor service is set successfully,
13742 * {@code false} otherwise.
13743 */
13744 public boolean setSatelliteServicePackageName(String servicePackageName) {
13745 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13746 TelephonyPermissions.enforceShellOnly(
13747 Binder.getCallingUid(), "setSatelliteServicePackageName");
13748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13749 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13750 "setSatelliteServicePackageName");
13751 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13752 }
13753
13754 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013755 * This API can be used by only CTS to update satellite gateway service package name.
13756 *
13757 * @param servicePackageName The package name of the satellite gateway service.
13758 * @return {@code true} if the satellite gateway service is set successfully,
13759 * {@code false} otherwise.
13760 */
13761 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13762 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13763 TelephonyPermissions.enforceShellOnly(
13764 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13766 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13767 "setSatelliteGatewayServicePackageName");
13768 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13769 }
13770
13771 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013772 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13773 *
13774 * @param packageName The package name of the satellite pointing UI app.
13775 * @param className The class name of the satellite pointing UI app.
13776 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13777 * {@code false} otherwise.
13778 */
13779 public boolean setSatellitePointingUiClassName(
13780 @Nullable String packageName, @Nullable String className) {
13781 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13782 + ", className=" + className);
13783 TelephonyPermissions.enforceShellOnly(
13784 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13786 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13787 "setSatelliteGatewayServicePackageName");
13788 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13789 }
13790
13791 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013792 * This API can be used by only CTS to update the timeout duration in milliseconds that
13793 * satellite should stay at listening mode to wait for the next incoming page before disabling
13794 * listening mode.
13795 *
13796 * @param timeoutMillis The timeout duration in millisecond.
13797 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13798 */
13799 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13800 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13801 TelephonyPermissions.enforceShellOnly(
13802 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13804 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13805 "setSatelliteListeningTimeoutDuration");
13806 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13807 }
13808
13809 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013810 * This API can be used by only CTS to override the timeout durations used by the
13811 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013812 *
13813 * @param timeoutMillis The timeout duration in millisecond.
13814 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13815 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013816 public boolean setDatagramControllerTimeoutDuration(
13817 boolean reset, int timeoutType, long timeoutMillis) {
13818 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13819 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013820 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013821 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13823 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013824 "setDatagramControllerTimeoutDuration");
13825 return mSatelliteController.setDatagramControllerTimeoutDuration(
13826 reset, timeoutType, timeoutMillis);
13827 }
13828
13829 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013830 * This API can be used by only CTS to override the boolean configs used by the
13831 * DatagramController module.
13832 *
13833 * @param enable Whether to enable or disable boolean config.
13834 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13835 */
13836 public boolean setDatagramControllerBooleanConfig(
13837 boolean reset, int booleanType, boolean enable) {
13838 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13839 + ", reset=" + reset + ", enable=" + enable);
13840 TelephonyPermissions.enforceShellOnly(
13841 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13843 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13844 "ssetDatagramControllerBooleanConfig");
13845 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13846 }
13847
13848
13849 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013850 * This API can be used by only CTS to override the timeout durations used by the
13851 * SatelliteController module.
13852 *
13853 * @param timeoutMillis The timeout duration in millisecond.
13854 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13855 */
13856 public boolean setSatelliteControllerTimeoutDuration(
13857 boolean reset, int timeoutType, long timeoutMillis) {
13858 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13859 + reset + ", timeoutMillis=" + timeoutMillis);
13860 TelephonyPermissions.enforceShellOnly(
13861 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13863 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13864 "setSatelliteControllerTimeoutDuration");
13865 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13866 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013867 }
13868
13869 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013870 * This API can be used in only testing to override connectivity status in monitoring emergency
13871 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13872 *
13873 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13874 * of the following values to enable the override:
13875 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13876 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13877 * To disable the override, use -1 for handoverType.
13878 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13879 * delaySeconds after the emergency call starts.
13880 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13881 */
13882 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13883 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13884 TelephonyPermissions.enforceShellOnly(
13885 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13887 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13888 "setEmergencyCallToSatelliteHandoverType");
13889 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13890 handoverType, delaySeconds);
13891 }
13892
13893 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013894 * This API can be used in only testing to override oem-enabled satellite provision status.
13895 *
13896 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13897 * otherwise.
13898 * @param isProvisioned The overriding provision status.
13899 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13900 */
13901 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13902 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13903 + ", isProvisioned=" + isProvisioned);
13904 TelephonyPermissions.enforceShellOnly(
13905 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13907 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13908 "setOemEnabledSatelliteProvisionStatus");
13909 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13910 }
13911
13912 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013913 * This API should be used by only CTS tests to forcefully set telephony country codes.
13914 *
13915 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13916 */
13917 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13918 Map cachedNetworkCountryCodes, String locationCountryCode,
13919 long locationCountryCodeTimestampNanos) {
13920 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13921 + String.join(", ", currentNetworkCountryCodes)
13922 + ", locationCountryCode=" + locationCountryCode
13923 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13924 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13925 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13926 TelephonyPermissions.enforceShellOnly(
13927 Binder.getCallingUid(), "setCachedLocationCountryCode");
13928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13929 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13930 "setCachedLocationCountryCode");
13931 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13932 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13933 locationCountryCodeTimestampNanos);
13934 }
13935
13936 /**
13937 * This API should be used by only CTS tests to override the overlay configs of satellite
13938 * access controller.
13939 *
13940 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13941 * otherwise.
13942 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13943 */
13944 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13945 String s2CellFile, long locationFreshDurationNanos,
13946 List<String> satelliteCountryCodes) {
13947 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13948 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13949 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13950 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13951 ? String.join(", ", satelliteCountryCodes) : null));
13952 TelephonyPermissions.enforceShellOnly(
13953 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13955 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13956 "setSatelliteAccessControlOverlayConfigs");
13957 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13958 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13959 }
13960
13961 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013962 * This API can be used by only CTS to override the cached value for the device overlay config
13963 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13964 * outgoing satellite datagrams should be sent to modem in demo mode.
13965 *
13966 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13967 * satellite modem or not.
13968 *
13969 * @return {@code true} if the operation is successful, {@code false} otherwise.
13970 */
13971 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13972 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13973 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13974 + "disabled");
13975 return false;
13976 }
13977 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13978 TelephonyPermissions.enforceShellOnly(
13979 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13981 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13982 "setShouldSendDatagramToModemInDemoMode");
13983 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13984 shouldSendToModemInDemoMode);
13985 }
13986
13987 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000013988 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
13989 *
13990 * @param state a state indicates whether satellite access allowed state should be cached and
13991 * the allowed state.
13992 * @return {@code true} if the setting is successful, {@code false} otherwise.
13993 */
13994 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
13995 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13996 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13997 + "oemEnabledSatelliteFlag is disabled");
13998 return false;
13999 }
14000
14001 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14002 + "state=" + state);
14003 TelephonyPermissions.enforceShellOnly(
14004 Binder.getCallingUid(),
14005 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14007 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14008 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14009 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
14010 state);
14011 }
14012
14013 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014014 * Sets the service defined in ComponentName to be bound.
14015 *
14016 * This should only be used for testing.
14017 * @return {@code true} if the DomainSelectionService to bind to was set,
14018 * {@code false} otherwise.
14019 */
14020 @Override
14021 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14022 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14023
14024 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14025 "setDomainSelectionServiceOverride");
14026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14027 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14028
14029 final long identity = Binder.clearCallingIdentity();
14030 try {
14031 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14032 return DomainSelectionResolver.getInstance()
14033 .setDomainSelectionServiceOverride(componentName);
14034 }
14035 } finally {
14036 Binder.restoreCallingIdentity(identity);
14037 }
14038 return false;
14039 }
14040
14041 /**
14042 * Clears the DomainSelectionService override.
14043 *
14044 * This should only be used for testing.
14045 * @return {@code true} if the DomainSelectionService override was cleared,
14046 * {@code false} otherwise.
14047 */
14048 @Override
14049 public boolean clearDomainSelectionServiceOverride() {
14050 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14051
14052 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14053 "clearDomainSelectionServiceOverride");
14054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14055 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14056
14057 final long identity = Binder.clearCallingIdentity();
14058 try {
14059 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14060 return DomainSelectionResolver.getInstance()
14061 .clearDomainSelectionServiceOverride();
14062 }
14063 } finally {
14064 Binder.restoreCallingIdentity(identity);
14065 }
14066 return false;
14067 }
14068
14069 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014070 * Enable or disable notifications sent for cellular identifier disclosure events.
14071 *
14072 * Disclosure events are defined as instances where a device has sent a cellular identifier
14073 * on the Non-access stratum (NAS) before a security context is established. As a result the
14074 * identifier is sent in the clear, which has privacy implications for the user.
14075 *
14076 * @param enable if notifications about disclosure events should be enabled
14077 * @throws SecurityException if the caller does not have the required privileges
14078 * @throws UnsupportedOperationException if the modem does not support this feature.
14079 */
14080 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014081 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014082 enforceModifyPermission();
14083 checkForIdentifierDisclosureNotificationSupport();
14084
14085 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14086 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14087 editor.apply();
14088
14089 // Each phone instance is responsible for updating its respective modem immediately
14090 // after we've made a preference change.
14091 for (Phone phone : PhoneFactory.getPhones()) {
14092 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14093 }
14094 }
14095
14096 /**
14097 * Get whether or not cellular identifier disclosure notifications are enabled.
14098 *
14099 * @throws SecurityException if the caller does not have the required privileges
14100 * @throws UnsupportedOperationException if the modem does not support this feature.
14101 */
14102 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014103 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014104 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14105 checkForIdentifierDisclosureNotificationSupport();
14106 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14107 }
14108
14109 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014110 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14111 * are in use by the cellular modem.
14112 *
14113 * @throws IllegalStateException if the Telephony process is not currently available
14114 * @throws SecurityException if the caller does not have the required privileges
14115 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14116 * and integrity algorithms in use
14117 * @hide
14118 */
14119 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014120 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014121 enforceModifyPermission();
14122 checkForNullCipherNotificationSupport();
14123
14124 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14125 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14126 editor.apply();
14127
14128 // Each phone instance is responsible for updating its respective modem immediately
14129 // after a preference change.
14130 for (Phone phone : PhoneFactory.getPhones()) {
14131 phone.handleNullCipherNotificationPreferenceChanged();
14132 }
14133 }
14134
14135 /**
14136 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14137 * cellular modem.
14138 *
14139 * @throws IllegalStateException if the Telephony process is not currently available
14140 * @throws SecurityException if the caller does not have the required privileges
14141 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14142 * and integrity algorithms in use
14143 * @hide
14144 */
14145 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14146 public boolean isNullCipherNotificationsEnabled() {
14147 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14148 checkForNullCipherNotificationSupport();
14149 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14150 }
14151
14152 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014153 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14154 *
14155 * <p>This method behaves in one of the following ways:
14156 * <ul>
14157 * <li>return true : if the calling package has the appop permission {@link
14158 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14159 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14160 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14161 * Owner device identifier access check, or the calling package has carrier privileges</>
14162 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14163 * </ul>
14164 */
14165 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14166 String callingPackage, @Nullable String callingFeatureId, String message) {
14167 for (Phone phone : PhoneFactory.getPhones()) {
14168 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14169 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14170 return true;
14171 }
14172 }
14173 return false;
14174 }
arunvoddud7401012022-12-15 16:08:12 +000014175
14176 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014177 * @return The subscription manager service instance.
14178 */
14179 public SubscriptionManagerService getSubscriptionManagerService() {
14180 return SubscriptionManagerService.getInstance();
14181 }
14182
14183 /**
arunvoddud7401012022-12-15 16:08:12 +000014184 * Class binds the consumer[callback] and carrierId.
14185 */
14186 private static class CallerCallbackInfo {
14187 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014188 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014189
Steve Statia28b7cb32024-03-11 23:58:50 +000014190 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014191 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014192 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014193 }
14194
14195 public Consumer<Integer> getConsumer() {
14196 return mConsumer;
14197 }
14198
Steve Statia28b7cb32024-03-11 23:58:50 +000014199 public Set<Integer> getCarrierIds() {
14200 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014201 }
14202 }
joonhunshin4ac60942023-11-15 15:23:39 +000014203
14204 /*
14205 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14206 * But the context that is passed in is unused if the phone app is already alive.
14207 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14208 */
14209 @VisibleForTesting
14210 public void setPackageManager(PackageManager packageManager) {
14211 mPackageManager = packageManager;
14212 }
14213
14214 /*
Nate Myren453c3472024-03-13 11:28:11 -070014215 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14216 * But the context that is passed in is unused if the phone app is already alive.
14217 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14218 */
14219 @VisibleForTesting
14220 public void setAppOpsManager(AppOpsManager appOps) {
14221 mAppOps = appOps;
14222 }
14223
14224 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014225 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14226 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14227 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14228 */
14229 @VisibleForTesting
14230 public void setFeatureFlags(FeatureFlags featureFlags) {
14231 mFeatureFlags = featureFlags;
14232 }
14233
14234 /**
14235 * Make sure the device has required telephony feature
14236 *
14237 * @throws UnsupportedOperationException if the device does not have required telephony feature
14238 */
14239 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14240 @NonNull String telephonyFeature, @NonNull String methodName) {
14241 if (callingPackage == null || mPackageManager == null) {
14242 return;
14243 }
14244
14245 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14246 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014247 Binder.getCallingUserHandle())
14248 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14249 // Skip to check associated telephony feature,
14250 // if compatibility change is not enabled for the current process or
14251 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014252 return;
14253 }
14254
14255 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14256 throw new UnsupportedOperationException(
14257 methodName + " is unsupported without " + telephonyFeature);
14258 }
14259 }
youngtaecha5d483d52024-04-29 17:05:45 +000014260
14261 /**
14262 * Registers for the satellite communication allowed state changed.
14263 *
14264 * @param subId The subId of the subscription to register for the satellite communication
14265 * allowed state changed.
14266 * @param callback The callback to handle the satellite communication allowed
14267 * state changed event.
14268 *
14269 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14270 *
14271 * @throws SecurityException if the caller doesn't have the required permission.
14272 */
14273 @Override
14274 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14275 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14276 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14277 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14278 subId, callback);
14279 }
14280
14281 /**
14282 * Unregisters for the satellite communication allowed state changed.
14283 * If callback was not registered before, the request will be ignored.
14284 *
14285 * @param subId The subId of the subscription to unregister for the satellite communication
14286 * allowed state changed.
14287 * @param callback The callback that was passed to
14288 * {@link #registerForCommunicationAllowedStateChanged(int,
14289 * ISatelliteCommunicationAllowedStateCallback)}. *
14290 * @throws SecurityException if the caller doesn't have the required permission.
14291 */
14292 @Override
14293 public void unregisterForCommunicationAllowedStateChanged(
14294 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14295 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14296 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14297 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014298
14299 /**
14300 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14301 *
14302 * @param subId The subId of the subscription to the satellite session stats for.
14303 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14304 * if the request is successful or an error code if the request failed.
14305 *
14306 * @throws SecurityException if the caller doesn't have required permission.
14307 */
14308 @Override
14309 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14310 enforceModifyPermission();
14311 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
14312 mSatelliteController.requestSatelliteSessionStats(subId, result);
14313 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014314
14315 /**
14316 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14317 *
14318 * @param result The result receiver, which returns the list of prioritized satellite tokens
14319 * to be used for provision if the request is successful or an error code if the request failed.
14320 *
14321 * @throws SecurityException if the caller doesn't have the required permission.
14322 */
14323 @Override
14324 public void requestProvisionSubscriberIds(@NonNull ResultReceiver result) {
14325 enforceSatelliteCommunicationPermission("requestProvisionSubscriberIds");
14326 mSatelliteController.requestProvisionSubscriberIds(result);
14327 }
14328
14329 /**
14330 * Request to get provisioned status for given a satellite subscriber id.
14331 *
14332 * @param satelliteSubscriberId Satellite subscriber id requiring provisioned status check.
14333 * @param result The result receiver, which returns the provisioned status of the token if the
14334 * request is successful or an error code if the request failed.
14335 *
14336 * @throws SecurityException if the caller doesn't have the required permission.
14337 */
14338 @Override
14339 public void requestIsProvisioned(String satelliteSubscriberId, @NonNull ResultReceiver result) {
14340 enforceSatelliteCommunicationPermission("requestIsProvisioned");
14341 mSatelliteController.requestIsProvisioned(satelliteSubscriberId, result);
14342 }
14343
14344 /**
14345 * Deliver the list of provisioned satellite subscriber ids.
14346 *
14347 * @param list List of provisioned satellite subscriber ids.
14348 * @param result The result receiver that returns whether deliver success or fail.
14349 *
14350 * @throws SecurityException if the caller doesn't have the required permission.
14351 */
14352 @Override
14353 public void provisionSatellite(List<ProvisionSubscriberId> list,
14354 @NonNull ResultReceiver result) {
14355 enforceSatelliteCommunicationPermission("provisionSatellite");
14356 mSatelliteController.provisionSatellite(list, result);
14357 }
Jack Yufa8ed012023-02-11 15:42:28 -080014358}