blob: 36ed19d0621d8bfc9bea08ded57730f050923836 [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;
Sangyun Yun8bb66452024-11-25 15:46:10 +000029import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_NOT_PROVISIONED;
30import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_NOT_SUPPORTED;
31import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP;
Hall Liud892bec2018-11-30 14:51:45 -080032
Shuo Qianccbaf742021-02-22 18:32:21 -080033import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
34import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070035import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070036import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000037import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070038
Brad Ebinger34c09a52021-02-17 23:23:21 +000039import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080040import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080041import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070042import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000043import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080044import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080046import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070047import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000048import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080049import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000050import android.compat.annotation.ChangeId;
51import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000052import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070053import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070054import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.content.Context;
56import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070057import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070058import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070059import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.net.Uri;
61import android.os.AsyncResult;
62import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080063import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080065import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070067import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080068import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080069import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.os.Looper;
71import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070072import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080073import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070074import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070075import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080076import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080077import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070078import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070079import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080080import android.os.SystemClock;
joonhunshinf624b2a2024-04-18 04:42:12 +000081import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070083import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070084import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070085import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070086import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080087import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070088import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000089import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090090import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080091import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080092import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070093import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080094import android.telephony.AccessNetworkConstants;
95import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070096import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070097import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080098import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070099import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -0800100import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -0700101import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -0800102import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600103import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700104import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800105import android.telephony.CellIdentityCdma;
106import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700108import android.telephony.CellInfoGsm;
109import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700110import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800111import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700112import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700113import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700114import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800115import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700116import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800117import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700118import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800119import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800120import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700121import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800122import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800124import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800125import android.telephony.SignalStrengthUpdateRequest;
126import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800127import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800128import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800129import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700130import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700131import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800132import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800133import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800134import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800135import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000136import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000137import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000138import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700139import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700140import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800141import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800142import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700143import android.telephony.gba.GbaAuthRequest;
144import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700145import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800146import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000147import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000148import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700149import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000150import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700151import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800152import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700153import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800154import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700155import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000156import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700157import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800158import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800159import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000160import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000161import android.telephony.satellite.ISatelliteCapabilitiesCallback;
youngtaecha5d483d52024-04-29 17:05:45 +0000162import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800163import android.telephony.satellite.ISatelliteDatagramCallback;
Duke Lee8852e512024-10-06 12:55:43 +0900164import android.telephony.satellite.ISatelliteDisallowedReasonsCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000165import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800166import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000167import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800168import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Daniel Banta93320242024-11-21 00:34:41 +0000169import android.telephony.satellite.ISelectedNbIotSatelliteSubscriptionCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000170import android.telephony.satellite.NtnSignalStrength;
171import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800172import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000173import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800174import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800175import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800176import android.telephony.satellite.SatelliteProvisionStateCallback;
Hyosun Kimb11f3ea2024-08-07 23:35:59 +0000177import android.telephony.satellite.SatelliteSubscriberInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700180import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800182import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800183
Andrew Lee312e8172014-10-23 17:01:36 -0700184import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800185import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800186import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800187import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800188import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700189import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700190import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700191import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800192import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800193import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700194import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800196import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700197import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800198import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800199import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800200import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700201import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000202import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700203import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800204import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800206import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800207import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800208import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700209import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700210import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700211import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700213import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800214import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700215import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700216import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700217import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700218import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800219import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800220import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700221import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000222import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700223import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700224import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800225import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800226import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800227import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700228import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000229import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800230import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700231import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700232import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800233import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700234import com.android.internal.telephony.imsphone.ImsPhone;
235import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000236import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800237import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000238import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800239import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
240import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700241import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242import com.android.internal.telephony.uicc.IccIoResult;
243import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800244import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700245import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800246import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700247import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000248import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800249import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000250import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800251import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000252import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700253import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700254import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800255import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800256import com.android.phone.callcomposer.CallComposerPictureManager;
257import com.android.phone.callcomposer.CallComposerPictureTransfer;
258import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800259import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000260import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700261import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700262import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000263import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700264import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800265import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700266import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700267import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800268import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800269import com.android.services.telephony.TelecomAccountRegistry;
270import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000271import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800272import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800273
Hall Liu82694d52020-12-11 18:22:04 -0800274import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700275import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800276import java.io.IOException;
277import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700278import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800280import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000281import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800282import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800283import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800284import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800285import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100286import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800287import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700288import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800289import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800290import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700291import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800292import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800293import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800294import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295
296/**
297 * Implementation of the ITelephony interface.
298 */
Santos Cordon117fee72014-05-16 17:56:12 -0700299public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300 private static final String LOG_TAG = "PhoneInterfaceManager";
301 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
302 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800303 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304
305 // Message codes used with mMainThreadHandler
306 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700307 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
308 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700309 private static final int CMD_OPEN_CHANNEL = 9;
310 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
311 private static final int CMD_CLOSE_CHANNEL = 11;
312 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800313 private static final int CMD_NV_READ_ITEM = 13;
314 private static final int EVENT_NV_READ_ITEM_DONE = 14;
315 private static final int CMD_NV_WRITE_ITEM = 15;
316 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
317 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
318 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700319 private static final int CMD_RESET_MODEM_CONFIG = 19;
320 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800321 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
322 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800323 private static final int CMD_SEND_ENVELOPE = 25;
324 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700325 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
326 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
327 private static final int CMD_EXCHANGE_SIM_IO = 31;
328 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800329 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
330 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700331 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
332 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700333 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
334 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700335 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
336 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
337 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
338 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700339 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
340 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
341 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
342 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700343 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800344 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
345 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000346 private static final int CMD_SWITCH_SLOTS = 50;
347 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700348 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
349 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
350 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
351 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
352 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
353 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
354 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
355 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700356 private static final int CMD_GET_ALL_CELL_INFO = 60;
357 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
358 private static final int CMD_GET_CELL_LOCATION = 62;
359 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700360 private static final int CMD_MODEM_REBOOT = 64;
361 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700362 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
363 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800364 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
365 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700366 private static final int CMD_GET_MODEM_STATUS = 70;
367 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700368 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
369 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700370 private static final int CMD_ERASE_MODEM_CONFIG = 74;
371 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800372 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
373 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
374 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
375 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800376 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
377 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800378 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800379 private static final int CMD_GET_CALL_FORWARDING = 83;
380 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
381 private static final int CMD_SET_CALL_FORWARDING = 85;
382 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
383 private static final int CMD_GET_CALL_WAITING = 87;
384 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
385 private static final int CMD_SET_CALL_WAITING = 89;
386 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700387 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
388 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
389 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
390 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700391 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
392 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800393 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
394 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800395 private static final int CMD_SET_DATA_THROTTLING = 99;
396 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800397 private static final int CMD_SET_SIM_POWER = 101;
398 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800399 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
400 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
401 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
402 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800403 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
404 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000405 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800406 private static final int CMD_GET_SLICING_CONFIG = 110;
407 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800408 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700409 private static final int CMD_ENABLE_VONR = 113;
410 private static final int EVENT_ENABLE_VONR_DONE = 114;
411 private static final int CMD_IS_VONR_ENABLED = 115;
412 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700413 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
414 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000415
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800416 // Parameters of select command.
417 private static final int SELECT_COMMAND = 0xA4;
418 private static final int SELECT_P1 = 0x04;
419 private static final int SELECT_P2 = 0;
420 private static final int SELECT_P3 = 0x10;
421
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000422 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
423 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000424 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
425 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600426 // Null cipher notification support was added in IRadioNetwork 2.2
427 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000428
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 /** The singleton instance. */
430 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800431 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432
Sarah Chin4beb2b72023-02-14 14:47:54 -0800433 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000434 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800435 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800436 private final CallManager mCM;
437 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000438
439 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800440 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800441 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800442 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800443 private final SharedPreferences mTelephonySharedPreferences;
444 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800445 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700446 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000447 private PackageManager mPackageManager;
joonhunshinf624b2a2024-04-18 04:42:12 +0000448 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449
Jack Yu26735292024-09-25 14:33:49 -0700450 @Nullable
451 private ComponentName mTestEuiccUiComponent;
452
Peter Wangdafb9ac2020-01-15 14:13:38 -0800453 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800454 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800455 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800456 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800457
Derek Tan97ebb422014-09-05 16:55:38 -0700458 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
459 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800460 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800461 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700462
Michelecea4cf22018-12-21 15:00:11 -0800463 // String to store multi SIM allowed
464 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
465
Derek Tan740e1672017-06-27 14:56:27 -0700466 // The AID of ISD-R.
467 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
468
yinxub1bed742017-04-17 11:45:04 -0700469 private NetworkScanRequestTracker mNetworkScanRequestTracker;
470
David Kelly5e06a7f2018-03-12 14:10:59 +0000471 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
472 private static final int MANUFACTURER_CODE_LENGTH = 8;
473
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800474 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800475 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800476
Sarah Chin2ec39f62022-08-31 17:03:26 -0700477 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
478 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
479
Derek Tan89e89d42014-07-08 17:00:10 -0700480 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700481 * Experiment flag to enable erase modem config on reset network, default value is false
482 */
483 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
484 "reset_network_erase_modem_config_enabled";
485
Nathan Harolddc3bcec2024-05-16 14:06:40 -0700486 private static final int BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800487
Gary Jian76280a42022-12-07 16:18:33 +0800488 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
489
arunvoddub1365e62024-07-31 09:42:31 +0000490 private static final int LINE1_NUMBER_MAX_LEN = 50;
491
sandeepjsb6c87872021-09-27 15:34:44 +0000492 /**
493 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
494 * one ICCID active at the same time.
495 * Apps should use below API signatures if targeting SDK is T and beyond.
496 *
497 * @hide
498 */
499 @ChangeId
500 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
501 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800502
Naina Nallurid63128d2019-09-17 14:10:30 -0700503 /**
Chen Xu540470b2021-12-14 17:15:47 -0800504 * Apps targeting on Android T and beyond will get exception whenever icc close channel
505 * operation fails.
506 */
507 @ChangeId
508 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
509 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
510
511 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700512 * A request object to use for transmitting data to an ICC.
513 */
514 private static final class IccAPDUArgument {
515 public int channel, cla, command, p1, p2, p3;
516 public String data;
517
518 public IccAPDUArgument(int channel, int cla, int command,
519 int p1, int p2, int p3, String data) {
520 this.channel = channel;
521 this.cla = cla;
522 this.command = command;
523 this.p1 = p1;
524 this.p2 = p2;
525 this.p3 = p3;
526 this.data = data;
527 }
528 }
529
530 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700531 * A request object to use for transmitting data to an ICC.
532 */
533 private static final class ManualNetworkSelectionArgument {
534 public OperatorInfo operatorInfo;
535 public boolean persistSelection;
536
537 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
538 this.operatorInfo = operatorInfo;
539 this.persistSelection = persistSelection;
540 }
541 }
542
Sarah Chin71b3a852022-09-28 15:54:19 -0700543 private static final class PurchasePremiumCapabilityArgument {
544 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700545 public @NonNull IIntegerConsumer callback;
546
547 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800548 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700549 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700550 this.callback = callback;
551 }
552 }
553
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700554 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700555 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
556 * request after sending. The main thread will notify the request when it is complete.
557 */
558 private static final class MainThreadRequest {
559 /** The argument to use for the request */
560 public Object argument;
561 /** The result of the request that is run on the main thread */
562 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800563 // The subscriber id that this request applies to. Defaults to
564 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
565 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700566
Nathan Harold92bed182018-10-12 18:16:49 -0700567 // In cases where subId is unavailable, the caller needs to specify the phone.
568 public Phone phone;
569
vagdeviaf9a5b92018-08-15 16:01:53 -0700570 public WorkSource workSource;
571
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700572 public MainThreadRequest(Object argument) {
573 this.argument = argument;
574 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800575
Nathan Harold92bed182018-10-12 18:16:49 -0700576 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
577 this.argument = argument;
578 if (phone != null) {
579 this.phone = phone;
580 }
581 this.workSource = workSource;
582 }
583
vagdeviaf9a5b92018-08-15 16:01:53 -0700584 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800585 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800586 if (subId != null) {
587 this.subId = subId;
588 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700589 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800590 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700591 }
592
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800593 private static final class IncomingThirdPartyCallArgs {
594 public final ComponentName component;
595 public final String callId;
596 public final String callerDisplayName;
597
598 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
599 String callerDisplayName) {
600 this.component = component;
601 this.callId = callId;
602 this.callerDisplayName = callerDisplayName;
603 }
604 }
605
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700606 /**
607 * A handler that processes messages on the main thread in the phone process. Since many
608 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
609 * inbound binder threads to the main thread in the phone process. The Binder thread
610 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
611 * on, which will be notified when the operation completes and will contain the result of the
612 * request.
613 *
614 * <p>If a MainThreadRequest object is provided in the msg.obj field,
615 * note that request.result must be set to something non-null for the calling thread to
616 * unblock.
617 */
618 private final class MainThreadHandler extends Handler {
619 @Override
620 public void handleMessage(Message msg) {
621 MainThreadRequest request;
622 Message onCompleted;
623 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000624 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800626 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700627
628 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 case CMD_HANDLE_USSD_REQUEST: {
630 request = (MainThreadRequest) msg.obj;
631 final Phone phone = getPhoneFromRequest(request);
632 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800633 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700635
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 if (!isUssdApiAllowed(request.subId)) {
637 // Carrier does not support use of this API, return failure.
638 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
639 UssdResponse response = new UssdResponse(ussdRequest, null);
640 Bundle returnData = new Bundle();
641 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
642 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700643
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 request.result = true;
645 notifyRequester(request);
646 return;
647 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700648
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 try {
650 request.result = phone != null
651 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
652 } catch (CallStateException cse) {
653 request.result = false;
654 }
655 // Wake up the requesting thread
656 notifyRequester(request);
657 break;
pkanwar32d516d2016-10-14 19:37:38 -0700658 }
659
Yorke Lee716f67e2015-06-17 15:39:16 -0700660 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700662 final Phone phone = getPhoneFromRequest(request);
663 request.result = phone != null ?
664 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
665 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700666 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700668 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700670
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000674 uiccPort = getUiccPortFromRequest(request);
675 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800677 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800681 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000682 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800683 iccArgument.channel, iccArgument.cla, iccArgument.command,
684 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
685 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 break;
688
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700689 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 ar = (AsyncResult) msg.obj;
691 request = (MainThreadRequest) ar.userObj;
692 if (ar.exception == null && ar.result != null) {
693 request.result = ar.result;
694 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800695 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 if (ar.result == null) {
697 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800698 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800700 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 } else {
702 loge("iccTransmitApduLogicalChannel: Unknown exception");
703 }
704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 break;
707
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
709 request = (MainThreadRequest) msg.obj;
710 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000711 uiccPort = getUiccPortFromRequest(request);
712 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700713 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800714 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700716 } else {
717 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800718 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000719 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800720 iccArgument.cla, iccArgument.command, iccArgument.p1,
721 iccArgument.p2,
722 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 }
724 break;
725
726 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
727 ar = (AsyncResult) msg.obj;
728 request = (MainThreadRequest) ar.userObj;
729 if (ar.exception == null && ar.result != null) {
730 request.result = ar.result;
731 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800732 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 if (ar.result == null) {
734 loge("iccTransmitApduBasicChannel: Empty response");
735 } else if (ar.exception instanceof CommandException) {
736 loge("iccTransmitApduBasicChannel: CommandException: " +
737 ar.exception);
738 } else {
739 loge("iccTransmitApduBasicChannel: Unknown exception");
740 }
741 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 break;
744
745 case CMD_EXCHANGE_SIM_IO:
746 request = (MainThreadRequest) msg.obj;
747 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000748 uiccPort = getUiccPortFromRequest(request);
749 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700750 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800751 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700752 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700753 } else {
754 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
755 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000756 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700757 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
758 iccArgument.data, onCompleted);
759 }
760 break;
761
762 case EVENT_EXCHANGE_SIM_IO_DONE:
763 ar = (AsyncResult) msg.obj;
764 request = (MainThreadRequest) ar.userObj;
765 if (ar.exception == null && ar.result != null) {
766 request.result = ar.result;
767 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800768 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700769 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700771 break;
772
Derek Tan4d5e5c12014-02-04 11:54:58 -0800773 case CMD_SEND_ENVELOPE:
774 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000775 uiccPort = getUiccPortFromRequest(request);
776 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700777 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800778 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700779 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700780 } else {
781 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800782 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700783 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800784 break;
785
786 case EVENT_SEND_ENVELOPE_DONE:
787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700789 if (ar.exception == null && ar.result != null) {
790 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800791 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800792 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700793 if (ar.result == null) {
794 loge("sendEnvelopeWithStatus: Empty response");
795 } else if (ar.exception instanceof CommandException) {
796 loge("sendEnvelopeWithStatus: CommandException: " +
797 ar.exception);
798 } else {
799 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
800 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800801 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700802 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800803 break;
804
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 case CMD_OPEN_CHANNEL:
806 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000807 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800808 IccLogicalChannelRequest openChannelRequest =
809 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000810 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700811 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800812 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800813 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700814 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700815 } else {
816 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800817 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
818 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700819 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700820 break;
821
822 case EVENT_OPEN_CHANNEL_DONE:
823 ar = (AsyncResult) msg.obj;
824 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700825 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700826 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700827 int[] result = (int[]) ar.result;
828 int channelId = result[0];
829 byte[] selectResponse = null;
830 if (result.length > 1) {
831 selectResponse = new byte[result.length - 1];
832 for (int i = 1; i < result.length; ++i) {
833 selectResponse[i - 1] = (byte) result[i];
834 }
835 }
836 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800837 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800838
839 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700840 if (uiccPort == null) {
841 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
842 } else {
843 IccLogicalChannelRequest channelRequest =
844 (IccLogicalChannelRequest) request.argument;
845 channelRequest.channel = channelId;
846 uiccPort.onLogicalChannelOpened(channelRequest);
847 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700849 if (ar.result == null) {
850 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700852 if (ar.exception != null) {
853 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
854 }
855
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700856 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700857 if (ar.exception instanceof CommandException) {
858 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800859 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700860 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700861 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700862 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700863 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700864 }
865 }
866 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800867 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700868 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700869 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700870 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700871 break;
872
873 case CMD_CLOSE_CHANNEL:
874 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000875 uiccPort = getUiccPortFromRequest(request);
876 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700877 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800878 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800879 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800880 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700881 } else {
882 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000883 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700884 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700885 break;
886
887 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800888 ar = (AsyncResult) msg.obj;
889 request = (MainThreadRequest) ar.userObj;
890 if (ar.exception == null) {
891 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800892 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700893 if (uiccPort == null) {
894 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
895 } else {
896 final int channelId = (Integer) request.argument;
897 uiccPort.onLogicalChannelClosed(channelId);
898 }
Chen Xu540470b2021-12-14 17:15:47 -0800899 } else {
900 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800901 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800902 if (ar.exception instanceof CommandException) {
903 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
904 CommandException.Error error =
905 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800906 if (error == CommandException.Error.INVALID_ARGUMENTS) {
907 // should only throw exceptions from the binder threads.
908 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800909 "iccCloseLogicalChannel: invalid argument ");
910 }
911 } else {
912 loge("iccCloseLogicalChannel: Unknown exception");
913 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800914 request.result = (exception != null) ? exception :
915 new IllegalStateException(
916 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800917 }
918 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800919 break;
920
921 case CMD_NV_READ_ITEM:
922 request = (MainThreadRequest) msg.obj;
923 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800924 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
925 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800926 break;
927
928 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700929 ar = (AsyncResult) msg.obj;
930 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800931 if (ar.exception == null && ar.result != null) {
932 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700933 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800934 request.result = "";
935 if (ar.result == null) {
936 loge("nvReadItem: Empty response");
937 } else if (ar.exception instanceof CommandException) {
938 loge("nvReadItem: CommandException: " +
939 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700940 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800941 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700942 }
943 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700944 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700945 break;
946
Jake Hambye994d462014-02-03 13:10:13 -0800947 case CMD_NV_WRITE_ITEM:
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
950 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800951 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700952 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800953 break;
954
955 case EVENT_NV_WRITE_ITEM_DONE:
956 handleNullReturnEvent(msg, "nvWriteItem");
957 break;
958
959 case CMD_NV_WRITE_CDMA_PRL:
960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800962 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800963 break;
964
965 case EVENT_NV_WRITE_CDMA_PRL_DONE:
966 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
967 break;
968
chen xu6dac5ab2018-10-26 17:39:23 -0700969 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800970 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700971 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800972 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800973 break;
974
chen xu6dac5ab2018-10-26 17:39:23 -0700975 case EVENT_RESET_MODEM_CONFIG_DONE:
976 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800977 break;
978
Sooraj Sasindran37444802020-08-11 10:40:43 -0700979 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
980 request = (MainThreadRequest) msg.obj;
981 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
982 request);
983 Phone phone = getPhoneFromRequest(request);
984 if (phone != null) {
985 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
986 } else {
987 loge("isNRDualConnectivityEnabled: No phone object");
988 request.result = false;
989 notifyRequester(request);
990 }
991 break;
992 }
993
994 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 if (ar.exception == null && ar.result != null) {
998 request.result = ar.result;
999 } else {
1000 // request.result must be set to something non-null
1001 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001002 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001003 request.result = ar.result;
1004 } else {
1005 request.result = false;
1006 }
1007 if (ar.result == null) {
1008 loge("isNRDualConnectivityEnabled: Empty response");
1009 } else if (ar.exception instanceof CommandException) {
1010 loge("isNRDualConnectivityEnabled: CommandException: "
1011 + ar.exception);
1012 } else {
1013 loge("isNRDualConnectivityEnabled: Unknown exception");
1014 }
1015 }
1016 notifyRequester(request);
1017 break;
1018
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001019 case CMD_IS_VONR_ENABLED: {
1020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1022 request);
1023 Phone phone = getPhoneFromRequest(request);
1024 if (phone != null) {
1025 phone.isVoNrEnabled(onCompleted, request.workSource);
1026 } else {
1027 loge("isVoNrEnabled: No phone object");
1028 request.result = false;
1029 notifyRequester(request);
1030 }
1031 break;
1032 }
1033
1034 case EVENT_IS_VONR_ENABLED_DONE:
1035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
1037 if (ar.exception == null && ar.result != null) {
1038 request.result = ar.result;
1039 } else {
1040 // request.result must be set to something non-null
1041 // for the calling thread to unblock
1042 if (ar.result != null) {
1043 request.result = ar.result;
1044 } else {
1045 request.result = false;
1046 }
1047 if (ar.result == null) {
1048 loge("isVoNrEnabled: Empty response");
1049 } else if (ar.exception instanceof CommandException) {
1050 loge("isVoNrEnabled: CommandException: "
1051 + ar.exception);
1052 } else {
1053 loge("isVoNrEnabled: Unknown exception");
1054 }
1055 }
1056 notifyRequester(request);
1057 break;
1058
Sooraj Sasindran37444802020-08-11 10:40:43 -07001059 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1060 request = (MainThreadRequest) msg.obj;
1061 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1062 Phone phone = getPhoneFromRequest(request);
1063 if (phone != null) {
1064 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1065 request.workSource);
1066 } else {
1067 loge("enableNrDualConnectivity: No phone object");
1068 request.result =
1069 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1070 notifyRequester(request);
1071 }
1072 break;
1073 }
1074
1075 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1076 ar = (AsyncResult) msg.obj;
1077 request = (MainThreadRequest) ar.userObj;
1078 if (ar.exception == null) {
1079 request.result =
1080 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1081 } else {
1082 request.result =
1083 TelephonyManager
1084 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1085 if (ar.exception instanceof CommandException) {
1086 CommandException.Error error =
1087 ((CommandException) (ar.exception)).getCommandError();
1088 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1089 request.result =
1090 TelephonyManager
1091 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001092 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1093 request.result =
1094 TelephonyManager
1095 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001096 }
1097 loge("enableNrDualConnectivity" + ": CommandException: "
1098 + ar.exception);
1099 } else {
1100 loge("enableNrDualConnectivity" + ": Unknown exception");
1101 }
1102 }
1103 notifyRequester(request);
1104 break;
1105 }
1106
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001107 case CMD_ENABLE_VONR: {
1108 request = (MainThreadRequest) msg.obj;
1109 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1110 Phone phone = getPhoneFromRequest(request);
1111 if (phone != null) {
1112 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1113 request.workSource);
1114 } else {
1115 loge("setVoNrEnabled: No phone object");
1116 request.result =
1117 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1118 notifyRequester(request);
1119 }
1120 break;
1121 }
1122
1123 case EVENT_ENABLE_VONR_DONE: {
1124 ar = (AsyncResult) msg.obj;
1125 request = (MainThreadRequest) ar.userObj;
1126 if (ar.exception == null) {
1127 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1128 } else {
1129 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1130 if (ar.exception instanceof CommandException) {
1131 CommandException.Error error =
1132 ((CommandException) (ar.exception)).getCommandError();
1133 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1134 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1135 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1136 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1137 } else {
1138 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1139 }
1140 loge("setVoNrEnabled" + ": CommandException: "
1141 + ar.exception);
1142 } else {
1143 loge("setVoNrEnabled" + ": Unknown exception");
1144 }
1145 }
1146 notifyRequester(request);
1147 break;
1148 }
1149
SongFerngWang3ef3e072020-12-21 16:41:52 +08001150 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001151 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001152 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1153 request);
1154 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001155 break;
1156
SongFerngWang3ef3e072020-12-21 16:41:52 +08001157 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 ar = (AsyncResult) msg.obj;
1159 request = (MainThreadRequest) ar.userObj;
1160 if (ar.exception == null && ar.result != null) {
1161 request.result = ar.result; // Integer
1162 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301163 // request.result must be set to something non-null
1164 // for the calling thread to unblock
1165 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001166 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001167 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001168 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001169 loge("getAllowedNetworkTypesBitmask: CommandException: "
1170 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001171 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001172 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001173 }
1174 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001175 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001176 break;
1177
SongFerngWang3ef3e072020-12-21 16:41:52 +08001178 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001179 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001180 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1181 request);
1182 Pair<Integer, Long> reasonWithNetworkTypes =
1183 (Pair<Integer, Long>) request.argument;
1184 getPhoneFromRequest(request).setAllowedNetworkTypes(
1185 reasonWithNetworkTypes.first,
1186 reasonWithNetworkTypes.second,
1187 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001188 break;
1189
SongFerngWang3ef3e072020-12-21 16:41:52 +08001190 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1191 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001192 break;
1193
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001194 case CMD_SET_VOICEMAIL_NUMBER:
1195 request = (MainThreadRequest) msg.obj;
1196 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1197 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001198 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1199 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001200 break;
1201
1202 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1203 handleNullReturnEvent(msg, "setVoicemailNumber");
1204 break;
1205
Stuart Scott54788802015-03-30 13:18:01 -07001206 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1207 request = (MainThreadRequest) msg.obj;
1208 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1209 request);
1210 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1211 break;
1212
1213 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1214 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1215 break;
1216
Shishir Agrawal302c8692015-06-19 13:49:39 -07001217 case CMD_PERFORM_NETWORK_SCAN:
1218 request = (MainThreadRequest) msg.obj;
1219 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1220 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1221 break;
1222
Hall Liu27d24262020-09-18 19:04:59 -07001223 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001224 request = (MainThreadRequest) msg.obj;
1225 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001226 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1227 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1228 request.argument;
1229 int callForwardingReason = args.first;
1230 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001231 break;
Hall Liu27d24262020-09-18 19:04:59 -07001232 }
1233 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001234 ar = (AsyncResult) msg.obj;
1235 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001236 TelephonyManager.CallForwardingInfoCallback callback =
1237 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1238 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001239 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001240 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001241 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1242 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1243 // Service Class is a bit mask per 3gpp 27.007. Search for
1244 // any service for voice call.
1245 if ((callForwardInfo.serviceClass
1246 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001247 callForwardingInfo = new CallForwardingInfo(
1248 callForwardInfo.status
1249 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001250 callForwardInfo.reason,
1251 callForwardInfo.number,
1252 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001253 break;
1254 }
1255 }
1256 // Didn't find a call forward info for voice call.
1257 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001258 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1259 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001260 }
Hall Liu27d24262020-09-18 19:04:59 -07001261 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001262 } else {
1263 if (ar.result == null) {
1264 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1265 }
1266 if (ar.exception != null) {
1267 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1268 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001269 int errorCode = TelephonyManager
1270 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001271 if (ar.exception instanceof CommandException) {
1272 CommandException.Error error =
1273 ((CommandException) (ar.exception)).getCommandError();
1274 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001275 errorCode = TelephonyManager
1276 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001277 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001278 errorCode = TelephonyManager
1279 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001280 }
1281 }
Hall Liu27d24262020-09-18 19:04:59 -07001282 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001283 }
Shuo Qian4a594052020-01-23 11:59:30 -08001284 break;
Hall Liu27d24262020-09-18 19:04:59 -07001285 }
Shuo Qian4a594052020-01-23 11:59:30 -08001286
Hall Liu27d24262020-09-18 19:04:59 -07001287 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001288 request = (MainThreadRequest) msg.obj;
1289 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001290 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001291 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001292 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1293 request.argument).first;
1294 request.phone.setCallForwardingOption(
1295 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001296 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001297 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001298 callForwardingInfoToSet.getReason(),
1299 callForwardingInfoToSet.getNumber(),
1300 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1301 break;
Hall Liu27d24262020-09-18 19:04:59 -07001302 }
Shuo Qian4a594052020-01-23 11:59:30 -08001303
Hall Liu27d24262020-09-18 19:04:59 -07001304 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001305 ar = (AsyncResult) msg.obj;
1306 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001307 Consumer<Integer> callback =
1308 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1309 request.argument).second;
1310 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001311 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001312 int errorCode = TelephonyManager.CallForwardingInfoCallback
1313 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001314 if (ar.exception instanceof CommandException) {
1315 CommandException.Error error =
1316 ((CommandException) (ar.exception)).getCommandError();
1317 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001318 errorCode = TelephonyManager.CallForwardingInfoCallback
1319 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001320 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001321 errorCode = TelephonyManager.CallForwardingInfoCallback
1322 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001323 }
1324 }
1325 callback.accept(errorCode);
1326 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001327 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001328 }
Shuo Qian4a594052020-01-23 11:59:30 -08001329 break;
Hall Liu27d24262020-09-18 19:04:59 -07001330 }
Shuo Qian4a594052020-01-23 11:59:30 -08001331
Hall Liu27d24262020-09-18 19:04:59 -07001332 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001333 request = (MainThreadRequest) msg.obj;
1334 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1335 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1336 break;
Hall Liu27d24262020-09-18 19:04:59 -07001337 }
Shuo Qian4a594052020-01-23 11:59:30 -08001338
Hall Liu27d24262020-09-18 19:04:59 -07001339 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001340 ar = (AsyncResult) msg.obj;
1341 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001342 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001343 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001344 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001345 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001346 // Service Class is a bit mask per 3gpp 27.007.
1347 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001348 if (callForwardResults.length > 1
1349 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001350 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001351 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001352 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1353 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001354 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001355 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001356 }
1357 } else {
1358 if (ar.result == null) {
1359 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1360 }
1361 if (ar.exception != null) {
1362 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1363 }
1364 if (ar.exception instanceof CommandException) {
1365 CommandException.Error error =
1366 ((CommandException) (ar.exception)).getCommandError();
1367 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001368 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001369 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001370 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1371 callWaitingStatus =
1372 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001373 }
1374 }
1375 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001376 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001377 break;
Hall Liu27d24262020-09-18 19:04:59 -07001378 }
Shuo Qian4a594052020-01-23 11:59:30 -08001379
Hall Liu27d24262020-09-18 19:04:59 -07001380 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001381 request = (MainThreadRequest) msg.obj;
1382 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001383 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1384 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001385 break;
Hall Liu27d24262020-09-18 19:04:59 -07001386 }
Shuo Qian4a594052020-01-23 11:59:30 -08001387
Hall Liu27d24262020-09-18 19:04:59 -07001388 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001389 ar = (AsyncResult) msg.obj;
1390 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001391 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1392 Consumer<Integer> callback =
1393 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1394 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001395 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001396 if (ar.exception instanceof CommandException) {
1397 CommandException.Error error =
1398 ((CommandException) (ar.exception)).getCommandError();
1399 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1400 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001401 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1402 callback.accept(
1403 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001404 } else {
1405 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1406 }
1407 } else {
1408 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1409 }
1410 } else {
1411 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1412 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001413 }
Shuo Qian4a594052020-01-23 11:59:30 -08001414 break;
Hall Liu27d24262020-09-18 19:04:59 -07001415 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001416 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1417 ar = (AsyncResult) msg.obj;
1418 request = (MainThreadRequest) ar.userObj;
1419 CellNetworkScanResult cellScanResult;
1420 if (ar.exception == null && ar.result != null) {
1421 cellScanResult = new CellNetworkScanResult(
1422 CellNetworkScanResult.STATUS_SUCCESS,
1423 (List<OperatorInfo>) ar.result);
1424 } else {
1425 if (ar.result == null) {
1426 loge("getCellNetworkScanResults: Empty response");
1427 }
1428 if (ar.exception != null) {
1429 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1430 }
1431 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1432 if (ar.exception instanceof CommandException) {
1433 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001434 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001435 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1436 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1437 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1438 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1439 }
1440 }
1441 cellScanResult = new CellNetworkScanResult(errorCode, null);
1442 }
1443 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001444 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001445 break;
1446
1447 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1448 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001449 ManualNetworkSelectionArgument selArg =
1450 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001451 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1452 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001453 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1454 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001455 break;
1456
1457 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001458 ar = (AsyncResult) msg.obj;
1459 request = (MainThreadRequest) ar.userObj;
1460 if (ar.exception == null) {
1461 request.result = true;
1462 } else {
1463 request.result = false;
1464 loge("setNetworkSelectionModeManual " + ar.exception);
1465 }
1466 notifyRequester(request);
1467 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001468 break;
1469
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001470 case CMD_GET_MODEM_ACTIVITY_INFO:
1471 request = (MainThreadRequest) msg.obj;
1472 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001473 if (defaultPhone != null) {
1474 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001475 } else {
1476 ResultReceiver result = (ResultReceiver) request.argument;
1477 Bundle bundle = new Bundle();
1478 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001479 new ModemActivityInfo(0, 0, 0,
1480 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001481 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001482 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001483 break;
1484
Hall Liud0f208c2020-10-14 16:54:44 -07001485 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001486 ar = (AsyncResult) msg.obj;
1487 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001488 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001489 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001490 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001491 if (mLastModemActivityInfo == null) {
1492 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1493 mLastModemActivitySpecificInfo[0] =
1494 new ActivityStatsTechSpecificInfo(
1495 0,
1496 0,
1497 new int[ModemActivityInfo.getNumTxPowerLevels()],
1498 0);
1499 mLastModemActivityInfo =
1500 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1501 }
1502
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001503 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001504 // Update the last modem activity info and the result of the request.
1505 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1506 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001507 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001508 } else {
1509 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001510 }
Kai Shi917fdc62022-11-28 14:01:02 -08001511 // This is needed to decouple ret from mLastModemActivityInfo
1512 // We don't want to return mLastModemActivityInfo which is updated
1513 // inside mergeModemActivityInfo()
1514 ret = new ModemActivityInfo(
1515 mLastModemActivityInfo.getTimestampMillis(),
1516 mLastModemActivityInfo.getSleepTimeMillis(),
1517 mLastModemActivityInfo.getIdleTimeMillis(),
1518 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001519
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001520 } else {
1521 if (ar.result == null) {
1522 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001523 error = TelephonyManager.ModemActivityInfoException
1524 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001525 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001526 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001527 error = TelephonyManager.ModemActivityInfoException
1528 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001529 } else {
1530 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001531 error = TelephonyManager.ModemActivityInfoException
1532 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001533 }
1534 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001535 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001536 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001537 bundle.putParcelable(
1538 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001539 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001540 } else {
1541 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1542 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001543 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001544 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001545 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001546 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001547
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001548 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001549 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001550 CarrierRestrictionRules argument =
1551 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001552 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001553 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001554 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001555 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001556
1557 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1558 ar = (AsyncResult) msg.obj;
1559 request = (MainThreadRequest) ar.userObj;
1560 if (ar.exception == null && ar.result != null) {
1561 request.result = ar.result;
1562 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001563 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1564 if (ar.exception instanceof CommandException) {
1565 loge("setAllowedCarriers: CommandException: " + ar.exception);
1566 CommandException.Error error =
1567 ((CommandException) (ar.exception)).getCommandError();
1568 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1569 request.result =
1570 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1571 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001572 } else {
1573 loge("setAllowedCarriers: Unknown exception");
1574 }
1575 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001576 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001577 break;
1578
1579 case CMD_GET_ALLOWED_CARRIERS:
1580 request = (MainThreadRequest) msg.obj;
1581 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001582 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001583 break;
1584
1585 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1586 ar = (AsyncResult) msg.obj;
1587 request = (MainThreadRequest) ar.userObj;
1588 if (ar.exception == null && ar.result != null) {
1589 request.result = ar.result;
1590 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001591 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001592 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001593 if (ar.result == null) {
1594 loge("getAllowedCarriers: Empty response");
1595 } else if (ar.exception instanceof CommandException) {
1596 loge("getAllowedCarriers: CommandException: " +
1597 ar.exception);
1598 } else {
1599 loge("getAllowedCarriers: Unknown exception");
1600 }
1601 }
arunvoddud7401012022-12-15 16:08:12 +00001602 if (request.argument != null) {
1603 // This is for the implementation of carrierRestrictionStatus.
1604 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1605 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001606 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001607 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1608 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1609 CarrierRestrictionRules carrierRestrictionRules =
1610 (CarrierRestrictionRules) ar.result;
1611 int carrierId = -1;
1612 try {
1613 CarrierIdentifier carrierIdentifier =
1614 carrierRestrictionRules.getAllowedCarriers().get(0);
1615 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1616 carrierIdentifier);
1617 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1618 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1619 }
1620 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001621 int restrictedStatus =
1622 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1623 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1624 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001625 lockStatus = TelephonyManager
1626 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001627 }
1628 } else {
1629 Rlog.e(LOG_TAG,
1630 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1631 }
1632 callback.accept(lockStatus);
1633 } else {
1634 // This is for the implementation of getAllowedCarriers.
1635 notifyRequester(request);
1636 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001637 break;
1638
Nathan Haroldb3014052017-01-25 15:57:32 -08001639 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1640 ar = (AsyncResult) msg.obj;
1641 request = (MainThreadRequest) ar.userObj;
1642 if (ar.exception == null && ar.result != null) {
1643 request.result = ar.result;
1644 } else {
1645 request.result = new IllegalArgumentException(
1646 "Failed to retrieve Forbidden Plmns");
1647 if (ar.result == null) {
1648 loge("getForbiddenPlmns: Empty response");
1649 } else {
1650 loge("getForbiddenPlmns: Unknown exception");
1651 }
1652 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001653 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001654 break;
1655
1656 case CMD_GET_FORBIDDEN_PLMNS:
1657 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001658 uiccPort = getUiccPortFromRequest(request);
1659 if (uiccPort == null) {
1660 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001661 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001662 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001663 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001664 break;
1665 }
1666 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001667 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001668 if (uiccApp == null) {
1669 loge("getForbiddenPlmns() no app with specified type -- "
1670 + appType);
1671 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001672 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001673 break;
1674 } else {
1675 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1676 + " specified type -- " + appType);
1677 }
1678 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1679 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001680 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001681 break;
1682
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001683 case CMD_SWITCH_SLOTS:
1684 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001685 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001686 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001687 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001688 break;
1689
1690 case EVENT_SWITCH_SLOTS_DONE:
1691 ar = (AsyncResult) msg.obj;
1692 request = (MainThreadRequest) ar.userObj;
1693 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001694 notifyRequester(request);
1695 break;
1696 case CMD_GET_NETWORK_SELECTION_MODE:
1697 request = (MainThreadRequest) msg.obj;
1698 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1699 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1700 break;
1701
1702 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
1705 if (ar.exception != null) {
1706 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1707 } else {
1708 int mode = ((int[]) ar.result)[0];
1709 if (mode == 0) {
1710 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1711 } else {
1712 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1713 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001714 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001715 notifyRequester(request);
1716 break;
1717 case CMD_GET_CDMA_ROAMING_MODE:
1718 request = (MainThreadRequest) msg.obj;
1719 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1720 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1721 break;
1722 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1723 ar = (AsyncResult) msg.obj;
1724 request = (MainThreadRequest) ar.userObj;
1725 if (ar.exception != null) {
1726 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1727 } else {
1728 request.result = ((int[]) ar.result)[0];
1729 }
1730 notifyRequester(request);
1731 break;
1732 case CMD_SET_CDMA_ROAMING_MODE:
1733 request = (MainThreadRequest) msg.obj;
1734 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1735 int mode = (int) request.argument;
1736 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1737 break;
1738 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1739 ar = (AsyncResult) msg.obj;
1740 request = (MainThreadRequest) ar.userObj;
1741 request.result = ar.exception == null;
1742 notifyRequester(request);
1743 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001744 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1745 request = (MainThreadRequest) msg.obj;
1746 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1747 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1748 break;
1749 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1750 ar = (AsyncResult) msg.obj;
1751 request = (MainThreadRequest) ar.userObj;
1752 if (ar.exception != null) {
1753 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1754 } else {
1755 request.result = ((int[]) ar.result)[0];
1756 }
1757 notifyRequester(request);
1758 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001759 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1760 request = (MainThreadRequest) msg.obj;
1761 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1762 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001763 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1764 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001765 break;
1766 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1767 ar = (AsyncResult) msg.obj;
1768 request = (MainThreadRequest) ar.userObj;
1769 request.result = ar.exception == null;
1770 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001771 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001772 case CMD_GET_ALL_CELL_INFO:
1773 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001774 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001775 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001776 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001777 case EVENT_GET_ALL_CELL_INFO_DONE:
1778 ar = (AsyncResult) msg.obj;
1779 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001780 // If a timeout occurs, the response will be null
1781 request.result = (ar.exception == null && ar.result != null)
1782 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001783 synchronized (request) {
1784 request.notifyAll();
1785 }
1786 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001787 case CMD_REQUEST_CELL_INFO_UPDATE:
1788 request = (MainThreadRequest) msg.obj;
1789 request.phone.requestCellInfoUpdate(request.workSource,
1790 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1791 break;
1792 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1793 ar = (AsyncResult) msg.obj;
1794 request = (MainThreadRequest) ar.userObj;
1795 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1796 try {
1797 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001798 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001799 cb.onError(
1800 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1801 ar.exception.getClass().getName(),
1802 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001803 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001804 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001805 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001806 } else {
1807 // use the result as returned
1808 cb.onCellInfo((List<CellInfo>) ar.result);
1809 }
1810 } catch (RemoteException re) {
1811 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1812 }
1813 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001814 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001815 request = (MainThreadRequest) msg.obj;
1816 WorkSource ws = (WorkSource) request.argument;
1817 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001818 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001819 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001820 }
1821 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001822 ar = (AsyncResult) msg.obj;
1823 request = (MainThreadRequest) ar.userObj;
1824 if (ar.exception == null) {
1825 request.result = ar.result;
1826 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001827 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001828 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001829 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001830 }
1831
1832 synchronized (request) {
1833 request.notifyAll();
1834 }
1835 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001836 }
chen xu6dac5ab2018-10-26 17:39:23 -07001837 case CMD_MODEM_REBOOT:
1838 request = (MainThreadRequest) msg.obj;
1839 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001840 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001841 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001842 case EVENT_CMD_MODEM_REBOOT_DONE:
1843 handleNullReturnEvent(msg, "rebootModem");
1844 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001845 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001846 request = (MainThreadRequest) msg.obj;
1847 boolean enable = (boolean) request.argument;
1848 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001849 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001850 PhoneConfigurationManager.getInstance()
1851 .enablePhone(request.phone, enable, onCompleted);
1852 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001853 }
Michele Berionne5e411512020-11-13 02:36:59 +00001854 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001855 ar = (AsyncResult) msg.obj;
1856 request = (MainThreadRequest) ar.userObj;
1857 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001858 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001859 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001860 if ((boolean) request.result) {
1861 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1862 updateModemStateMetrics();
1863 } else {
1864 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1865 + ar.exception);
1866 }
1867 notifyRequester(request);
1868 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001869 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001870 case CMD_GET_MODEM_STATUS:
1871 request = (MainThreadRequest) msg.obj;
1872 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1873 PhoneConfigurationManager.getInstance()
1874 .getPhoneStatusFromModem(request.phone, onCompleted);
1875 break;
1876 case EVENT_GET_MODEM_STATUS_DONE:
1877 ar = (AsyncResult) msg.obj;
1878 request = (MainThreadRequest) ar.userObj;
1879 int id = request.phone.getPhoneId();
1880 if (ar.exception == null && ar.result != null) {
1881 request.result = ar.result;
1882 //update the cache as modem status has changed
1883 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1884 (boolean) request.result);
1885 } else {
1886 // Return true if modem status cannot be retrieved. For most cases,
1887 // modem status is on. And for older version modems, GET_MODEM_STATUS
1888 // and disable modem are not supported. Modem is always on.
1889 // TODO: this should be fixed in R to support a third
1890 // status UNKNOWN b/131631629
1891 request.result = true;
1892 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1893 + ar.exception);
1894 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001895 notifyRequester(request);
1896 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001897 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1898 request = (MainThreadRequest) msg.obj;
1899 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1900 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1901 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1902 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1903 break;
1904 }
1905 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1906 ar = (AsyncResult) msg.obj;
1907 request = (MainThreadRequest) ar.userObj;
1908 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1909 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1910 args.second.accept(ar.exception == null);
1911 notifyRequester(request);
1912 break;
1913 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001914 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1915 request = (MainThreadRequest) msg.obj;
1916 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1917 Phone phone = getPhoneFromRequest(request);
1918 if (phone != null) {
1919 phone.getSystemSelectionChannels(onCompleted);
1920 } else {
1921 loge("getSystemSelectionChannels: No phone object");
1922 request.result = new ArrayList<RadioAccessSpecifier>();
1923 notifyRequester(request);
1924 }
1925 break;
1926 }
1927 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1928 ar = (AsyncResult) msg.obj;
1929 request = (MainThreadRequest) ar.userObj;
1930 if (ar.exception == null && ar.result != null) {
1931 request.result = ar.result;
1932 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001933 request.result = new IllegalStateException(
1934 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001935 if (ar.result == null) {
1936 loge("getSystemSelectionChannels: Empty response");
1937 } else {
1938 loge("getSystemSelectionChannels: Unknown exception");
1939 }
1940 }
1941 notifyRequester(request);
1942 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001943 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1944 ar = (AsyncResult) msg.obj;
1945 request = (MainThreadRequest) ar.userObj;
1946 if (ar.exception == null && ar.result != null) {
1947 request.result = ar.result;
1948 } else {
1949 request.result = -1;
1950 loge("Failed to set Forbidden Plmns");
1951 if (ar.result == null) {
1952 loge("setForbidenPlmns: Empty response");
1953 } else if (ar.exception != null) {
1954 loge("setForbiddenPlmns: Exception: " + ar.exception);
1955 request.result = -1;
1956 } else {
1957 loge("setForbiddenPlmns: Unknown exception");
1958 }
1959 }
1960 notifyRequester(request);
1961 break;
1962 case CMD_SET_FORBIDDEN_PLMNS:
1963 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001964 uiccPort = getUiccPortFromRequest(request);
1965 if (uiccPort == null) {
1966 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001967 request.result = -1;
1968 notifyRequester(request);
1969 break;
1970 }
1971 Pair<Integer, List<String>> setFplmnsArgs =
1972 (Pair<Integer, List<String>>) request.argument;
1973 appType = setFplmnsArgs.first;
1974 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001975 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001976 if (uiccApp == null) {
1977 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1978 request.result = -1;
1979 loge("Failed to get UICC App");
1980 notifyRequester(request);
1981 } else {
1982 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1983 ((SIMRecords) uiccApp.getIccRecords())
1984 .setForbiddenPlmns(onCompleted, fplmns);
1985 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001986 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001987 case CMD_ERASE_MODEM_CONFIG:
1988 request = (MainThreadRequest) msg.obj;
1989 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1990 defaultPhone.eraseModemConfig(onCompleted);
1991 break;
1992 case EVENT_ERASE_MODEM_CONFIG_DONE:
1993 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001994 break;
zoey chene02881a2019-12-30 16:11:23 +08001995
Kai Shif70f46f2021-03-03 13:59:46 -08001996 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1997 request = (MainThreadRequest) msg.obj;
1998 request.result = defaultPhone.eraseDataInSharedPreferences();
1999 notifyRequester(request);
2000 break;
2001
zoey chene02881a2019-12-30 16:11:23 +08002002 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2003 request = (MainThreadRequest) msg.obj;
2004 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2005 Pair<String, String> changed = (Pair<String, String>) request.argument;
2006 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2007 changed.first, changed.second, onCompleted);
2008 break;
2009 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2010 ar = (AsyncResult) msg.obj;
2011 request = (MainThreadRequest) ar.userObj;
2012 if (ar.exception == null) {
2013 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002014 // If the operation is successful, update the PIN storage
2015 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2016 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002017 UiccController.getInstance().getPinStorage()
2018 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002019 } else {
2020 request.result = msg.arg1;
2021 }
2022 notifyRequester(request);
2023 break;
2024
Michele Berionne5e411512020-11-13 02:36:59 +00002025 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002026 request = (MainThreadRequest) msg.obj;
2027 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2028 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2029 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2030 enabled.first, enabled.second, onCompleted);
2031 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002032 }
zoey chene02881a2019-12-30 16:11:23 +08002033 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2034 ar = (AsyncResult) msg.obj;
2035 request = (MainThreadRequest) ar.userObj;
2036 if (ar.exception == null) {
2037 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002038 // If the operation is successful, update the PIN storage
2039 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2040 int phoneId = getPhoneFromRequest(request).getPhoneId();
2041 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002042 UiccController.getInstance().getPinStorage()
2043 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002044 } else {
2045 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2046 }
zoey chene02881a2019-12-30 16:11:23 +08002047 } else {
2048 request.result = msg.arg1;
2049 }
Michele Berionne5e411512020-11-13 02:36:59 +00002050
2051
zoey chene02881a2019-12-30 16:11:23 +08002052 notifyRequester(request);
2053 break;
2054
Peter Wangdafb9ac2020-01-15 14:13:38 -08002055 case MSG_NOTIFY_USER_ACTIVITY:
2056 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002057 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002058 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2059 getDefaultPhone().getContext().sendBroadcastAsUser(
2060 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2061 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002062
2063 case CMD_SET_DATA_THROTTLING: {
2064 request = (MainThreadRequest) msg.obj;
2065 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2066 DataThrottlingRequest dataThrottlingRequest =
2067 (DataThrottlingRequest) request.argument;
2068 Phone phone = getPhoneFromRequest(request);
2069 if (phone != null) {
2070 phone.setDataThrottling(onCompleted,
2071 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2072 dataThrottlingRequest.getCompletionDurationMillis());
2073 } else {
2074 loge("setDataThrottling: No phone object");
2075 request.result =
2076 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2077 notifyRequester(request);
2078 }
2079
2080 break;
2081 }
2082 case EVENT_SET_DATA_THROTTLING_DONE:
2083 ar = (AsyncResult) msg.obj;
2084 request = (MainThreadRequest) ar.userObj;
2085
2086 if (ar.exception == null) {
2087 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2088 } else if (ar.exception instanceof CommandException) {
2089 loge("setDataThrottling: CommandException: " + ar.exception);
2090 CommandException.Error error =
2091 ((CommandException) (ar.exception)).getCommandError();
2092
2093 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2094 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002095 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002096 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2097 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002098 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2099 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002100 } else {
2101 request.result =
2102 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2103 }
2104 } else {
2105 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2106 }
2107 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2108 notifyRequester(request);
2109 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002110
2111 case CMD_SET_SIM_POWER: {
2112 request = (MainThreadRequest) msg.obj;
2113 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2114 request = (MainThreadRequest) msg.obj;
2115 int stateToSet =
2116 ((Pair<Integer, IIntegerConsumer>)
2117 request.argument).first;
2118 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2119 break;
2120 }
2121 case EVENT_SET_SIM_POWER_DONE: {
2122 ar = (AsyncResult) msg.obj;
2123 request = (MainThreadRequest) ar.userObj;
2124 IIntegerConsumer callback =
2125 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2126 if (ar.exception != null) {
2127 loge("setSimPower exception: " + ar.exception);
2128 int errorCode = TelephonyManager.CallForwardingInfoCallback
2129 .RESULT_ERROR_UNKNOWN;
2130 if (ar.exception instanceof CommandException) {
2131 CommandException.Error error =
2132 ((CommandException) (ar.exception)).getCommandError();
2133 if (error == CommandException.Error.SIM_ERR) {
2134 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2135 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2136 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2137 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2138 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2139 } else {
2140 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2141 }
2142 }
2143 try {
2144 callback.accept(errorCode);
2145 } catch (RemoteException e) {
2146 // Ignore if the remote process is no longer available to call back.
2147 Log.w(LOG_TAG, "setSimPower: callback not available.");
2148 }
2149 } else {
2150 try {
2151 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2152 } catch (RemoteException e) {
2153 // Ignore if the remote process is no longer available to call back.
2154 Log.w(LOG_TAG, "setSimPower: callback not available.");
2155 }
2156 }
2157 break;
2158 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002159 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2160 request = (MainThreadRequest) msg.obj;
2161
2162 final Phone phone = getPhoneFromRequest(request);
2163 if (phone == null || phone.getServiceStateTracker() == null) {
2164 request.result = new IllegalStateException("Phone or SST is null");
2165 notifyRequester(request);
2166 break;
2167 }
2168
2169 Pair<Integer, SignalStrengthUpdateRequest> pair =
2170 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2171 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2172 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002173 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002174 request.subId, pair.first /*callingUid*/,
2175 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002176 break;
2177 }
2178 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2179 ar = (AsyncResult) msg.obj;
2180 request = (MainThreadRequest) ar.userObj;
2181 // request.result will be the exception of ar if present, true otherwise.
2182 // Be cautious not to leave result null which will wait() forever
2183 request.result = ar.exception != null ? ar.exception : true;
2184 notifyRequester(request);
2185 break;
2186 }
2187 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2188 request = (MainThreadRequest) msg.obj;
2189
2190 Phone phone = getPhoneFromRequest(request);
2191 if (phone == null || phone.getServiceStateTracker() == null) {
2192 request.result = new IllegalStateException("Phone or SST is null");
2193 notifyRequester(request);
2194 break;
2195 }
2196
2197 Pair<Integer, SignalStrengthUpdateRequest> pair =
2198 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2199 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2200 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002201 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002202 request.subId, pair.first /*callingUid*/,
2203 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002204 break;
2205 }
2206 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2207 ar = (AsyncResult) msg.obj;
2208 request = (MainThreadRequest) ar.userObj;
2209 request.result = ar.exception != null ? ar.exception : true;
2210 notifyRequester(request);
2211 break;
2212 }
Jordan Liu109698e2020-11-24 14:50:34 -08002213
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002214 case CMD_GET_SLICING_CONFIG: {
2215 request = (MainThreadRequest) msg.obj;
2216 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2217 request.phone.getSlicingConfig(onCompleted);
2218 break;
2219 }
2220 case EVENT_GET_SLICING_CONFIG_DONE: {
2221 ar = (AsyncResult) msg.obj;
2222 request = (MainThreadRequest) ar.userObj;
2223 ResultReceiver result = (ResultReceiver) request.argument;
2224
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002225 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002226 Bundle bundle = new Bundle();
2227 int resultCode = 0;
2228 if (ar.exception != null) {
2229 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2230 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002231 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002232 } else if (ar.result == null) {
2233 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002234 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002235 } else {
2236 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002237 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2238 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002239 }
2240
2241 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002242 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002243 }
2244 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2245 result.send(resultCode, bundle);
2246 notifyRequester(request);
2247 break;
2248 }
2249
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251 request = (MainThreadRequest) msg.obj;
2252 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002253 PurchasePremiumCapabilityArgument arg =
2254 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002255 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2256 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002257 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002258 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002259
Sarah Chin71b3a852022-09-28 15:54:19 -07002260 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002261 ar = (AsyncResult) msg.obj;
2262 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002263 PurchasePremiumCapabilityArgument arg =
2264 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002265 try {
2266 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002267 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002268 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002269 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002270 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002271 + TelephonyManager.convertPurchaseResultToString(result));
2272 } catch (RemoteException e) {
2273 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002274 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002275 + " failed: " + e;
2276 if (DBG) log(logStr);
2277 AnomalyReporter.reportAnomaly(
2278 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2279 }
2280 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002281 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002282
Michele Berionne5e411512020-11-13 02:36:59 +00002283 case CMD_PREPARE_UNATTENDED_REBOOT:
2284 request = (MainThreadRequest) msg.obj;
2285 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002286 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002287 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002288 notifyRequester(request);
2289 break;
2290
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 default:
2292 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2293 break;
2294 }
2295 }
Jake Hambye994d462014-02-03 13:10:13 -08002296
Pengquan Menga1bb6272018-09-06 09:59:22 -07002297 private void notifyRequester(MainThreadRequest request) {
2298 synchronized (request) {
2299 request.notifyAll();
2300 }
2301 }
2302
Jake Hambye994d462014-02-03 13:10:13 -08002303 private void handleNullReturnEvent(Message msg, String command) {
2304 AsyncResult ar = (AsyncResult) msg.obj;
2305 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2306 if (ar.exception == null) {
2307 request.result = true;
2308 } else {
2309 request.result = false;
2310 if (ar.exception instanceof CommandException) {
2311 loge(command + ": CommandException: " + ar.exception);
2312 } else {
2313 loge(command + ": Unknown exception");
2314 }
2315 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002316 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -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) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002326 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2327 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -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 */
2335 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2336 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002337 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002338 }
2339
2340 /**
2341 * Posts the specified command to be executed on the main thread,
2342 * waits for the request to complete, and returns the result.
2343 * @see #sendRequestAsync
2344 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002345 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002346 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2347 }
2348
2349 /**
2350 * Posts the specified command to be executed on the main thread,
2351 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2352 * if not timeout or null otherwise.
2353 * @see #sendRequestAsync
2354 */
2355 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2356 long timeoutInMs) {
2357 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002358 }
2359
2360 /**
2361 * Posts the specified command to be executed on the main thread,
2362 * waits for the request to complete, and returns the result.
2363 * @see #sendRequestAsync
2364 */
Nathan Harold92bed182018-10-12 18:16:49 -07002365 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002366 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002367 }
2368
2369 /**
2370 * Posts the specified command to be executed on the main thread,
2371 * waits for the request to complete, and returns the result.
2372 * @see #sendRequestAsync
2373 */
2374 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002375 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2376 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002377 }
2378
2379 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002380 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2381 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2382 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002383 * @see #sendRequestAsync
2384 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002385 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2386 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2388 throw new RuntimeException("This method will deadlock if called from the main thread.");
2389 }
2390
Nathan Harold92bed182018-10-12 18:16:49 -07002391 MainThreadRequest request = null;
2392 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2393 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2394 } else if (phone != null) {
2395 request = new MainThreadRequest(argument, phone, workSource);
2396 } else {
2397 request = new MainThreadRequest(argument, subId, workSource);
2398 }
2399
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 Message msg = mMainThreadHandler.obtainMessage(command, request);
2401 msg.sendToTarget();
2402
Rambo Wang0f050d82021-02-12 11:43:36 -08002403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002405 if (timeoutInMs >= 0) {
2406 // Wait for at least timeoutInMs before returning null request result
2407 long now = SystemClock.elapsedRealtime();
2408 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002409 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002410 try {
2411 request.wait(deadline - now);
2412 } catch (InterruptedException e) {
2413 // Do nothing, go back and check if request is completed or timeout
2414 } finally {
2415 now = SystemClock.elapsedRealtime();
2416 }
2417 }
2418 } else {
2419 // Wait for the request to complete
2420 while (request.result == null) {
2421 try {
2422 request.wait();
2423 } catch (InterruptedException e) {
2424 // Do nothing, go back and wait until the request is complete
2425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 }
2427 }
2428 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002429 if (request.result == null) {
2430 Log.wtf(LOG_TAG,
2431 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 return request.result;
2434 }
2435
2436 /**
2437 * Asynchronous ("fire and forget") version of sendRequest():
2438 * Posts the specified command to be executed on the main thread, and
2439 * returns immediately.
2440 * @see #sendRequest
2441 */
2442 private void sendRequestAsync(int command) {
2443 mMainThreadHandler.sendEmptyMessage(command);
2444 }
2445
2446 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002447 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002448 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002449 */
2450 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002451 sendRequestAsync(command, argument, null, null);
2452 }
2453
2454 /**
2455 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2456 * @see {@link #sendRequest(int,Object)}
2457 */
2458 private void sendRequestAsync(
2459 int command, Object argument, Phone phone, WorkSource workSource) {
2460 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002461 Message msg = mMainThreadHandler.obtainMessage(command, request);
2462 msg.sendToTarget();
2463 }
2464
2465 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 * Initialize the singleton PhoneInterfaceManager instance.
2467 * This is only done once, at startup, from PhoneApp.onCreate().
2468 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002469 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 synchronized (PhoneInterfaceManager.class) {
2471 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002472 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 } else {
2474 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2475 }
2476 return sInstance;
2477 }
2478 }
2479
2480 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002481 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002483 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002484 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002486 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002487 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002488 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2490 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002491 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002492 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002493 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002494 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002495 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002496 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002497 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2498 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002499 mVendorApiLevel = SystemProperties.getInt(
2500 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2501
Tyler Gunn64144d92022-03-17 14:16:41 -07002502 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503 publish();
arunvoddud7401012022-12-15 16:08:12 +00002504 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002505
2506 // Create the SatelliteEntitlementController singleton, for using the get the
2507 // entitlementStatus for satellite service.
2508 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 }
2510
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002511 @VisibleForTesting
2512 public SharedPreferences getSharedPreferences() {
2513 return mTelephonySharedPreferences;
2514 }
2515
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002516 /**
2517 * Get the default phone for this device.
2518 */
2519 @VisibleForTesting
2520 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002521 Phone thePhone = getPhone(getDefaultSubscription());
2522 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2523 }
2524
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 private void publish() {
2526 if (DBG) log("publish: " + this);
2527
Peter Wangc035ce42020-01-08 21:00:22 -08002528 TelephonyFrameworkInitializer
2529 .getTelephonyServiceManager()
2530 .getTelephonyServiceRegisterer()
2531 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532 }
2533
Stuart Scott584921c2015-01-15 17:10:34 -08002534 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002535 if (request.phone != null) {
2536 return request.phone;
2537 } else {
2538 return getPhoneFromSubId(request.subId);
2539 }
2540 }
2541
2542 private Phone getPhoneFromSubId(int subId) {
2543 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2544 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002545 }
2546
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002547 /**
2548 * Get phone object associated with a subscription.
2549 * Return default phone if phone object associated with subscription is null
2550 * @param subId - subscriptionId
2551 * @return phone object associated with a subscription or default phone if null.
2552 */
Ling Mac28f0212023-03-24 16:07:15 -07002553 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002554 Phone phone = getPhoneFromSubId(subId);
2555 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002556 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002557 phone = getDefaultPhone();
2558 }
2559 return phone;
2560 }
2561
Rambo Wange53e07d2022-05-10 13:01:13 -07002562 @Nullable
2563 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002564 Phone phone = getPhoneFromRequest(request);
2565 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002566 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002567 }
2568
Ling Mac28f0212023-03-24 16:07:15 -07002569 /**
2570 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2571 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2572 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2573 * @return The Phone associated the sub Id
2574 */
2575 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002576 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578
Kai Shif70f46f2021-03-03 13:59:46 -08002579 private void sendEraseModemConfig(@NonNull Phone phone) {
2580 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2581 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2582 }
2583
2584 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2585 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2586 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002587 }
2588
Peter Wang44b186e2020-01-13 23:33:09 -08002589 private boolean isImsAvailableOnDevice() {
2590 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2591 if (pm == null) {
2592 // For some reason package manger is not available.. This will fail internally anyway,
2593 // so do not throw error and allow.
2594 return true;
2595 }
2596 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2597 }
2598
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002600 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2601 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2602
Wink Savilleadd7cc52014-09-08 14:23:09 -07002603 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002604 }
2605
Wink Savilleb564aae2014-10-23 10:18:09 -07002606 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 if (DBG) log("dial: " + number);
2608 // No permission check needed here: This is just a wrapper around the
2609 // ACTION_DIAL intent, which is available to any app since it puts up
2610 // the UI before it does anything.
2611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 final long identity = Binder.clearCallingIdentity();
2613 try {
2614 String url = createTelUrl(number);
2615 if (url == null) {
2616 return;
2617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 // PENDING: should we just silently fail if phone is offhook or ringing?
2620 PhoneConstants.State state = mCM.getState(subId);
2621 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2622 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2623 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002624 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 }
2629 }
2630
2631 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002632 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002633 }
2634
Wink Savilleb564aae2014-10-23 10:18:09 -07002635 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636 if (DBG) log("call: " + number);
2637
2638 // This is just a wrapper around the ACTION_CALL intent, but we still
Jack Yu58d04bd2024-09-10 17:32:39 -07002639 // need to do a permission check since we're calling startActivityAsUser()
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640 // from the context of the phone app.
2641 enforceCallPermission();
2642
Jordan Liu1617b712019-07-10 15:06:26 -07002643 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 != AppOpsManager.MODE_ALLOWED) {
2645 return;
2646 }
2647
joonhunshin4ac60942023-11-15 15:23:39 +00002648 enforceTelephonyFeatureWithException(callingPackage,
2649 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 String url = createTelUrl(number);
2654 if (url == null) {
2655 return;
2656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 boolean isValid = false;
2659 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2660 if (slist != null) {
2661 for (SubscriptionInfo subInfoRecord : slist) {
2662 if (subInfoRecord.getSubscriptionId() == subId) {
2663 isValid = true;
2664 break;
2665 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002666 }
Wink Saville08874612014-08-31 19:19:58 -07002667 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 if (!isValid) {
2669 return;
2670 }
Wink Saville08874612014-08-31 19:19:58 -07002671
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2673 intent.putExtra(SUBSCRIPTION_KEY, subId);
2674 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002675 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676 } finally {
2677 Binder.restoreCallingIdentity(identity);
2678 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 }
2680
Wink Savilleb564aae2014-10-23 10:18:09 -07002681 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002682 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002683 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2684 }
2685
Wink Savilleb564aae2014-10-23 10:18:09 -07002686 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002687 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002688 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2689 }
2690
Wink Savilleb564aae2014-10-23 10:18:09 -07002691 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693
joonhunshin4ac60942023-11-15 15:23:39 +00002694 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2695 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2696 "supplyPinReportResultForSubscriber");
2697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 final long identity = Binder.clearCallingIdentity();
2699 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002700 Phone phone = getPhone(subId);
2701 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702 checkSimPin.start();
2703 return checkSimPin.unlockSim(null, pin);
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
2706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 }
2708
Wink Savilleb564aae2014-10-23 10:18:09 -07002709 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002710 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002711
joonhunshin4ac60942023-11-15 15:23:39 +00002712 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2713 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 final long identity = Binder.clearCallingIdentity();
2716 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002717 Phone phone = getPhone(subId);
2718 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 checkSimPuk.start();
2720 return checkSimPuk.unlockSim(puk, pin);
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
2723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 }
2725
2726 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002727 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728 * a synchronous one.
2729 */
2730 private static class UnlockSim extends Thread {
2731
2732 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002733 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734
2735 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002736 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2737 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738
2739 // For replies from SimCard interface
2740 private Handler mHandler;
2741
2742 // For async handler to identify request type
2743 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002744 private static final int SUPPLY_PIN_DELAYED = 101;
2745 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2746 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2747 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748
Michele Berionne5e411512020-11-13 02:36:59 +00002749 UnlockSim(int phoneId, IccCard simCard) {
2750 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 mSimCard = simCard;
2752 }
2753
2754 @Override
2755 public void run() {
2756 Looper.prepare();
2757 synchronized (UnlockSim.this) {
2758 mHandler = new Handler() {
2759 @Override
2760 public void handleMessage(Message msg) {
2761 AsyncResult ar = (AsyncResult) msg.obj;
2762 switch (msg.what) {
2763 case SUPPLY_PIN_COMPLETE:
2764 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2765 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002766 mRetryCount = msg.arg1;
2767 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002768 CommandException.Error error = null;
2769 if (ar.exception instanceof CommandException) {
2770 error = ((CommandException) (ar.exception))
2771 .getCommandError();
2772 }
2773 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002774 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002775 } else if (error == CommandException.Error.ABORTED) {
2776 /* When UiccCardApp dispose, handle message and return
2777 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002778 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002779 } else {
2780 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2781 }
2782 } else {
2783 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002785 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002786 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 UnlockSim.this.notifyAll();
2788 }
2789 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002790 case SUPPLY_PIN_DELAYED:
2791 if(!mDone) {
2792 String logStr = "Delay in receiving SIM PIN response ";
2793 if (DBG) log(logStr);
2794 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2795 }
2796 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 }
2798 }
2799 };
2800 UnlockSim.this.notifyAll();
2801 }
2802 Looper.loop();
2803 }
2804
2805 /*
2806 * Use PIN or PUK to unlock SIM card
2807 *
2808 * If PUK is null, unlock SIM card with PIN
2809 *
2810 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302811 *
2812 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2813 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 */
Wink Saville9de0f752013-10-22 19:04:03 -07002815 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816
2817 while (mHandler == null) {
2818 try {
2819 wait();
2820 } catch (InterruptedException e) {
2821 Thread.currentThread().interrupt();
2822 }
2823 }
2824 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2825
2826 if (puk == null) {
2827 mSimCard.supplyPin(pin, callback);
2828 } else {
2829 mSimCard.supplyPuk(puk, pin, callback);
2830 }
2831
2832 while (!mDone) {
2833 try {
2834 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002835 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2836 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002837 wait();
2838 } catch (InterruptedException e) {
2839 // Restore the interrupted status
2840 Thread.currentThread().interrupt();
2841 }
2842 }
2843 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002844 int[] resultArray = new int[2];
2845 resultArray[0] = mResult;
2846 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002847
2848 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002849 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002850 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302851 // This instance is no longer reused, so quit its thread's looper.
2852 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002853
Wink Saville9de0f752013-10-22 19:04:03 -07002854 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 }
2856 }
2857
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002858 /**
2859 * This method has been removed due to privacy and stability concerns.
2860 */
2861 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002863 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2864 return;
Wink Saville36469e72014-06-11 15:17:00 -07002865 }
2866
Nathan Harold1f889d82020-06-04 17:05:26 -07002867 @Override
2868 public void updateServiceLocationWithPackageName(String callingPackage) {
2869 mApp.getSystemService(AppOpsManager.class)
2870 .checkPackage(Binder.getCallingUid(), callingPackage);
2871
Nathan Haroldf096d982020-11-18 17:18:06 -08002872 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002873 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2874 // Callers targeting S have no business invoking this method.
2875 return;
2876 }
2877
2878 LocationAccessPolicy.LocationPermissionResult locationResult =
2879 LocationAccessPolicy.checkLocationPermission(mApp,
2880 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2881 .setCallingPackage(callingPackage)
2882 .setCallingFeatureId(null)
2883 .setCallingPid(Binder.getCallingPid())
2884 .setCallingUid(Binder.getCallingUid())
2885 .setMethod("updateServiceLocation")
2886 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2887 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2888 .build());
2889 // Apps that lack location permission have no business calling this method;
2890 // however, because no permission was declared in the public API, denials must
2891 // all be "soft".
2892 switch (locationResult) {
2893 case DENIED_HARD: /* fall through */
2894 case DENIED_SOFT:
2895 return;
2896 }
2897
2898 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899 final long identity = Binder.clearCallingIdentity();
2900 try {
Ling Mac28f0212023-03-24 16:07:15 -07002901 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 } finally {
2903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002905 }
2906
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002907 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002908 @Override
2909 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002910 return isRadioOnWithFeature(callingPackage, null);
2911 }
2912
2913
2914 @Override
2915 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2916 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2917 callingFeatureId);
2918 }
2919
2920 @Deprecated
2921 @Override
2922 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2923 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002924 }
2925
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002926 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002927 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2928 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002930 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002931 return false;
2932 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933
joonhunshin4ac60942023-11-15 15:23:39 +00002934 enforceTelephonyFeatureWithException(callingPackage,
2935 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 return isRadioOnForSubscriber(subId);
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
2942 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002943 }
2944
2945 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 final long identity = Binder.clearCallingIdentity();
2947 try {
2948 final Phone phone = getPhone(subId);
2949 if (phone != null) {
2950 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2951 } else {
2952 return false;
2953 }
2954 } finally {
2955 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 }
2958
2959 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002960 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002961 }
Wink Saville36469e72014-06-11 15:17:00 -07002962
Wink Savilleb564aae2014-10-23 10:18:09 -07002963 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965
joonhunshin4ac60942023-11-15 15:23:39 +00002966 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2967 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969 final long identity = Binder.clearCallingIdentity();
2970 try {
2971 final Phone phone = getPhone(subId);
2972 if (phone != null) {
2973 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2974 }
2975 } finally {
2976 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002977 }
Wink Saville36469e72014-06-11 15:17:00 -07002978 }
2979
2980 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002981 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002982 }
2983
Wink Savilleb564aae2014-10-23 10:18:09 -07002984 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002985 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986
2987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 final Phone phone = getPhone(subId);
2990 if (phone == null) {
2991 return false;
2992 }
2993 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2994 toggleRadioOnOffForSubscriber(subId);
2995 }
2996 return true;
2997 } finally {
2998 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003000 }
Wink Saville36469e72014-06-11 15:17:00 -07003001
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003002 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003003 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00003004
Tomasz Wasilczykef763582024-09-17 13:50:32 -07003005 if (!mApp.getResources().getBoolean(
3006 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3007 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3008 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
3009 }
joonhunshin4ac60942023-11-15 15:23:39 +00003010
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003011 /*
3012 * If any of the Radios are available, it will need to be
3013 * shutdown. So return true if any Radio is available.
3014 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3018 Phone phone = PhoneFactory.getPhone(i);
3019 if (phone != null && phone.isRadioAvailable()) return true;
3020 }
3021 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3022 return false;
3023 } finally {
3024 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003025 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003026 }
3027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003029 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030 enforceModifyPermission();
3031
joonhunshin4ac60942023-11-15 15:23:39 +00003032 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3033 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035 final long identity = Binder.clearCallingIdentity();
3036 try {
3037 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3038 logv("Shutting down Phone " + i);
3039 shutdownRadioUsingPhoneId(i);
3040 }
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003043 }
3044 }
3045
3046 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003047 Phone phone = PhoneFactory.getPhone(phoneId);
3048 if (phone != null && phone.isRadioAvailable()) {
3049 phone.shutdownRadio();
3050 }
3051 }
3052
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003053 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003054 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055
Ling Ma83dc5ea2023-01-12 15:06:04 -08003056 if (!turnOn) {
3057 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3058 }
3059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3063 if (defaultPhone != null) {
3064 defaultPhone.setRadioPower(turnOn);
3065 return true;
3066 } else {
3067 loge("There's no default phone.");
3068 return false;
3069 }
3070 } finally {
3071 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003072 }
Wink Saville36469e72014-06-11 15:17:00 -07003073 }
3074
Wink Savilleb564aae2014-10-23 10:18:09 -07003075 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003076 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003077
Ling Ma83dc5ea2023-01-12 15:06:04 -08003078 if (!turnOn) {
3079 log("setRadioPowerForSubscriber off: subId=" + subId
3080 + ",callingPackage=" + getCurrentPackageName());
3081 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 final Phone phone = getPhone(subId);
3085 if (phone != null) {
3086 phone.setRadioPower(turnOn);
3087 return true;
3088 } else {
3089 return false;
3090 }
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003094 }
3095
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003096 /**
3097 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3098 * no reason to power it off. When any of the voters want to power it off, it will be turned
3099 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3100 * powering it off, and these radio off votes will be cleared.
3101 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3102 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3103 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3104 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3105 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3106 * check its vote.
3107 *
3108 * @param subId The subscription ID.
3109 * @param reason The reason for powering off radio.
3110 * @return true on success and false on failure.
3111 */
3112 public boolean requestRadioPowerOffForReason(int subId,
3113 @TelephonyManager.RadioPowerReason int reason) {
3114 enforceModifyPermission();
3115
joonhunshin4ac60942023-11-15 15:23:39 +00003116 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3117 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3118
Ling Ma83dc5ea2023-01-12 15:06:04 -08003119 log("requestRadioPowerOffForReason: subId=" + subId
3120 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003121 final long identity = Binder.clearCallingIdentity();
3122 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003123 boolean result = false;
3124 for (Phone phone : PhoneFactory.getPhones()) {
3125 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003126 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003127 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003128 if (!result) {
3129 loge("requestRadioPowerOffForReason: no phone exists");
3130 }
3131 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003132 } finally {
3133 Binder.restoreCallingIdentity(identity);
3134 }
3135 }
3136
3137 /**
3138 * Remove the vote on powering off the radio for a reason, as requested by
3139 * {@link requestRadioPowerOffForReason}.
3140 *
3141 * @param subId The subscription ID.
3142 * @param reason The reason for powering off radio.
3143 * @return true on success and false on failure.
3144 */
3145 public boolean clearRadioPowerOffForReason(int subId,
3146 @TelephonyManager.RadioPowerReason int reason) {
3147 enforceModifyPermission();
3148
joonhunshin4ac60942023-11-15 15:23:39 +00003149 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3150 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3151
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003152 final long identity = Binder.clearCallingIdentity();
3153 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003154 boolean result = false;
3155 for (Phone phone : PhoneFactory.getPhones()) {
3156 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003157 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003158 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003159 if (!result) {
3160 loge("clearRadioPowerOffForReason: no phone exists");
3161 }
3162 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003163 } finally {
3164 Binder.restoreCallingIdentity(identity);
3165 }
3166 }
3167
3168 /**
3169 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3170 *
3171 * @param subId The subscription ID.
3172 * @param callingPackage The package making the call.
3173 * @param callingFeatureId The feature in the package.
3174 * @return List of reasons for powering off radio.
3175 */
3176 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3177 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3178
joonhunshin4ac60942023-11-15 15:23:39 +00003179 enforceTelephonyFeatureWithException(callingPackage,
3180 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3181
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003182 final long identity = Binder.clearCallingIdentity();
3183 List result = new ArrayList();
3184 try {
3185 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3186 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3187 return result;
3188 }
3189
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003190 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003191 if (phone != null) {
3192 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003193 } else {
3194 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003195 }
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
3198 }
3199 return result;
3200 }
3201
Wink Saville36469e72014-06-11 15:17:00 -07003202 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003203 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003204 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206
joonhunshin4ac60942023-11-15 15:23:39 +00003207 enforceTelephonyFeatureWithException(callingPackage,
3208 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 final long identity = Binder.clearCallingIdentity();
3211 try {
Jack Yu285100e2022-12-02 22:48:35 -08003212 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003214 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003215 phone.getDataSettingsManager().setDataEnabled(
3216 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217 return true;
3218 } else {
3219 return false;
3220 }
3221 } finally {
3222 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003224 }
3225
Wink Saville36469e72014-06-11 15:17:00 -07003226 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003227 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003228 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003229 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230
joonhunshin4ac60942023-11-15 15:23:39 +00003231 enforceTelephonyFeatureWithException(callingPackage,
3232 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 final long identity = Binder.clearCallingIdentity();
3235 try {
Jack Yu285100e2022-12-02 22:48:35 -08003236 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003237 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003238 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003239 phone.getDataSettingsManager().setDataEnabled(
3240 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241 return true;
3242 } else {
3243 return false;
3244 }
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 }
3249
Sanket Padawe356d7632015-06-22 14:03:32 -07003250 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003251 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003252 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3253 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 final Phone phone = getPhone(subId);
3258 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003259 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003260 } else {
3261 return false;
3262 }
3263 } finally {
3264 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003266 }
3267
3268 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003269 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003270 }
3271
pkanwarae03a6b2016-11-06 20:37:09 -08003272 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273 enforceCallPermission();
3274
joonhunshin4ac60942023-11-15 15:23:39 +00003275 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3276 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3281 return;
3282 }
3283 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3284 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
pkanwar32d516d2016-10-14 19:37:38 -07003288 };
3289
Wink Savilleb564aae2014-10-23 10:18:09 -07003290 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003291 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292
joonhunshin4ac60942023-11-15 15:23:39 +00003293 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3294 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3299 return false;
3300 }
3301 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3302 } finally {
3303 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003305 }
3306
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003307 /**
3308 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3309 * tag on getCallState Binder call.
3310 */
3311 @Deprecated
3312 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003313 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003314 if (CompatChanges.isChangeEnabled(
3315 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3316 Binder.getCallingUid())) {
3317 // Do not allow this API to be called on API version 31+, it should only be
3318 // called on old apps using this Binder call directly.
3319 throw new SecurityException("This method can only be used for applications "
3320 + "targeting API version 30 or less.");
3321 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003322 final long identity = Binder.clearCallingIdentity();
3323 try {
Ling Mac28f0212023-03-24 16:07:15 -07003324 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3325 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003326 } finally {
3327 Binder.restoreCallingIdentity(identity);
3328 }
3329 }
3330
3331 @Override
3332 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3333 if (CompatChanges.isChangeEnabled(
3334 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3335 Binder.getCallingUid())) {
3336 // Check READ_PHONE_STATE for API version 31+
3337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3338 featureId, "getCallStateForSubscription")) {
3339 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3340 + "targeting API level 31+.");
3341 }
3342 }
joonhunshin4ac60942023-11-15 15:23:39 +00003343
3344 enforceTelephonyFeatureWithException(callingPackage,
3345 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3346
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003350 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3351 PhoneConstantConversions.convertCallState(phone.getState());
3352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003355 }
3356
Sanket Padawe356d7632015-06-22 14:03:32 -07003357 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003358 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003359 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003360 }
3361
3362 @Override
3363 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003364 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3365 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 final long identity = Binder.clearCallingIdentity();
3368 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003369 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003370 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003371 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003372 } else {
3373 return PhoneConstantConversions.convertDataState(
3374 PhoneConstants.DataState.DISCONNECTED);
3375 }
3376 } finally {
3377 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003379 }
3380
Sanket Padawe356d7632015-06-22 14:03:32 -07003381 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003382 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003383 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003384 }
3385
3386 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003387 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003388 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3389 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003391 final long identity = Binder.clearCallingIdentity();
3392 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003393 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003394 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003395 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003396 } else {
3397 return TelephonyManager.DATA_ACTIVITY_NONE;
3398 }
3399 } finally {
3400 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003402 }
3403
3404 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003405 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003406 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003407 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003408
3409 LocationAccessPolicy.LocationPermissionResult locationResult =
3410 LocationAccessPolicy.checkLocationPermission(mApp,
3411 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3412 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003413 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003414 .setCallingPid(Binder.getCallingPid())
3415 .setCallingUid(Binder.getCallingUid())
3416 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003417 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003418 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3419 .build());
3420 switch (locationResult) {
3421 case DENIED_HARD:
3422 throw new SecurityException("Not allowed to access cell location");
3423 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003424 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3425 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003426 }
3427
joonhunshin4ac60942023-11-15 15:23:39 +00003428 enforceTelephonyFeatureWithException(callingPackage,
3429 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3430
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003431 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432 final long identity = Binder.clearCallingIdentity();
3433 try {
3434 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003435 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003436 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437 } finally {
3438 Binder.restoreCallingIdentity(identity);
3439 }
Svetoslav64fad262015-04-14 14:35:21 -07003440 }
3441
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003442 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003443 public String getNetworkCountryIsoForPhone(int phoneId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003444 if (!mApp.getResources().getBoolean(
3445 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3446 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3447 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3448 }
joonhunshin4ac60942023-11-15 15:23:39 +00003449
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003450 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3451 // registered cell info, so return a NULL country instead.
3452 final long identity = Binder.clearCallingIdentity();
3453 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003454 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3455 // Get default phone in this case.
3456 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3457 }
Jack Yu285100e2022-12-02 22:48:35 -08003458 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003459 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003460 if (phone == null) return "";
3461 ServiceStateTracker sst = phone.getServiceStateTracker();
3462 if (sst == null) return "";
3463 LocaleTracker lt = sst.getLocaleTracker();
3464 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003465 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -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 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003478 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003479 public void enableLocationUpdates() {
3480 mApp.enforceCallingOrSelfPermission(
3481 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003482 }
3483
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003484 /**
3485 * This method was removed due to potential issues caused by performing partial
3486 * updates of service state, and lack of a credible use case.
3487 *
3488 * This has the ability to break the telephony implementation by disabling notification of
3489 * changes in device connectivity. DO NOT USE THIS!
3490 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 @Override
3492 public void disableLocationUpdates() {
3493 mApp.enforceCallingOrSelfPermission(
3494 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003495 }
3496
3497 @Override
3498 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003499 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3500 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003501 try {
3502 mApp.getSystemService(AppOpsManager.class)
3503 .checkPackage(Binder.getCallingUid(), callingPackage);
3504 } catch (SecurityException e) {
3505 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3506 throw e;
3507 }
3508
Nathan Haroldf096d982020-11-18 17:18:06 -08003509 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003510 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3511 throw new SecurityException(
3512 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3513 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003514
Jordan Liu1617b712019-07-10 15:06:26 -07003515 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003516 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3517 return null;
3518 }
Svetoslav64fad262015-04-14 14:35:21 -07003519
joonhunshin4ac60942023-11-15 15:23:39 +00003520 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3521 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3522
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003523 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003525 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003526 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003527
Nathan Haroldf180aac2018-06-01 18:43:55 -07003528 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3529 for (CellInfo ci : info) {
3530 if (ci instanceof CellInfoGsm) {
3531 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3532 } else if (ci instanceof CellInfoWcdma) {
3533 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003535 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003536 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003537 }
3538
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003539 private List<CellInfo> getCachedCellInfo() {
3540 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3541 for (Phone phone : PhoneFactory.getPhones()) {
3542 List<CellInfo> info = phone.getAllCellInfo();
3543 if (info != null) cellInfos.addAll(info);
3544 }
3545 return cellInfos;
3546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003547
3548 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003549 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003550 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003551 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003552
3553 LocationAccessPolicy.LocationPermissionResult locationResult =
3554 LocationAccessPolicy.checkLocationPermission(mApp,
3555 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3556 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003557 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003558 .setCallingPid(Binder.getCallingPid())
3559 .setCallingUid(Binder.getCallingUid())
3560 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003561 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003562 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3563 .build());
3564 switch (locationResult) {
3565 case DENIED_HARD:
3566 throw new SecurityException("Not allowed to access cell info");
3567 case DENIED_SOFT:
3568 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003569 }
3570
Nathan Haroldf096d982020-11-18 17:18:06 -08003571 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003572 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3573 return getCachedCellInfo();
3574 }
3575
joonhunshin4ac60942023-11-15 15:23:39 +00003576 enforceTelephonyFeatureWithException(callingPackage,
3577 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3578
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003579 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003580 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3584 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003585 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003586 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587 if (info != null) cellInfos.addAll(info);
3588 }
3589 return cellInfos;
3590 } finally {
3591 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003592 }
3593 }
3594
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003595 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003596 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3597 String callingFeatureId) {
3598 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3599 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003600 }
3601
3602 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003603 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3604 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003605 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003606 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003607 }
3608
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003609 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3610 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003611 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003612 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003613
3614 LocationAccessPolicy.LocationPermissionResult locationResult =
3615 LocationAccessPolicy.checkLocationPermission(mApp,
3616 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3617 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003618 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003619 .setCallingPid(Binder.getCallingPid())
3620 .setCallingUid(Binder.getCallingUid())
3621 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003622 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3623 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003624 .build());
3625 switch (locationResult) {
3626 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003627 if (TelephonyPermissions
3628 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003629 // Safetynet logging for b/154934934
3630 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3631 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003632 throw new SecurityException("Not allowed to access cell info");
3633 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003634 if (TelephonyPermissions
3635 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003636 // Safetynet logging for b/154934934
3637 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3638 }
Nathan Harold5320c422019-05-09 10:26:08 -07003639 try {
3640 cb.onCellInfo(new ArrayList<CellInfo>());
3641 } catch (RemoteException re) {
3642 // Drop without consequences
3643 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003644 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003645 }
3646
joonhunshin4ac60942023-11-15 15:23:39 +00003647 enforceTelephonyFeatureWithException(callingPackage,
3648 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003649
3650 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003651 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3652
3653 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3654 }
3655
3656 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003657 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003658 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003659 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660
3661 final long identity = Binder.clearCallingIdentity();
3662 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003663 Phone phone = getPhone(subId);
3664 if (phone == null) {
3665 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3666 } else {
3667 phone.setCellInfoListRate(rateInMillis, workSource);
3668 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669 } finally {
3670 Binder.restoreCallingIdentity(identity);
3671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003672 }
3673
Shishir Agrawala9f32182016-04-12 12:00:16 -07003674 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003675 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003676 Phone phone = PhoneFactory.getPhone(slotIndex);
3677 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003678 return null;
3679 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003680 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003681 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003682 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003683 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003684 return null;
3685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 return phone.getImei();
3690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003693 }
3694
3695 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003696 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3697 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3698 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3699 callingFeatureId, "getPrimaryImei")) {
3700 throw new SecurityException("Caller does not have permission");
3701 }
joonhunshin4ac60942023-11-15 15:23:39 +00003702
arunvoddud5c6ce02022-12-11 06:03:12 +00003703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 for (Phone phone : PhoneFactory.getPhones()) {
3706 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3707 return phone.getImei();
3708 }
3709 }
3710 throw new UnsupportedOperationException("Operation not supported");
3711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
3714 }
3715
3716 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003717 public String getTypeAllocationCodeForSlot(int slotIndex) {
3718 Phone phone = PhoneFactory.getPhone(slotIndex);
3719 String tac = null;
3720 if (phone != null) {
3721 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003722 try {
3723 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3724 } catch (IndexOutOfBoundsException e) {
3725 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3726 return null;
3727 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003728 }
3729 return tac;
3730 }
3731
3732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003733 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003734 try {
3735 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3736 } catch (SecurityException se) {
3737 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3738 throw new SecurityException("Package " + callingPackage + " does not belong to "
3739 + Binder.getCallingUid());
3740 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003741 Phone phone = PhoneFactory.getPhone(slotIndex);
3742 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003743 return null;
3744 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003745
Jeff Davidson913390f2018-02-23 17:11:49 -08003746 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003747 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003748 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003749 return null;
3750 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751
joonhunshin4ac60942023-11-15 15:23:39 +00003752 enforceTelephonyFeatureWithException(callingPackage,
3753 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3754
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755 final long identity = Binder.clearCallingIdentity();
3756 try {
3757 return phone.getMeid();
3758 } finally {
3759 Binder.restoreCallingIdentity(identity);
3760 }
Jack Yu2af8d712017-03-15 17:14:14 -07003761 }
3762
3763 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003764 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003765 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3766 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3767
David Kelly5e06a7f2018-03-12 14:10:59 +00003768 Phone phone = PhoneFactory.getPhone(slotIndex);
3769 String manufacturerCode = null;
3770 if (phone != null) {
3771 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003772 try {
3773 manufacturerCode =
3774 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3775 } catch (IndexOutOfBoundsException e) {
3776 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3777 return null;
3778 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003779 }
3780 return manufacturerCode;
3781 }
3782
3783 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003784 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3785 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003786 Phone phone = PhoneFactory.getPhone(slotIndex);
3787 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003788 return null;
3789 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003790 int subId = phone.getSubId();
3791 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003792 mApp, subId, callingPackage, callingFeatureId,
3793 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003794 return null;
3795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796
joonhunshin4ac60942023-11-15 15:23:39 +00003797 enforceTelephonyFeatureWithException(callingPackage,
3798 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 return phone.getDeviceSvn();
3803 } finally {
3804 Binder.restoreCallingIdentity(identity);
3805 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003806 }
3807
fionaxu43304da2017-11-27 22:51:16 -08003808 @Override
3809 public int getSubscriptionCarrierId(int subId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003810 if (!mApp.getResources().getBoolean(
3811 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3812 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3813 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3814 }
joonhunshin4ac60942023-11-15 15:23:39 +00003815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816 final long identity = Binder.clearCallingIdentity();
3817 try {
3818 final Phone phone = getPhone(subId);
3819 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
3822 }
fionaxu43304da2017-11-27 22:51:16 -08003823 }
3824
3825 @Override
3826 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003827 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3828 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 final Phone phone = getPhone(subId);
3833 return phone == null ? null : phone.getCarrierName();
3834 } finally {
3835 Binder.restoreCallingIdentity(identity);
3836 }
fionaxu43304da2017-11-27 22:51:16 -08003837 }
3838
calvinpanffe225e2018-11-01 19:43:06 +08003839 @Override
chen xu0026ca62019-03-06 15:28:50 -08003840 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003841 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3842 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3843
chen xu25637222018-11-04 17:17:00 -08003844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 final Phone phone = getPhone(subId);
3847 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003848 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003849 } finally {
3850 Binder.restoreCallingIdentity(identity);
3851 }
3852 }
3853
3854 @Override
chen xu0026ca62019-03-06 15:28:50 -08003855 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003856 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3857 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3858 "getSubscriptionSpecificCarrierName");
3859
chen xu25637222018-11-04 17:17:00 -08003860 final long identity = Binder.clearCallingIdentity();
3861 try {
3862 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003863 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003864 } finally {
3865 Binder.restoreCallingIdentity(identity);
3866 }
3867 }
3868
chen xu651eec72018-11-11 19:03:44 -08003869 @Override
chen xu864e11c2018-12-06 22:10:03 -08003870 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3871 if (!isSubscriptionMccMnc) {
3872 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3873 }
chen xu651eec72018-11-11 19:03:44 -08003874 final Phone phone = PhoneFactory.getPhone(slotIndex);
3875 if (phone == null) {
3876 return TelephonyManager.UNKNOWN_CARRIER_ID;
3877 }
joonhunshin4ac60942023-11-15 15:23:39 +00003878
3879 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3880 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3881
chen xu651eec72018-11-11 19:03:44 -08003882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3885 } finally {
3886 Binder.restoreCallingIdentity(identity);
3887 }
3888 }
3889
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003890 //
3891 // Internal helper methods.
3892 //
3893
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003894 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003895 * Make sure the caller is the calling package itself
3896 *
3897 * @throws SecurityException if the caller is not the calling package
3898 */
3899 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3900 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003901 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3902 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003903 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003904 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003905 } catch (PackageManager.NameNotFoundException e) {
3906 // packageUid is -1
3907 }
3908 if (packageUid != callingUid) {
3909 throw new SecurityException(message + ": Package " + callingPackage
3910 + " does not belong to " + callingUid);
3911 }
3912 }
3913
3914 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003915 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3916 *
3917 * @throws SecurityException if the caller does not have the required permission
3918 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003919 @VisibleForTesting
3920 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003921 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3922 }
3923
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003924 /**
arunvoddud7401012022-12-15 16:08:12 +00003925 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003926 *
3927 * @throws SecurityException if the caller does not have the required permission
3928 */
3929 @VisibleForTesting
3930 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003931 enforceReadPermission(null);
3932 }
3933
3934 /**
3935 * Make sure the caller has the READ_PHONE_STATE permissions.
3936 *
3937 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3938 */
3939 @VisibleForTesting
3940 public void enforceReadPermission(String msg) {
3941 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003942 }
3943
Shuo Qian3b6ee772019-11-13 17:43:31 -08003944 private void enforceActiveEmergencySessionPermission() {
3945 mApp.enforceCallingOrSelfPermission(
3946 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3947 }
3948
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003949 /**
3950 * Make sure the caller has the CALL_PHONE permission.
3951 *
3952 * @throws SecurityException if the caller does not have the required permission
3953 */
3954 private void enforceCallPermission() {
3955 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3956 }
3957
paulhu5a773602019-08-23 19:17:33 +08003958 private void enforceSettingsPermission() {
3959 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003960 }
3961
Michele Berionne5e411512020-11-13 02:36:59 +00003962 private void enforceRebootPermission() {
3963 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3964 }
3965
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003966 /**
3967 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3968 * @param message - log message to print.
3969 * @throws SecurityException if the caller does not have the required permission
3970 */
3971 private void enforceSatelliteCommunicationPermission(String message) {
3972 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3973 }
3974
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003975 /**
3976 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3977 * @param message - log message to print.
3978 * @throws SecurityException if the caller does not have the required permission
3979 */
3980 private void enforcePackageUsageStatsPermission(String message) {
3981 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3982 }
3983
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003984 private String createTelUrl(String number) {
3985 if (TextUtils.isEmpty(number)) {
3986 return null;
3987 }
3988
Jake Hambye994d462014-02-03 13:10:13 -08003989 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003990 }
3991
Ihab Awadf9e92732013-12-05 18:02:52 -08003992 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003993 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003994 }
3995
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003996 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003997 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003998 }
3999
Ihab Awadf9e92732013-12-05 18:02:52 -08004000 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004001 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004002 }
4003
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004004 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004005 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004006 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004007 }
4008
Sanket Padawe356d7632015-06-22 14:03:32 -07004009 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004010 public int getActivePhoneTypeForSlot(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07004011 if (!mApp.getResources().getBoolean(
4012 com.android.internal.R.bool.config_force_phone_globals_creation)) {
4013 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4014 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4015 }
joonhunshin4ac60942023-11-15 15:23:39 +00004016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 final long identity = Binder.clearCallingIdentity();
4018 try {
4019 final Phone phone = PhoneFactory.getPhone(slotIndex);
4020 if (phone == null) {
4021 return PhoneConstants.PHONE_TYPE_NONE;
4022 } else {
4023 return phone.getPhoneType();
4024 }
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004028 }
4029
4030 /**
4031 * Returns the CDMA ERI icon index to display
4032 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004033 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004034 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4035 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4036 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004037 }
4038
Sanket Padawe356d7632015-06-22 14:03:32 -07004039 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004040 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4041 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004043 mApp, subId, callingPackage, callingFeatureId,
4044 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004045 return -1;
4046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047
joonhunshin4ac60942023-11-15 15:23:39 +00004048 enforceTelephonyFeatureWithException(callingPackage,
4049 PackageManager.FEATURE_TELEPHONY_CDMA,
4050 "getCdmaEriIconIndexForSubscriber");
4051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 final Phone phone = getPhone(subId);
4055 if (phone != null) {
4056 return phone.getCdmaEriIconIndex();
4057 } else {
4058 return -1;
4059 }
4060 } finally {
4061 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004062 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004063 }
4064
4065 /**
4066 * Returns the CDMA ERI icon mode,
4067 * 0 - ON
4068 * 1 - FLASHING
4069 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004070 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004071 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4072 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4073 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004074 }
4075
Sanket Padawe356d7632015-06-22 14:03:32 -07004076 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004077 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4078 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004080 mApp, subId, callingPackage, callingFeatureId,
4081 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004082 return -1;
4083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004084
4085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 final Phone phone = getPhone(subId);
4088 if (phone != null) {
4089 return phone.getCdmaEriIconMode();
4090 } else {
4091 return -1;
4092 }
4093 } finally {
4094 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004096 }
4097
4098 /**
4099 * Returns the CDMA ERI text,
4100 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004101 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004102 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4103 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4104 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004105 }
4106
Sanket Padawe356d7632015-06-22 14:03:32 -07004107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004108 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4109 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004111 mApp, subId, callingPackage, callingFeatureId,
4112 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004113 return null;
4114 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115
4116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 final Phone phone = getPhone(subId);
4119 if (phone != null) {
4120 return phone.getCdmaEriText();
4121 } else {
4122 return null;
4123 }
4124 } finally {
4125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004127 }
4128
4129 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004130 * Returns the CDMA MDN.
4131 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004132 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004133 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4135 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004136
joonhunshin4ac60942023-11-15 15:23:39 +00004137 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4138 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4139
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140 final long identity = Binder.clearCallingIdentity();
4141 try {
4142 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004143 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144 return phone.getLine1Number();
4145 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004146 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004147 return null;
4148 }
4149 } finally {
4150 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004151 }
4152 }
4153
4154 /**
4155 * Returns the CDMA MIN.
4156 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004157 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004158 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4160 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004161
joonhunshin4ac60942023-11-15 15:23:39 +00004162 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4163 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165 final long identity = Binder.clearCallingIdentity();
4166 try {
4167 final Phone phone = getPhone(subId);
4168 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4169 return phone.getCdmaMin();
4170 } else {
4171 return null;
4172 }
4173 } finally {
4174 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004175 }
4176 }
4177
Hall Liud892bec2018-11-30 14:51:45 -08004178 @Override
4179 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4180 INumberVerificationCallback callback, String callingPackage) {
4181 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4182 != PERMISSION_GRANTED) {
4183 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4184 }
4185 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4186
4187 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4188 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004189 throw new SecurityException("Calling package must be configured in the device config: "
4190 + "calling package: " + callingPackage
4191 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004192 }
4193
joonhunshin4ac60942023-11-15 15:23:39 +00004194 enforceTelephonyFeatureWithException(callingPackage,
4195 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4196
Hall Liud892bec2018-11-30 14:51:45 -08004197 if (range == null) {
4198 throw new NullPointerException("Range must be non-null");
4199 }
4200
4201 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004202 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004203
4204 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4205 }
4206
Junda Liuca05d5d2014-08-14 22:36:34 -07004207 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004208 * Returns true if CDMA provisioning needs to run.
4209 */
4210 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004211 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4212 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 final long identity = Binder.clearCallingIdentity();
4215 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004216 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217 } finally {
4218 Binder.restoreCallingIdentity(identity);
4219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004220 }
4221
4222 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004223 * Sets the voice mail number of a given subId.
4224 */
4225 @Override
4226 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004227 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4228 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229
joonhunshin4ac60942023-11-15 15:23:39 +00004230 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4231 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004233 final long identity = Binder.clearCallingIdentity();
4234 try {
Nathan Harolddc3bcec2024-05-16 14:06:40 -07004235 Boolean success = (Boolean) sendRequest(
4236 CMD_SET_VOICEMAIL_NUMBER,
4237 new Pair<String, String>(alphaTag, number),
4238 new Integer(subId),
4239 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
4240 if (success == null) return false; // most likely due to a timeout
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004241 return success;
4242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004245 }
4246
Ta-wei Yen87c49842016-05-13 21:19:52 -07004247 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004248 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4249 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004250 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4251 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004252 if (!TextUtils.equals(callingPackage, systemDialer)) {
4253 throw new SecurityException("caller must be system dialer");
4254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004255
joonhunshin4ac60942023-11-15 15:23:39 +00004256 enforceTelephonyFeatureWithException(callingPackage,
4257 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259 final long identity = Binder.clearCallingIdentity();
4260 try {
4261 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4262 if (phoneAccountHandle == null) {
4263 return null;
4264 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004265 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004266 } finally {
4267 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004268 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004269 }
4270
4271 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4273 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004274 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004276 mApp, subId, callingPackage, callingFeatureId,
4277 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004278 return null;
4279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280
joonhunshin4ac60942023-11-15 15:23:39 +00004281 enforceTelephonyFeatureWithException(callingPackage,
4282 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4283
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004284 final long identity = Binder.clearCallingIdentity();
4285 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004286 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004290 }
4291
4292 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004293 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4294 VisualVoicemailSmsFilterSettings settings) {
4295 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004296 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004297 enforceTelephonyFeatureWithException(callingPackage,
4298 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299 final long identity = Binder.clearCallingIdentity();
4300 try {
4301 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004302 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004303 } finally {
4304 Binder.restoreCallingIdentity(identity);
4305 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004306 }
4307
4308 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004309 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4310 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004311 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004312 enforceTelephonyFeatureWithException(callingPackage,
4313 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315 final long identity = Binder.clearCallingIdentity();
4316 try {
4317 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004318 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004322 }
4323
4324 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004325 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4326 String callingPackage, int subId) {
4327 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328
4329 final long identity = Binder.clearCallingIdentity();
4330 try {
4331 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004332 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004336 }
4337
4338 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004339 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004340 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341
4342 final long identity = Binder.clearCallingIdentity();
4343 try {
4344 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004345 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004346 } finally {
4347 Binder.restoreCallingIdentity(identity);
4348 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004349 }
4350
4351 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004352 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4353 String callingAttributionTag, int subId, String number, int port, String text,
4354 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004355 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004356 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004357 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004358
4359 enforceTelephonyFeatureWithException(callingPackage,
4360 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4361
Amit Mahajandccb3f12019-05-13 13:48:32 -07004362 SmsController smsController = PhoneFactory.getSmsController();
Nikhil Kumardeebd752024-08-14 14:49:06 +01004363 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage,
4364 Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number,
4365 port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004366 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004367
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004368 /**
fionaxu0152e512016-11-14 13:36:14 -08004369 * Sets the voice activation state of a given subId.
4370 */
4371 @Override
4372 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4374 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375
joonhunshin4ac60942023-11-15 15:23:39 +00004376 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4377 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004379 final long identity = Binder.clearCallingIdentity();
4380 try {
4381 final Phone phone = getPhone(subId);
4382 if (phone != null) {
4383 phone.setVoiceActivationState(activationState);
4384 } else {
4385 loge("setVoiceActivationState fails with invalid subId: " + subId);
4386 }
4387 } finally {
4388 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004389 }
4390 }
4391
4392 /**
4393 * Sets the data activation state of a given subId.
4394 */
4395 @Override
4396 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4398 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004399
joonhunshin4ac60942023-11-15 15:23:39 +00004400 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4401 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 final long identity = Binder.clearCallingIdentity();
4404 try {
4405 final Phone phone = getPhone(subId);
4406 if (phone != null) {
4407 phone.setDataActivationState(activationState);
4408 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004409 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 }
4411 } finally {
4412 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004413 }
4414 }
4415
4416 /**
4417 * Returns the voice activation state of a given subId.
4418 */
4419 @Override
4420 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004421 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422
joonhunshin4ac60942023-11-15 15:23:39 +00004423 enforceTelephonyFeatureWithException(callingPackage,
4424 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4425
fionaxu0152e512016-11-14 13:36:14 -08004426 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427 final long identity = Binder.clearCallingIdentity();
4428 try {
4429 if (phone != null) {
4430 return phone.getVoiceActivationState();
4431 } else {
4432 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4433 }
4434 } finally {
4435 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004436 }
4437 }
4438
4439 /**
4440 * Returns the data activation state of a given subId.
4441 */
4442 @Override
4443 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004444 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445
joonhunshin4ac60942023-11-15 15:23:39 +00004446 enforceTelephonyFeatureWithException(callingPackage,
4447 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4448
fionaxu0152e512016-11-14 13:36:14 -08004449 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 final long identity = Binder.clearCallingIdentity();
4451 try {
4452 if (phone != null) {
4453 return phone.getDataActivationState();
4454 } else {
4455 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4456 }
4457 } finally {
4458 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004459 }
4460 }
4461
4462 /**
Wink Saville36469e72014-06-11 15:17:00 -07004463 * Returns the unread count of voicemails for a subId
4464 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004465 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004466 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4467 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004468 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004469 mApp, subId, callingPackage, callingFeatureId,
4470 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004471 return 0;
4472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004473 final long identity = Binder.clearCallingIdentity();
4474 try {
4475 final Phone phone = getPhone(subId);
4476 if (phone != null) {
4477 return phone.getVoiceMessageCount();
4478 } else {
4479 return 0;
4480 }
4481 } finally {
4482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004484 }
4485
4486 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004487 * returns true, if the device is in a state where both voice and data
4488 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004489 */
4490 @Override
4491 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004492 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4493 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
Ling Mac28f0212023-03-24 16:07:15 -07004497 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004501 }
4502
4503 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004504 * Send the dialer code if called from the current default dialer or the caller has
4505 * carrier privilege.
4506 * @param inputCode The dialer code to send
4507 */
4508 @Override
4509 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004510 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004511 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004512 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4513 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004514 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004515 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004516 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518
joonhunshin4ac60942023-11-15 15:23:39 +00004519 enforceTelephonyFeatureWithException(callingPackage,
4520 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522 final long identity = Binder.clearCallingIdentity();
4523 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004524 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525 } finally {
4526 Binder.restoreCallingIdentity(identity);
4527 }
fionaxu235cc5e2017-03-06 22:25:57 -08004528 }
4529
Pengquan Menga1bb6272018-09-06 09:59:22 -07004530 @Override
4531 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004532 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004533 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4534 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004535
4536 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4537 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4538
shilufc958392020-01-20 11:36:01 -08004539 final long identity = Binder.clearCallingIdentity();
4540 try {
4541 if (!isActiveSubscription(subId)) {
4542 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4543 }
4544 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4545 } finally {
4546 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004548 }
4549
Brad Ebinger35c841c2018-10-01 10:40:55 -07004550 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004551 public boolean isInEmergencySmsMode() {
4552 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004553
4554 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4555 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4556
Brad Ebingerb2b65522019-03-15 13:48:47 -07004557 final long identity = Binder.clearCallingIdentity();
4558 try {
4559 for (Phone phone : PhoneFactory.getPhones()) {
4560 if (phone.isInEmergencySmsMode()) {
4561 return true;
4562 }
4563 }
4564 } finally {
4565 Binder.restoreCallingIdentity(identity);
4566 }
4567 return false;
4568 }
4569
shilu366312e2019-12-17 09:28:10 -08004570 /**
4571 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4572 * @param subId The subscription to use to check the configuration.
4573 * @param c The callback that will be used to send the result.
4574 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004575 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004576 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4577 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004578 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004579 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004580
4581 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4582 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4583 "IMS not available on device.");
4584 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004585 final long token = Binder.clearCallingIdentity();
4586 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004587 int slotId = getSlotIndexOrException(subId);
4588 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004589
4590 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4591 if (controller != null) {
4592 ImsManager imsManager = controller.getImsManager(subId);
4593 if (imsManager != null) {
4594 imsManager.addRegistrationCallbackForSubscription(c, subId);
4595 } else {
4596 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4597 }
4598 } else {
4599 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4600 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004601 } catch (ImsException e) {
4602 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004603 } finally {
4604 Binder.restoreCallingIdentity(token);
4605 }
4606 }
4607
shilu366312e2019-12-17 09:28:10 -08004608 /**
4609 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4610 * @param subId The subscription to use to check the configuration.
4611 * @param c The callback that will be used to send the result.
4612 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004613 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004614 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004615 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004616 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004617 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4618 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4619 }
Meng Wangafbc5852019-09-19 17:37:13 -07004620 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004621
Meng Wangafbc5852019-09-19 17:37:13 -07004622 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004623 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4624 if (controller != null) {
4625 ImsManager imsManager = controller.getImsManager(subId);
4626 if (imsManager != null) {
4627 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4628 } else {
4629 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4630 + "is inactive, ignoring unregister.");
4631 // If the ImsManager is not valid, just return, since the callback
4632 // will already have been removed internally.
4633 }
4634 }
Meng Wangafbc5852019-09-19 17:37:13 -07004635 } finally {
4636 Binder.restoreCallingIdentity(token);
4637 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004638 }
4639
Brad Ebingera34a6c22019-10-22 17:36:18 -07004640 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004641 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4642 * @param subId The subscription to use to check the configuration.
4643 * @param c The callback that will be used to send the result.
4644 */
4645 @Override
4646 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4647 throws RemoteException {
4648 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4649 mApp, subId, "registerImsEmergencyRegistrationCallback");
4650
4651 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4652 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4653 "IMS not available on device.");
4654 }
4655 final long token = Binder.clearCallingIdentity();
4656 try {
4657 int slotId = getSlotIndexOrException(subId);
4658 verifyImsMmTelConfiguredOrThrow(slotId);
4659
4660 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4661 if (controller != null) {
4662 ImsManager imsManager = controller.getImsManager(subId);
4663 if (imsManager != null) {
4664 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4665 } else {
4666 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4667 }
4668 } else {
4669 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4670 }
4671 } catch (ImsException e) {
4672 throw new ServiceSpecificException(e.getCode());
4673 } finally {
4674 Binder.restoreCallingIdentity(token);
4675 }
4676 }
4677
4678 /**
4679 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4680 * @param subId The subscription to use to check the configuration.
4681 * @param c The callback that will be used to send the result.
4682 */
4683 @Override
4684 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4685 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4686 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4687 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4688 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4689 }
4690 final long token = Binder.clearCallingIdentity();
4691
4692 try {
4693 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4694 if (controller != null) {
4695 ImsManager imsManager = controller.getImsManager(subId);
4696 if (imsManager != null) {
4697 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4698 } else {
4699 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4700 + "is inactive, ignoring unregister.");
4701 // If the ImsManager is not valid, just return, since the callback
4702 // will already have been removed internally.
4703 }
4704 }
4705 } finally {
4706 Binder.restoreCallingIdentity(token);
4707 }
4708 }
4709
4710 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004711 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4712 */
4713 @Override
4714 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4715 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4716 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4717 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4718 "IMS not available on device.");
4719 }
4720 final long token = Binder.clearCallingIdentity();
4721 try {
4722 Phone phone = getPhone(subId);
4723 if (phone == null) {
4724 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4725 + subId + "'");
4726 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4727 }
4728 phone.getImsRegistrationState(regState -> {
4729 try {
4730 consumer.accept((regState == null)
4731 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4732 } catch (RemoteException e) {
4733 // Ignore if the remote process is no longer available to call back.
4734 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4735 }
4736 });
4737 } finally {
4738 Binder.restoreCallingIdentity(token);
4739 }
4740 }
4741
4742 /**
4743 * Get the transport type for the IMS service registration state.
4744 */
4745 @Override
4746 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004747 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004748 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004749 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4750 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4751 "IMS not available on device.");
4752 }
4753 final long token = Binder.clearCallingIdentity();
4754 try {
4755 Phone phone = getPhone(subId);
4756 if (phone == null) {
4757 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4758 + subId + "'");
4759 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4760 }
4761 phone.getImsRegistrationTech(regTech -> {
4762 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4763 int regTechConverted = (regTech == null)
4764 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4765 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4766 regTechConverted);
4767 try {
4768 consumer.accept(regTechConverted);
4769 } catch (RemoteException e) {
4770 // Ignore if the remote process is no longer available to call back.
4771 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4772 }
4773 });
4774 } finally {
4775 Binder.restoreCallingIdentity(token);
4776 }
4777 }
4778
shilu366312e2019-12-17 09:28:10 -08004779 /**
4780 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4781 * @param subId The subscription to use to check the configuration.
4782 * @param c The callback that will be used to send the result.
4783 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004784 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004785 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4786 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004787 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004788 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004789 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4790 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4791 "IMS not available on device.");
4792 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004793 final long token = Binder.clearCallingIdentity();
4794 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004795 int slotId = getSlotIndexOrException(subId);
4796 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004797
4798 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4799 if (controller != null) {
4800 ImsManager imsManager = controller.getImsManager(subId);
4801 if (imsManager != null) {
4802 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4803 } else {
4804 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4805 }
4806 } else {
4807 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4808 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004809 } catch (ImsException e) {
4810 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004811 } finally {
4812 Binder.restoreCallingIdentity(token);
4813 }
4814 }
4815
shilu366312e2019-12-17 09:28:10 -08004816 /**
4817 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4818 * @param subId The subscription to use to check the configuration.
4819 * @param c The callback that will be used to send the result.
4820 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004821 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004822 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004823 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004824 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004825 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4826 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4827 }
Meng Wangafbc5852019-09-19 17:37:13 -07004828
4829 final long token = Binder.clearCallingIdentity();
4830 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004831 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4832 if (controller != null) {
4833 ImsManager imsManager = controller.getImsManager(subId);
4834 if (imsManager != null) {
4835 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4836 } else {
4837 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4838 + " is inactive, ignoring unregister.");
4839 // If the ImsManager is not valid, just return, since the callback
4840 // will already have been removed internally.
4841 }
4842 }
Meng Wangafbc5852019-09-19 17:37:13 -07004843 } finally {
4844 Binder.restoreCallingIdentity(token);
4845 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004846 }
4847
4848 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004849 public boolean isCapable(int subId, int capability, int regTech) {
4850 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004851
4852 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4853 FEATURE_TELEPHONY_IMS, "isCapable");
4854
Brad Ebinger35c841c2018-10-01 10:40:55 -07004855 final long token = Binder.clearCallingIdentity();
4856 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004857 int slotId = getSlotIndexOrException(subId);
4858 verifyImsMmTelConfiguredOrThrow(slotId);
4859 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4860 } catch (com.android.ims.ImsException e) {
4861 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4862 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004863 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004864 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4865 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004866 } finally {
4867 Binder.restoreCallingIdentity(token);
4868 }
4869 }
4870
4871 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004872 public boolean isAvailable(int subId, int capability, int regTech) {
4873 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004874
4875 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4876 FEATURE_TELEPHONY_IMS, "isAvailable");
4877
Brad Ebinger35c841c2018-10-01 10:40:55 -07004878 final long token = Binder.clearCallingIdentity();
4879 try {
4880 Phone phone = getPhone(subId);
4881 if (phone == null) return false;
4882 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004883 } catch (com.android.ims.ImsException e) {
4884 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4885 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004886 } finally {
4887 Binder.restoreCallingIdentity(token);
4888 }
4889 }
4890
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004891 /**
4892 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4893 * subscription.
4894 * @param subId The subscription to use to check the configuration.
4895 * @param callback The callback that will be used to send the result.
4896 * @param capability The MmTelFeature capability that will be used to send the result.
4897 * @param transportType The transport type of the MmTelFeature capability.
4898 */
4899 @Override
4900 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4901 int transportType) {
4902 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004903 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4904 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4905 "IMS not available on device.");
4906 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004907 final long token = Binder.clearCallingIdentity();
4908 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004909 int slotId = getSlotIndex(subId);
4910 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4911 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4912 + subId + "'");
4913 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4914 }
4915 verifyImsMmTelConfiguredOrThrow(slotId);
4916 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4917 transportType, aBoolean -> {
4918 try {
4919 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4920 } catch (RemoteException e) {
4921 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4922 + "running. Ignore");
4923 }
4924 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004925 } catch (ImsException e) {
4926 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004927 } finally {
4928 Binder.restoreCallingIdentity(token);
4929 }
4930 }
4931
shilu366312e2019-12-17 09:28:10 -08004932 /**
4933 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4934 * @param subId The subscription to use to check the configuration.
4935 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004936 @Override
4937 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004938 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004939 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004940
joonhunshin4ac60942023-11-15 15:23:39 +00004941 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4942 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4943
Brad Ebinger35c841c2018-10-01 10:40:55 -07004944 final long token = Binder.clearCallingIdentity();
4945 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004946 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004947 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004948 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004949 } catch (ImsException e) {
4950 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004951 } finally {
4952 Binder.restoreCallingIdentity(token);
4953 }
4954 }
4955
4956 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004957 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004959 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004960
4961 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4962 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4963
Brad Ebinger35c841c2018-10-01 10:40:55 -07004964 final long identity = Binder.clearCallingIdentity();
4965 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004966 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004967 // This setting doesn't require an active ImsService connection, so do not verify. The
4968 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004969 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004970 } catch (ImsException e) {
4971 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
4975 }
4976
shilu366312e2019-12-17 09:28:10 -08004977 /**
4978 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4979 * @param subId The subscription to use to check the configuration.
4980 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004981 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004982 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004983 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004984 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004985
4986 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4987 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4988
Brad Ebinger35c841c2018-10-01 10:40:55 -07004989 final long identity = Binder.clearCallingIdentity();
4990 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004991 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004992 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004993 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004994 } catch (ImsException e) {
4995 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
4999 }
5000
5001 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005002 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005004 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005005
5006 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5007 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
5008
Brad Ebinger35c841c2018-10-01 10:40:55 -07005009 final long identity = Binder.clearCallingIdentity();
5010 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005011 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005012 // This setting doesn't require an active ImsService connection, so do not verify. The
5013 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005014 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005015 } catch (ImsException e) {
5016 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005017 } finally {
5018 Binder.restoreCallingIdentity(identity);
5019 }
5020 }
5021
shilu366312e2019-12-17 09:28:10 -08005022 /**
5023 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5024 * @param subId The subscription to use to check the configuration.
5025 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005026 @Override
5027 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005028 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005029 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005030
5031 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5032 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5033
Brad Ebinger35c841c2018-10-01 10:40:55 -07005034 final long identity = Binder.clearCallingIdentity();
5035 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005036 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005037 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005038 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005039 } catch (ImsException e) {
5040 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005041 } finally {
5042 Binder.restoreCallingIdentity(identity);
5043 }
5044 }
5045
5046 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005047 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005049 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005050
5051 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5052 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5053
Brad Ebinger35c841c2018-10-01 10:40:55 -07005054 final long identity = Binder.clearCallingIdentity();
5055 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005056 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005057 // This setting doesn't require an active ImsService connection, so do not verify. The
5058 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005059 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005060 } catch (ImsException e) {
5061 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005062 } finally {
5063 Binder.restoreCallingIdentity(identity);
5064 }
5065 }
5066
shilu366312e2019-12-17 09:28:10 -08005067 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005068 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5069 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5070 * @param subId The subscription to use to check the configuration.
5071 */
5072 @Override
5073 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005074 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005075 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005076
5077 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5078 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5079
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005080 final long identity = Binder.clearCallingIdentity();
5081 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005082 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005083 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005084 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005085 } catch (ImsException e) {
5086 throw new ServiceSpecificException(e.getCode());
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
5089 }
5090 }
5091
5092 /**
5093 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5094 * Requires MODIFY_PHONE_STATE permission.
5095 * @param subId The subscription to use to check the configuration.
5096 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5097 * false otherwise
5098 */
5099 @Override
5100 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5102 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005103
5104 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5105 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5106
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005107 final long identity = Binder.clearCallingIdentity();
5108 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005109 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005110 // This setting doesn't require an active ImsService connection, so do not verify. The
5111 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005112 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005113 } catch (ImsException e) {
5114 throw new ServiceSpecificException(e.getCode());
5115 } finally {
5116 Binder.restoreCallingIdentity(identity);
5117 }
5118 }
5119
5120 /**
shilu366312e2019-12-17 09:28:10 -08005121 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5122 * @param subId The subscription to use to check the configuration.
5123 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005124 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005125
Brad Ebinger35c841c2018-10-01 10:40:55 -07005126 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005127 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005128 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005129
5130 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5131 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5132
Brad Ebinger35c841c2018-10-01 10:40:55 -07005133 final long identity = Binder.clearCallingIdentity();
5134 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005135 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005136 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005137 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005138 } catch (ImsException e) {
5139 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005140 } finally {
5141 Binder.restoreCallingIdentity(identity);
5142 }
5143 }
5144
5145 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005146 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005148 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005149
5150 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5151 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5152
Brad Ebinger35c841c2018-10-01 10:40:55 -07005153 final long identity = Binder.clearCallingIdentity();
5154 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005155 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005156 // This setting doesn't require an active ImsService connection, so do not verify. The
5157 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005158 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005159 } catch (ImsException e) {
5160 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005161 } finally {
5162 Binder.restoreCallingIdentity(identity);
5163 }
5164 }
5165
5166 @Override
5167 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5169 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005170
5171 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5172 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5173
Brad Ebinger35c841c2018-10-01 10:40:55 -07005174 final long identity = Binder.clearCallingIdentity();
5175 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005176 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005177 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005178 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005179 } catch (ImsException e) {
5180 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005181 } finally {
5182 Binder.restoreCallingIdentity(identity);
5183 }
5184 }
5185
shilu366312e2019-12-17 09:28:10 -08005186 /**
5187 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5188 * @param subId The subscription to use to check the configuration.
5189 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005190 @Override
5191 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005192 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005193 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005194
5195 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5196 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5197
Brad Ebinger35c841c2018-10-01 10:40:55 -07005198 final long identity = Binder.clearCallingIdentity();
5199 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005200 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005201 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005202 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005203 } catch (ImsException e) {
5204 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
5208 }
5209
5210 @Override
5211 public void setVoWiFiModeSetting(int subId, int mode) {
5212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5213 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005214
5215 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5216 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5217
Brad Ebinger35c841c2018-10-01 10:40:55 -07005218 final long identity = Binder.clearCallingIdentity();
5219 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005220 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005221 // This setting doesn't require an active ImsService connection, so do not verify. The
5222 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005223 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005224 } catch (ImsException e) {
5225 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
5229 }
5230
5231 @Override
5232 public int getVoWiFiRoamingModeSetting(int subId) {
5233 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005234
5235 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5236 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5237
Brad Ebinger35c841c2018-10-01 10:40:55 -07005238 final long identity = Binder.clearCallingIdentity();
5239 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005240 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005241 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005242 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005243 } catch (ImsException e) {
5244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005245 } finally {
5246 Binder.restoreCallingIdentity(identity);
5247 }
5248 }
5249
5250 @Override
5251 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5253 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005254
5255 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5256 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5257
Brad Ebinger35c841c2018-10-01 10:40:55 -07005258 final long identity = Binder.clearCallingIdentity();
5259 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005260 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005261 // This setting doesn't require an active ImsService connection, so do not verify. The
5262 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005263 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005264 } catch (ImsException e) {
5265 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005266 } finally {
5267 Binder.restoreCallingIdentity(identity);
5268 }
5269 }
5270
5271 @Override
5272 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5274 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005275
5276 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5277 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5278
Brad Ebinger35c841c2018-10-01 10:40:55 -07005279 final long identity = Binder.clearCallingIdentity();
5280 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005281 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005282 // This setting doesn't require an active ImsService connection, so do not verify. The
5283 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005284 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005285 } catch (ImsException e) {
5286 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005287 } finally {
5288 Binder.restoreCallingIdentity(identity);
5289 }
5290 }
5291
shilu366312e2019-12-17 09:28:10 -08005292 /**
5293 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5294 * @param subId The subscription to use to check the configuration.
5295 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005296 @Override
5297 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005298 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005299 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005300
5301 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5302 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5303
Brad Ebinger35c841c2018-10-01 10:40:55 -07005304 final long identity = Binder.clearCallingIdentity();
5305 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005306 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005307 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005308 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005309 } catch (ImsException e) {
5310 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
5314 }
5315
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005316 @Override
5317 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5318 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005319
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005320 final long identity = Binder.clearCallingIdentity();
5321 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005322 if (!isImsAvailableOnDevice()) {
5323 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5324 "IMS not available on device.");
5325 }
5326 int slotId = getSlotIndexOrException(subId);
5327 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005328
5329 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5330 if (controller != null) {
5331 ImsManager imsManager = controller.getImsManager(subId);
5332 if (imsManager != null) {
5333 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5334 } else {
5335 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5336 }
5337 } else {
5338 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5339 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005340 } catch (ImsException e) {
5341 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005342 } finally {
5343 Binder.restoreCallingIdentity(identity);
5344 }
5345 }
5346
5347 @Override
5348 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5349 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005350
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005351 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005352 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5353 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5354 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005355 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005356 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5357 if (controller != null) {
5358 ImsManager imsManager = controller.getImsManager(subId);
5359 if (imsManager != null) {
5360 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5361 } else {
5362 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5363 + " is inactive, ignoring unregister.");
5364 // If the ImsManager is not valid, just return, since the callback will already
5365 // have been removed internally.
5366 }
5367 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005368 } finally {
5369 Binder.restoreCallingIdentity(identity);
5370 }
5371 }
5372
joonhunshincffb7fc2021-11-28 07:32:01 +00005373 @Override
5374 public void registerFeatureProvisioningChangedCallback(int subId,
5375 IFeatureProvisioningCallback callback) {
5376 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5377 mApp, subId, "registerFeatureProvisioningChangedCallback");
5378
5379 final long identity = Binder.clearCallingIdentity();
5380 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5381 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5382 }
5383
joonhunshin91bc1952022-04-29 08:47:15 +00005384 try {
5385 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5386 if (controller == null) {
5387 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5388 "Device does not support IMS");
5389 }
5390 controller.addFeatureProvisioningChangedCallback(subId, callback);
5391 } finally {
5392 Binder.restoreCallingIdentity(identity);
5393 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005394 }
5395
5396 @Override
5397 public void unregisterFeatureProvisioningChangedCallback(int subId,
5398 IFeatureProvisioningCallback callback) {
5399 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5400 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5401
5402 final long identity = Binder.clearCallingIdentity();
5403 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5404 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5405 }
5406
joonhunshin91bc1952022-04-29 08:47:15 +00005407 try {
5408 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5409 if (controller == null) {
5410 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5411 return;
5412 }
5413 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005417 }
allenwtsu99c623b2020-01-03 18:24:23 +08005418
5419 private void checkModifyPhoneStatePermission(int subId, String message) {
5420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5421 message);
5422 }
5423
allenwtsu99c623b2020-01-03 18:24:23 +08005424 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005425 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005426 boolean isProvisioned) {
5427 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5428
joonhunshin4ac60942023-11-15 15:23:39 +00005429 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5430 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5431
allenwtsu99c623b2020-01-03 18:24:23 +08005432 final long identity = Binder.clearCallingIdentity();
5433 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005434 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5435 if (controller == null) {
5436 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5437 return;
5438 }
5439 controller.setRcsProvisioningStatusForCapability(
5440 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005441 } finally {
5442 Binder.restoreCallingIdentity(identity);
5443 }
allenwtsu99c623b2020-01-03 18:24:23 +08005444 }
5445
5446
5447 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005448 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5449 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5450 mApp, subId, "getRcsProvisioningStatusForCapability");
5451
joonhunshin4ac60942023-11-15 15:23:39 +00005452 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5453 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5454
allenwtsu99c623b2020-01-03 18:24:23 +08005455 final long identity = Binder.clearCallingIdentity();
5456 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005457 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5458 if (controller == null) {
5459 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5460
5461 // device does not support IMS, this method will return true always.
5462 return true;
5463 }
5464 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005465 } finally {
5466 Binder.restoreCallingIdentity(identity);
5467 }
5468 }
5469
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005470 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005471 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5472 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005473 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005474
joonhunshin4ac60942023-11-15 15:23:39 +00005475 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5476 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5477
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005478 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005479 final long identity = Binder.clearCallingIdentity();
5480 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005481 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5482 if (controller == null) {
5483 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5484 return;
5485 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005486 controller.setImsProvisioningStatusForCapability(displayPackageName,
joonhunshin91bc1952022-04-29 08:47:15 +00005487 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005488 } finally {
5489 Binder.restoreCallingIdentity(identity);
5490 }
5491 }
5492
5493 @Override
5494 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005495 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5496 mApp, subId, "getProvisioningStatusForCapability");
5497
joonhunshin4ac60942023-11-15 15:23:39 +00005498 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5499 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5500
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005501 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005502 final long identity = Binder.clearCallingIdentity();
5503 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005504 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5505 if (controller == null) {
5506 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005507
joonhunshin91bc1952022-04-29 08:47:15 +00005508 // device does not support IMS, this method will return true always.
5509 return true;
5510 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005511 return controller.getImsProvisioningStatusForCapability(displayPackageName,
5512 subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005513 } finally {
5514 Binder.restoreCallingIdentity(identity);
5515 }
5516 }
5517
5518 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005519 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5520 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5521 mApp, subId, "isProvisioningRequiredForCapability");
5522
joonhunshin4ac60942023-11-15 15:23:39 +00005523 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5524 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5525
joonhunshincffb7fc2021-11-28 07:32:01 +00005526 final long identity = Binder.clearCallingIdentity();
5527 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005528 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5529 if (controller == null) {
5530 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5531
5532 // device does not support IMS, this method will return false
5533 return false;
5534 }
5535 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005536 } finally {
5537 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005538 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005539 }
5540
5541 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005542 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5543 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5544 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005545
joonhunshin4ac60942023-11-15 15:23:39 +00005546 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5547 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5548
joonhunshincffb7fc2021-11-28 07:32:01 +00005549 final long identity = Binder.clearCallingIdentity();
5550 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005551 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5552 if (controller == null) {
5553 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5554
5555 // device does not support IMS, this method will return false
5556 return false;
5557 }
5558 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005559 } finally {
5560 Binder.restoreCallingIdentity(identity);
5561 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005562 }
5563
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005564 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005565 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005566 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5567 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5568 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005569 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5570 mApp, subId, "getImsProvisioningInt");
5571
joonhunshin4ac60942023-11-15 15:23:39 +00005572 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5573 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5574
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005575 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005576 final long identity = Binder.clearCallingIdentity();
5577 try {
5578 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005579 int slotId = getSlotIndex(subId);
5580 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5581 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5582 + subId + "' for key:" + key);
5583 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5584 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005585
joonhunshin91bc1952022-04-29 08:47:15 +00005586 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5587 if (controller == null) {
5588 loge("getImsProvisioningInt: Device does not support IMS");
5589
5590 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5591 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5592 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005593 int retVal = controller.getProvisioningValue(displayPackageName, subId,
5594 key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005595 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5596 return retVal;
5597 }
5598
calvinpanb5a34062021-02-08 19:59:36 +08005599 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005600 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005601 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5602 + subId + "' for key:" + key);
5603 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005604 } finally {
5605 Binder.restoreCallingIdentity(identity);
5606 }
5607 }
5608
5609 @Override
5610 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005611 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5612 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5613 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005614 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5615 mApp, subId, "getImsProvisioningString");
5616
joonhunshin4ac60942023-11-15 15:23:39 +00005617 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5618 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5619
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005620 final long identity = Binder.clearCallingIdentity();
5621 try {
5622 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005623 int slotId = getSlotIndex(subId);
5624 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5625 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5626 + subId + "' for key:" + key);
5627 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5628 }
calvinpanb5a34062021-02-08 19:59:36 +08005629 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005630 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005631 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5632 + subId + "' for key:" + key);
5633 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
5637 }
5638
5639 @Override
5640 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5642 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5643 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5645 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005646
joonhunshin4ac60942023-11-15 15:23:39 +00005647 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5648 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5649
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005650 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005651 final long identity = Binder.clearCallingIdentity();
5652 try {
5653 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005654 int slotId = getSlotIndex(subId);
5655 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5656 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5657 + subId + "' for key:" + key);
5658 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5659 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005660
joonhunshin91bc1952022-04-29 08:47:15 +00005661 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5662 if (controller == null) {
5663 loge("setImsProvisioningInt: Device does not support IMS");
5664
5665 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5666 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5667 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005668 int retVal = controller.setProvisioningValue(displayPackageName, subId, key,
5669 value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005670 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5671 return retVal;
5672 }
5673
calvinpanb5a34062021-02-08 19:59:36 +08005674 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5675 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005676 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005677 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005678 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005679 } finally {
5680 Binder.restoreCallingIdentity(identity);
5681 }
5682 }
5683
5684 @Override
5685 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005686 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5687 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5688 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5690 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005691
5692 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5693 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5694
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005698 int slotId = getSlotIndex(subId);
5699 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5700 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5701 + subId + "' for key:" + key);
5702 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5703 }
calvinpanb5a34062021-02-08 19:59:36 +08005704 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5705 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005706 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005707 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005708 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
5712 }
5713
Brad Ebinger919631e2021-06-02 17:46:35 -07005714 /**
5715 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5716 * for the given slot ID or no ImsResolver instance has been created.
5717 * @param slotId The slot ID that the IMS service is created for.
5718 * @throws ImsException If there is no ImsService configured for this slot.
5719 */
5720 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5721 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5722 ImsFeature.FEATURE_MMTEL)) {
5723 throw new ImsException("This subscription does not support MMTEL over IMS",
5724 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5725 }
5726 }
5727
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005728 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005729 int slotId = SubscriptionManager.getSlotIndex(subId);
5730 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005731 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5732 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005733 }
5734 return slotId;
5735 }
5736
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005737 private int getSlotIndex(int subId) {
5738 int slotId = SubscriptionManager.getSlotIndex(subId);
5739 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5740 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5741 }
5742 return slotId;
5743 }
5744
Wink Saville36469e72014-06-11 15:17:00 -07005745 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005746 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005747 */
5748 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005749 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5750 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005751 try {
5752 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5753 } catch (SecurityException se) {
5754 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5755 throw new SecurityException("Package " + callingPackage + " does not belong to "
5756 + Binder.getCallingUid());
5757 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005758 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005759 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005760 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005761 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005762 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005763 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005764 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005765 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5766 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005767
joonhunshin4ac60942023-11-15 15:23:39 +00005768 enforceTelephonyFeatureWithException(callingPackage,
5769 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5770
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 final long identity = Binder.clearCallingIdentity();
5772 try {
5773 final Phone phone = getPhone(subId);
5774 if (phone != null) {
5775 return phone.getServiceState().getDataNetworkType();
5776 } else {
5777 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5778 }
5779 } finally {
5780 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005782 }
5783
5784 /**
5785 * Returns the data network type
5786 */
5787 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005788 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005789 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005790 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005791 }
5792
5793 /**
5794 * Returns the data network type for a subId
5795 */
5796 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005797 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5798 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005799 String functionName = "getDataNetworkTypeForSubscriber";
5800 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5801 mApp, functionName)) {
5802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5803 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5804 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5805 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005806 }
5807
joonhunshin4ac60942023-11-15 15:23:39 +00005808 enforceTelephonyFeatureWithException(callingPackage,
5809 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005811 final long identity = Binder.clearCallingIdentity();
5812 try {
5813 final Phone phone = getPhone(subId);
5814 if (phone != null) {
5815 return phone.getServiceState().getDataNetworkType();
5816 } else {
5817 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5818 }
5819 } finally {
5820 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005822 }
5823
5824 /**
Wink Saville36469e72014-06-11 15:17:00 -07005825 * Returns the Voice network type for a subId
5826 */
5827 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005828 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5829 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005830 String functionName = "getVoiceNetworkTypeForSubscriber";
5831 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5832 mApp, functionName)) {
5833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5834 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5835 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5836 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005837 }
5838
joonhunshin4ac60942023-11-15 15:23:39 +00005839 enforceTelephonyFeatureWithException(callingPackage,
5840 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 final Phone phone = getPhone(subId);
5845 if (phone != null) {
5846 return phone.getServiceState().getVoiceNetworkType();
5847 } else {
5848 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5849 }
5850 } finally {
5851 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005853 }
5854
5855 /**
5856 * @return true if a ICC card is present
5857 */
5858 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005859 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005860 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005861 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005862 }
5863
5864 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005865 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005866 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005867 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005868 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07005869 if (!mApp.getResources().getBoolean(
5870 com.android.internal.R.bool.config_force_phone_globals_creation)) {
5871 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5872 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5873 }
joonhunshin4ac60942023-11-15 15:23:39 +00005874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875 final long identity = Binder.clearCallingIdentity();
5876 try {
5877 final Phone phone = PhoneFactory.getPhone(slotIndex);
5878 if (phone != null) {
5879 return phone.getIccCard().hasIccCard();
5880 } else {
5881 return false;
5882 }
5883 } finally {
5884 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005885 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005886 }
5887
5888 /**
5889 * Return if the current radio is LTE on CDMA. This
5890 * is a tri-state return value as for a period of time
5891 * the mode may be unknown.
5892 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005893 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005894 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005895 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005896 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005897 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005898 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5899 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5900 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005901 }
5902
Sanket Padawe356d7632015-06-22 14:03:32 -07005903 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005904 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5905 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005906 try {
5907 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5908 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005909 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5910 }
5911
joonhunshin4ac60942023-11-15 15:23:39 +00005912 enforceTelephonyFeatureWithException(callingPackage,
5913 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 final long identity = Binder.clearCallingIdentity();
5916 try {
5917 final Phone phone = getPhone(subId);
5918 if (phone == null) {
5919 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5920 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005921 return TelephonyProperties.lte_on_cdma_device()
5922 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923 }
5924 } finally {
5925 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005926 }
Wink Saville36469e72014-06-11 15:17:00 -07005927 }
5928
Wink Saville36469e72014-06-11 15:17:00 -07005929 /**
5930 * {@hide}
5931 * Returns Default subId, 0 in the case of single standby.
5932 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005933 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005934 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005935 }
5936
Shishir Agrawala9f32182016-04-12 12:00:16 -07005937 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005938 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005939 }
5940
Wink Savilleb564aae2014-10-23 10:18:09 -07005941 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005942 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005943 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005944
Pengquan Menge92a50d2018-09-21 15:54:48 -07005945 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005946 return getSubscriptionManagerService().isActiveSubId(subId,
5947 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005948 }
5949
Ihab Awadf2177b72013-11-25 13:33:23 -08005950 /**
5951 * @see android.telephony.TelephonyManager.WifiCallingChoices
5952 */
5953 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 final long identity = Binder.clearCallingIdentity();
5955 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005956 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5958 getWhenToMakeWifiCallsDefaultPreference());
5959 } finally {
5960 Binder.restoreCallingIdentity(identity);
5961 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005962 }
5963
5964 /**
5965 * @see android.telephony.TelephonyManager.WifiCallingChoices
5966 */
5967 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 final long identity = Binder.clearCallingIdentity();
5969 try {
5970 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005971 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5973 } finally {
5974 Binder.restoreCallingIdentity(identity);
5975 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005976 }
5977
Sailesh Nepald1e68152013-12-12 19:08:02 -08005978 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005979 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005980 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005981 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005982
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005983 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5984 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5985 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005986 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005987 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005988 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005989 }
5990 return PhoneFactory.getPhone(phoneId);
5991 }
5992
Shishir Agrawal566b7612013-10-28 14:41:00 -07005993 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005994 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005995 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005996
Rambo Wanga1782702021-11-10 20:15:19 -08005997 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5998 /*message=*/ "iccOpenLogicalChannel");
5999
6000 if (DBG) log("iccOpenLogicalChannel: request=" + request);
6001 // Verify that the callingPackage in the request belongs to the calling UID
6002 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
6003
joonhunshin4ac60942023-11-15 15:23:39 +00006004 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6005 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
6006
Rambo Wanga1782702021-11-10 20:15:19 -08006007 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006008 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006009
Rambo Wanga1782702021-11-10 20:15:19 -08006010 private Phone getPhoneFromValidIccLogicalChannelRequest(
6011 @NonNull IccLogicalChannelRequest request, String message) {
6012 Phone phone;
6013 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6015 mApp, request.subId, message);
6016 phone = getPhoneFromSubId(request.subId);
6017 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6018 enforceModifyPermission();
6019 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6020 } else {
6021 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006022 }
Rambo Wanga1782702021-11-10 20:15:19 -08006023 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006024 }
6025
6026 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006027 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 final long identity = Binder.clearCallingIdentity();
6029 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006030 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006032 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6033 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006034 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6035 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 loge("The calling package is not allowed to access ISD-R.");
6037 throw new SecurityException(
6038 "The calling package is not allowed to access ISD-R.");
6039 }
Derek Tan740e1672017-06-27 14:56:27 -07006040 }
Derek Tan740e1672017-06-27 14:56:27 -07006041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006043 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6044 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 return response;
6046 } finally {
6047 Binder.restoreCallingIdentity(identity);
6048 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006049 }
6050
6051 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006052 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006053 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6054 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6055
Rambo Wanga1782702021-11-10 20:15:19 -08006056 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6057 /*message=*/"iccCloseLogicalChannel");
6058
6059 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6060
6061 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006062 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006063
Rambo Wanga1782702021-11-10 20:15:19 -08006064 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6065 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006066 // before this feature is enabled, this API should only return false if
6067 // the operation fails instead of throwing runtime exception for
6068 // backward-compatibility.
6069 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6070 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 final long identity = Binder.clearCallingIdentity();
6072 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006073 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006074 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075 }
Chen Xue9d737e2022-01-01 23:41:31 -08006076 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006077 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006078 Boolean success = false;
6079 if (result instanceof RuntimeException) {
6080 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006081 if (shouldThrowExceptionOnFailure) {
6082 throw (RuntimeException) result;
6083 } else {
6084 return false;
6085 }
Chen Xue9d737e2022-01-01 23:41:31 -08006086 } else if (result instanceof Boolean) {
6087 success = (Boolean) result;
6088 } else {
6089 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6090 }
Rambo Wanga1782702021-11-10 20:15:19 -08006091 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 return success;
6093 } finally {
6094 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006095 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006096 }
6097
6098 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006099 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006100 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6102 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006103
6104 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6105 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6106
Jordan Liu4c733742019-02-28 12:03:40 -08006107 if (DBG) {
6108 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6109 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6110 + p3 + " data=" + data);
6111 }
6112 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6113 command, p1, p2, p3, data);
6114 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006115
Jordan Liu4c733742019-02-28 12:03:40 -08006116 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006117 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006118 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006119 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006120
6121 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6122 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6123 "iccTransmitApduLogicalChannelBySlot");
6124
Jordan Liu4c733742019-02-28 12:03:40 -08006125 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006126 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006127 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6128 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006129 }
6130 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006131 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6132 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006133 }
6134
6135 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6136 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 final long identity = Binder.clearCallingIdentity();
6138 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006139 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 return "";
6141 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006144 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6145 null /* workSource */);
6146 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006147
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 // Append the returned status code to the end of the response payload.
6149 String s = Integer.toHexString(
6150 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6151 if (response.payload != null) {
6152 s = IccUtils.bytesToHexString(response.payload) + s;
6153 }
6154 return s;
6155 } finally {
6156 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006157 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006158 }
Jake Hambye994d462014-02-03 13:10:13 -08006159
Evan Charltonc66da362014-05-16 14:06:40 -07006160 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006161 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6162 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6164 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006166
6167 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6168 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6169
Jordan Liu4c733742019-02-28 12:03:40 -08006170 if (DBG) {
6171 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6172 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6173 }
6174 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6175 cla, command, p1, p2, p3, data);
6176 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006177
Jordan Liu4c733742019-02-28 12:03:40 -08006178 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006179 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006180 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006181 enforceModifyPermission();
6182 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006183
6184 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6185 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6186
Jordan Liu4c733742019-02-28 12:03:40 -08006187 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006188 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006189 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6190 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006191 }
6192
6193 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006194 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6195 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006196 }
6197
6198 // open APDU basic channel assuming the caller has sufficient permissions
6199 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6200 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006201 final long identity = Binder.clearCallingIdentity();
6202 try {
6203 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6204 && TextUtils.equals(ISDR_AID, data)) {
6205 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006206 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6207 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208 if (bestComponent == null
6209 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6210 loge("The calling package is not allowed to select ISD-R.");
6211 throw new SecurityException(
6212 "The calling package is not allowed to select ISD-R.");
6213 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006214 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006217 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6218 null /* workSource */);
6219 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006221 // Append the returned status code to the end of the response payload.
6222 String s = Integer.toHexString(
6223 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6224 if (response.payload != null) {
6225 s = IccUtils.bytesToHexString(response.payload) + s;
6226 }
6227 return s;
6228 } finally {
6229 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006230 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006231 }
6232
6233 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006234 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006235 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6237 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006238
joonhunshin4ac60942023-11-15 15:23:39 +00006239 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6240 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 final long identity = Binder.clearCallingIdentity();
6243 try {
6244 if (DBG) {
6245 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6246 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6247 }
6248
6249 IccIoResult response =
6250 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6251 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6252 subId);
6253
6254 if (DBG) {
6255 log("Exchange SIM_IO [R]" + response);
6256 }
6257
6258 byte[] result = null;
6259 int length = 2;
6260 if (response.payload != null) {
6261 length = 2 + response.payload.length;
6262 result = new byte[length];
6263 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6264 } else {
6265 result = new byte[length];
6266 }
6267
6268 result[length - 1] = (byte) response.sw2;
6269 result[length - 2] = (byte) response.sw1;
6270 return result;
6271 } finally {
6272 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006273 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006274 }
6275
Nathan Haroldb3014052017-01-25 15:57:32 -08006276 /**
6277 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6278 * on a particular subscription
6279 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006280 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6281 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006283 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006284 return null;
6285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286
joonhunshin4ac60942023-11-15 15:23:39 +00006287 enforceTelephonyFeatureWithException(callingPackage,
6288 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 final long identity = Binder.clearCallingIdentity();
6291 try {
6292 if (appType != TelephonyManager.APPTYPE_USIM
6293 && appType != TelephonyManager.APPTYPE_SIM) {
6294 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6295 return null;
6296 }
6297 Object response = sendRequest(
6298 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6299 if (response instanceof String[]) {
6300 return (String[]) response;
6301 }
yincheng zhao2737e882019-09-06 17:06:54 -07006302 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006304 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 } finally {
6306 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006307 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006308 }
6309
yincheng zhao2737e882019-09-06 17:06:54 -07006310 /**
6311 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6312 * subscription.
6313 *
6314 * @param subId the id of the subscription.
6315 * @param appType the uicc app type, must be USIM or SIM.
6316 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6317 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006318 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006319 * @return number of fplmns that is successfully written to the SIM.
6320 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006321 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6322 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6324 mApp, subId, "setForbiddenPlmns");
6325
joonhunshin4ac60942023-11-15 15:23:39 +00006326 enforceTelephonyFeatureWithException(callingPackage,
6327 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6328
yincheng zhao2737e882019-09-06 17:06:54 -07006329 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6330 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6331 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6332 }
6333 if (fplmns == null) {
6334 throw new IllegalArgumentException("Fplmn List provided is null");
6335 }
6336 for (String fplmn : fplmns) {
6337 if (!CellIdentity.isValidPlmn(fplmn)) {
6338 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6339 }
6340 }
6341 final long identity = Binder.clearCallingIdentity();
6342 try {
6343 Object response = sendRequest(
6344 CMD_SET_FORBIDDEN_PLMNS,
6345 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6346 subId);
6347 return (int) response;
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
6350 }
6351 }
6352
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006353 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006354 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6356 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006357
joonhunshin4ac60942023-11-15 15:23:39 +00006358 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6359 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361 final long identity = Binder.clearCallingIdentity();
6362 try {
6363 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6364 if (response.payload == null) {
6365 return "";
6366 }
Evan Charltonc66da362014-05-16 14:06:40 -07006367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 // Append the returned status code to the end of the response payload.
6369 String s = Integer.toHexString(
6370 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6371 s = IccUtils.bytesToHexString(response.payload) + s;
6372 return s;
6373 } finally {
6374 Binder.restoreCallingIdentity(identity);
6375 }
Evan Charltonc66da362014-05-16 14:06:40 -07006376 }
6377
Jake Hambye994d462014-02-03 13:10:13 -08006378 /**
6379 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6380 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6381 *
6382 * @param itemID the ID of the item to read
6383 * @return the NV item as a String, or null on error.
6384 */
6385 @Override
6386 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006387 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6389 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390
6391 final long identity = Binder.clearCallingIdentity();
6392 try {
6393 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006394 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006395 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6396 return value;
6397 } finally {
6398 Binder.restoreCallingIdentity(identity);
6399 }
Jake Hambye994d462014-02-03 13:10:13 -08006400 }
6401
6402 /**
6403 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6404 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6405 *
6406 * @param itemID the ID of the item to read
6407 * @param itemValue the value to write, as a String
6408 * @return true on success; false on any failure
6409 */
6410 @Override
6411 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006412 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6414 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415
6416 final long identity = Binder.clearCallingIdentity();
6417 try {
6418 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6419 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006420 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6422 return success;
6423 } finally {
6424 Binder.restoreCallingIdentity(identity);
6425 }
Jake Hambye994d462014-02-03 13:10:13 -08006426 }
6427
6428 /**
6429 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6430 * Used for device configuration by some CDMA operators.
6431 *
6432 * @param preferredRoamingList byte array containing the new PRL
6433 * @return true on success; false on any failure
6434 */
6435 @Override
6436 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6438 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439
6440 final long identity = Binder.clearCallingIdentity();
6441 try {
6442 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6443 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6444 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6445 return success;
6446 } finally {
6447 Binder.restoreCallingIdentity(identity);
6448 }
Jake Hambye994d462014-02-03 13:10:13 -08006449 }
6450
6451 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006452 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006453 * Used for device configuration by some CDMA operators.
6454 *
chen xu6dac5ab2018-10-26 17:39:23 -07006455 * @param slotIndex - device slot.
6456 *
Jake Hambye994d462014-02-03 13:10:13 -08006457 * @return true on success; false on any failure
6458 */
6459 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006460 public boolean resetModemConfig(int slotIndex) {
6461 Phone phone = PhoneFactory.getPhone(slotIndex);
6462 if (phone != null) {
6463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6464 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006465
joonhunshin4ac60942023-11-15 15:23:39 +00006466 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6467 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6468
chen xu6dac5ab2018-10-26 17:39:23 -07006469 final long identity = Binder.clearCallingIdentity();
6470 try {
6471 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6472 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6473 return success;
6474 } finally {
6475 Binder.restoreCallingIdentity(identity);
6476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477 }
chen xu6dac5ab2018-10-26 17:39:23 -07006478 return false;
6479 }
6480
6481 /**
6482 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6483 *
6484 * @param slotIndex - device slot.
6485 *
6486 * @return true on success; false on any failure
6487 */
6488 @Override
6489 public boolean rebootModem(int slotIndex) {
6490 Phone phone = PhoneFactory.getPhone(slotIndex);
6491 if (phone != null) {
6492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6493 mApp, phone.getSubId(), "rebootModem");
6494
joonhunshin4ac60942023-11-15 15:23:39 +00006495 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6496 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6497
chen xu6dac5ab2018-10-26 17:39:23 -07006498 final long identity = Binder.clearCallingIdentity();
6499 try {
6500 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6501 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6502 return success;
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
6506 }
6507 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006508 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006509
Brad Ebinger51f743a2017-01-23 13:50:20 -08006510 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006511 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6512 * {@link #disableIms(int)}.
6513 * @param slotIndex device slot.
6514 */
6515 public void resetIms(int slotIndex) {
6516 enforceModifyPermission();
6517
joonhunshin4ac60942023-11-15 15:23:39 +00006518 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6519 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6520
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006521 final long identity = Binder.clearCallingIdentity();
6522 try {
6523 if (mImsResolver == null) {
6524 // may happen if the does not support IMS.
6525 return;
6526 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006527 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
6531 }
6532
6533 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006534 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6535 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006536 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006537 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006538 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539
6540 final long identity = Binder.clearCallingIdentity();
6541 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006542 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006543 // may happen if the device does not support IMS.
6544 return;
6545 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006546 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547 } finally {
6548 Binder.restoreCallingIdentity(identity);
6549 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006550 }
6551
6552 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006553 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6554 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006555 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006556 public void disableIms(int slotId) {
6557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558
6559 final long identity = Binder.clearCallingIdentity();
6560 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006561 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006562 // may happen if the device does not support IMS.
6563 return;
6564 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006565 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 } finally {
6567 Binder.restoreCallingIdentity(identity);
6568 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006569 }
6570
6571 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006572 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6573 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006574 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006575 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006576 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006577 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578
6579 final long identity = Binder.clearCallingIdentity();
6580 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006581 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006582 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6583 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006584 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006585 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 } finally {
6587 Binder.restoreCallingIdentity(identity);
6588 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006589 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006590 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006591 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6592 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006593 @Override
6594 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006595 enforceModifyPermission();
6596
6597 final long identity = Binder.clearCallingIdentity();
6598 try {
6599 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006600 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006601 } finally {
6602 Binder.restoreCallingIdentity(identity);
6603 }
6604 }
6605
6606 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006607 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006608 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006609 */
6610 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6611 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612
6613 final long identity = Binder.clearCallingIdentity();
6614 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006615 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006616 // may happen if the device does not support IMS.
6617 return null;
6618 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006619 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006620 } finally {
6621 Binder.restoreCallingIdentity(identity);
6622 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006623 }
6624
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006625 /**
6626 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006627 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006628 */
6629 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6630 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006631
6632 final long identity = Binder.clearCallingIdentity();
6633 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006634 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006635 // may happen if the device does not support IMS.
6636 return null;
6637 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006638 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 } finally {
6640 Binder.restoreCallingIdentity(identity);
6641 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006642 }
6643
Brad Ebinger884c07b2018-02-15 16:17:40 -08006644 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006645 * Sets the ImsService Package Name that Telephony will bind to.
6646 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006647 * @param slotIndex the slot ID that the ImsService should bind for.
Brad Ebinger555ddec2024-11-04 13:46:31 -08006648 * @param userId the user ID that the ImsService should bind for or {@link UserHandle#USER_NULL}
6649 * if there is no preference.
Brad Ebinger24c29992019-12-05 13:03:21 -08006650 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006651 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006652 * @param featureTypes An integer array of feature types associated with a packageName.
6653 * @param packageName The name of the package that the current configuration will be replaced
6654 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006655 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006656 */
Brad Ebinger555ddec2024-11-04 13:46:31 -08006657 public boolean setBoundImsServiceOverride(int slotIndex, int userId, boolean isCarrierService,
Brad Ebinger24c29992019-12-05 13:03:21 -08006658 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006659 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006661 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663 final long identity = Binder.clearCallingIdentity();
6664 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006665 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006666 // may happen if the device does not support IMS.
6667 return false;
6668 }
Brad Ebinger555ddec2024-11-04 13:46:31 -08006669 return mImsResolver.overrideImsServiceConfiguration(packageName, slotIndex, userId,
6670 isCarrierService, featureTypes);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006671 } finally {
6672 Binder.restoreCallingIdentity(identity);
6673 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006674 }
6675
6676 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006677 * Clears any carrier ImsService overrides for the slot index specified that were previously
6678 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6679 *
6680 * This should only be used for testing.
6681 *
6682 * @param slotIndex the slot ID that the ImsService should bind for.
6683 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6684 */
6685 @Override
6686 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006687 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6688 "clearCarrierImsServiceOverride");
6689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006690 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006691
6692 final long identity = Binder.clearCallingIdentity();
6693 try {
6694 if (mImsResolver == null) {
6695 // may happen if the device does not support IMS.
6696 return false;
6697 }
6698 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6699 } finally {
6700 Binder.restoreCallingIdentity(identity);
6701 }
6702 }
6703
6704 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006705 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006706 *
6707 * @param slotId The slot that the ImsService is associated with.
6708 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6709 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006710 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006711 * @return the package name of the ImsService configuration.
6712 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006713 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6714 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006715 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006716 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6717 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006719 final long identity = Binder.clearCallingIdentity();
6720 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006721 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006722 // may happen if the device does not support IMS.
6723 return "";
6724 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006725 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006726 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6727 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728 } finally {
6729 Binder.restoreCallingIdentity(identity);
6730 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006731 }
6732
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006733 /**
6734 * Get the MmTelFeature state associated with the requested subscription id.
6735 * @param subId The subscription that the MmTelFeature is associated with.
6736 * @param callback A callback with an integer containing the
6737 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6738 */
6739 @Override
6740 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6741 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006742 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6743 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6744 "IMS not available on device.");
6745 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006746 final long token = Binder.clearCallingIdentity();
6747 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006748 int slotId = getSlotIndex(subId);
6749 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6750 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6751 + subId + "'");
6752 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6753 }
6754 verifyImsMmTelConfiguredOrThrow(slotId);
6755 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6756 try {
6757 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6758 } catch (RemoteException e) {
6759 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6760 + "Ignore");
6761 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006762 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006763 } catch (ImsException e) {
6764 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006765 } finally {
6766 Binder.restoreCallingIdentity(token);
6767 }
6768 }
6769
Daniel Brightbb5840b2021-01-12 15:48:18 -08006770 /**
6771 * Sets the ims registration state on all valid {@link Phone}s.
6772 */
6773 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775
6776 final long identity = Binder.clearCallingIdentity();
6777 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006778 // NOTE: Before S, this method only set the default phone.
6779 for (final Phone phone : PhoneFactory.getPhones()) {
6780 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6781 phone.setImsRegistrationState(registered);
6782 }
6783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
Wink Saville36469e72014-06-11 15:17:00 -07006787 }
6788
6789 /**
Stuart Scott54788802015-03-30 13:18:01 -07006790 * Set the network selection mode to automatic.
6791 *
6792 */
6793 @Override
6794 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6796 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797
joonhunshin4ac60942023-11-15 15:23:39 +00006798 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6799 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801 final long identity = Binder.clearCallingIdentity();
6802 try {
shilufc958392020-01-20 11:36:01 -08006803 if (!isActiveSubscription(subId)) {
6804 return;
6805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006807 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
Nathan Harolddc3bcec2024-05-16 14:06:40 -07006808 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 } finally {
6810 Binder.restoreCallingIdentity(identity);
6811 }
Stuart Scott54788802015-03-30 13:18:01 -07006812 }
6813
Jack Yud10cdd42020-09-28 20:28:01 -07006814 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006815 * Ask the radio to connect to the input network and change selection mode to manual.
6816 *
6817 * @param subId the id of the subscription.
6818 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6819 * the operator to attach to.
6820 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6821 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6822 * normal network selection next time.
6823 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006824 */
6825 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006826 public boolean setNetworkSelectionModeManual(
6827 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6829 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006830
joonhunshin4ac60942023-11-15 15:23:39 +00006831 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6832 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6833
Jack Yu285100e2022-12-02 22:48:35 -08006834 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006835 if (!isActiveSubscription(subId)) {
6836 return false;
6837 }
6838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006840 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006842 if (DBG) {
6843 log("setNetworkSelectionModeManual: subId: " + subId
6844 + " operator: " + operatorInfo);
6845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006846 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6847 } finally {
6848 Binder.restoreCallingIdentity(identity);
6849 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006850 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006851 /**
shilu84f6e8b2019-12-19 13:58:01 -08006852 * Get the manual network selection
6853 *
6854 * @param subId the id of the subscription.
6855 *
6856 * @return the previously saved user selected PLMN
6857 */
6858 @Override
6859 public String getManualNetworkSelectionPlmn(int subId) {
6860 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006861 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6862 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006863
joonhunshin4ac60942023-11-15 15:23:39 +00006864 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6865 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6866
shilu84f6e8b2019-12-19 13:58:01 -08006867 final long identity = Binder.clearCallingIdentity();
6868 try {
6869 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006870 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006871 }
6872
6873 final Phone phone = getPhone(subId);
6874 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006875 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006876 }
6877 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6878 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006879 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006880 } finally {
6881 Binder.restoreCallingIdentity(identity);
6882 }
6883 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006884
6885 /**
6886 * Scans for available networks.
6887 */
6888 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006889 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6890 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6892 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006893 LocationAccessPolicy.LocationPermissionResult locationResult =
6894 LocationAccessPolicy.checkLocationPermission(mApp,
6895 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6896 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006897 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006898 .setCallingPid(Binder.getCallingPid())
6899 .setCallingUid(Binder.getCallingUid())
6900 .setMethod("getCellNetworkScanResults")
6901 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006902 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6903 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006904 .build());
6905 switch (locationResult) {
6906 case DENIED_HARD:
6907 throw new SecurityException("Not allowed to access scan results -- location");
6908 case DENIED_SOFT:
6909 return null;
6910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911
Pengquan Menga1bb6272018-09-06 09:59:22 -07006912 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913 try {
6914 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006915 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006917 } finally {
6918 Binder.restoreCallingIdentity(identity);
6919 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006920 }
6921
6922 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006923 * Get the call forwarding info, given the call forwarding reason.
6924 */
6925 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006926 public void getCallForwarding(int subId, int callForwardingReason,
6927 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006928 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006929
6930 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6931 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6932
Shuo Qian4a594052020-01-23 11:59:30 -08006933 long identity = Binder.clearCallingIdentity();
6934 try {
6935 if (DBG) {
6936 log("getCallForwarding: subId " + subId
6937 + " callForwardingReason" + callForwardingReason);
6938 }
Hall Liu27d24262020-09-18 19:04:59 -07006939
6940 Phone phone = getPhone(subId);
6941 if (phone == null) {
6942 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006943 callback.onError(
6944 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006945 } catch (RemoteException e) {
6946 // ignore
6947 }
6948 return;
6949 }
6950
6951 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6952 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6953 @Override
6954 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6955 try {
6956 callback.onCallForwardingInfoAvailable(info);
6957 } catch (RemoteException e) {
6958 // ignore
6959 }
6960 }
6961
6962 @Override
6963 public void onError(int error) {
6964 try {
6965 callback.onError(error);
6966 } catch (RemoteException e) {
6967 // ignore
6968 }
6969 }
6970 });
6971 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006972 } finally {
6973 Binder.restoreCallingIdentity(identity);
6974 }
6975 }
6976
6977 /**
6978 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6979 * reason, the number to forward, and the timeout before the forwarding is attempted.
6980 */
6981 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006982 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6983 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006984 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006985
6986 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6987 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6988
Shuo Qian4a594052020-01-23 11:59:30 -08006989 long identity = Binder.clearCallingIdentity();
6990 try {
6991 if (DBG) {
6992 log("setCallForwarding: subId " + subId
6993 + " callForwardingInfo" + callForwardingInfo);
6994 }
Hall Liu27d24262020-09-18 19:04:59 -07006995
6996 Phone phone = getPhone(subId);
6997 if (phone == null) {
6998 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006999 callback.accept(
7000 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007001 } catch (RemoteException e) {
7002 // ignore
7003 }
7004 return;
7005 }
7006
7007 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7008 FunctionalUtils.ignoreRemoteException(callback::accept));
7009
7010 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007011 } finally {
7012 Binder.restoreCallingIdentity(identity);
7013 }
7014 }
7015
7016 /**
Hall Liu27d24262020-09-18 19:04:59 -07007017 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007018 */
7019 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007020 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007021 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007022
7023 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7024 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7025
Shuo Qian4a594052020-01-23 11:59:30 -08007026 long identity = Binder.clearCallingIdentity();
7027 try {
Hall Liu27d24262020-09-18 19:04:59 -07007028 Phone phone = getPhone(subId);
7029 if (phone == null) {
7030 try {
7031 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7032 } catch (RemoteException e) {
7033 // ignore
7034 }
7035 return;
7036 }
SongFerngWang0e767992021-03-31 22:08:45 +08007037 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7038 PersistableBundle c = configManager.getConfigForSubId(subId);
7039 boolean requireUssd = c.getBoolean(
7040 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007041
Shuo Qian4a594052020-01-23 11:59:30 -08007042 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007043 if (requireUssd) {
7044 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7045 getSubscriptionCarrierId(subId));
7046 String newUssdCommand = "";
7047 try {
7048 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007049 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007050 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7051 } catch (NullPointerException e) {
7052 loge("Failed to generate USSD number" + e);
7053 }
7054 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7055 mMainThreadHandler, callback, carrierXmlParser,
7056 CarrierXmlParser.SsEntry.SSAction.QUERY);
7057 final String ussdCommand = newUssdCommand;
7058 Executors.newSingleThreadExecutor().execute(() -> {
7059 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7060 });
7061 } else {
7062 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7063 callback::accept);
7064 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7065 }
Shuo Qian4a594052020-01-23 11:59:30 -08007066 } finally {
7067 Binder.restoreCallingIdentity(identity);
7068 }
7069 }
7070
7071 /**
Hall Liu27d24262020-09-18 19:04:59 -07007072 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007073 */
7074 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007075 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007076 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007077
7078 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7079 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7080
Shuo Qian4a594052020-01-23 11:59:30 -08007081 long identity = Binder.clearCallingIdentity();
7082 try {
Hall Liu27d24262020-09-18 19:04:59 -07007083 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7084
7085 Phone phone = getPhone(subId);
7086 if (phone == null) {
7087 try {
7088 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7089 } catch (RemoteException e) {
7090 // ignore
7091 }
7092 return;
7093 }
7094
SongFerngWang0e767992021-03-31 22:08:45 +08007095 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7096 PersistableBundle c = configManager.getConfigForSubId(subId);
7097 boolean requireUssd = c.getBoolean(
7098 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007099
SongFerngWang0e767992021-03-31 22:08:45 +08007100 if (DBG) log("getCallWaitingStatus: subId " + subId);
7101 if (requireUssd) {
7102 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7103 getSubscriptionCarrierId(subId));
7104 CarrierXmlParser.SsEntry.SSAction ssAction =
7105 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7106 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7107 String newUssdCommand = "";
7108 try {
7109 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007110 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007111 .makeCommand(ssAction, null);
7112 } catch (NullPointerException e) {
7113 loge("Failed to generate USSD number" + e);
7114 }
7115 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7116 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7117 final String ussdCommand = newUssdCommand;
7118 Executors.newSingleThreadExecutor().execute(() -> {
7119 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7120 });
7121 } else {
7122 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7123 FunctionalUtils.ignoreRemoteException(callback::accept));
7124
7125 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7126 }
Shuo Qian4a594052020-01-23 11:59:30 -08007127 } finally {
7128 Binder.restoreCallingIdentity(identity);
7129 }
7130 }
7131
7132 /**
yinxub1bed742017-04-17 11:45:04 -07007133 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007134 *
yinxub1bed742017-04-17 11:45:04 -07007135 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007136 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7137 * location related information which will be sent if the caller already possess
7138 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007139 * @param request contains the radio access networks with bands/channels to scan
7140 * @param messenger callback messenger for scan results or errors
7141 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007142 * @return the id of the requested scan which can be used to stop the scan.
7143 */
7144 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007145 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7146 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007147 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7149 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007150 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007151 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7152 if (!renounceFineLocationAccess) {
7153 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007154 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7155 .setCallingPackage(callingPackage)
7156 .setCallingFeatureId(callingFeatureId)
7157 .setCallingPid(Binder.getCallingPid())
7158 .setCallingUid(Binder.getCallingUid())
7159 .setMethod("requestNetworkScan")
7160 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7161 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7162 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7163 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007164 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007165 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007166 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7167 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007168 if (e != null) {
7169 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7170 throw e;
7171 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007172 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007173 return TelephonyScanManager.INVALID_SCAN_ID;
7174 }
7175 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176 }
joonhunshin4ac60942023-11-15 15:23:39 +00007177
7178 enforceTelephonyFeatureWithException(callingPackage,
7179 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7180
Hall Liu912dfd32019-04-25 14:02:26 -07007181 int callingUid = Binder.getCallingUid();
7182 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007183 final long identity = Binder.clearCallingIdentity();
7184 try {
7185 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007186 renounceFineLocationAccess, request, messenger, binder,
7187 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007188 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007189 } finally {
7190 Binder.restoreCallingIdentity(identity);
7191 }
yinxu504e1392017-04-12 16:03:22 -07007192 }
7193
Hall Liub2ac8ef2019-02-28 15:56:23 -08007194 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007195 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007196 boolean hasCarrierPriv;
7197 final long identity = Binder.clearCallingIdentity();
7198 try {
7199 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7200 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7201 } finally {
7202 Binder.restoreCallingIdentity(identity);
7203 }
Hall Liu558027f2019-05-15 19:14:05 -07007204 boolean hasNetworkScanPermission =
7205 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007206 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007207
7208 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7209 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7210 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007211 }
7212
7213 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7214 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007215 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7216 return new SecurityException("Specific channels must not be"
7217 + " scanned without location access.");
7218 }
7219 }
7220 }
7221
Hall Liub2ac8ef2019-02-28 15:56:23 -08007222 return null;
7223 }
7224
yinxu504e1392017-04-12 16:03:22 -07007225 /**
7226 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007227 *
7228 * @param subId id of the subscription
7229 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007230 */
7231 @Override
7232 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7234 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235
Hall Liu912dfd32019-04-25 14:02:26 -07007236 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237 final long identity = Binder.clearCallingIdentity();
7238 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007239 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240 } finally {
7241 Binder.restoreCallingIdentity(identity);
7242 }
yinxu504e1392017-04-12 16:03:22 -07007243 }
7244
7245 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007246 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007247 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007248 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007249 */
7250 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007251 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007252 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007253 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007254 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255
joonhunshin4ac60942023-11-15 15:23:39 +00007256 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7257 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259 final long identity = Binder.clearCallingIdentity();
7260 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007261 if (DBG) log("getAllowedNetworkTypesBitmask");
7262 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7263 int networkTypesBitmask = (result != null ? result[0] : -1);
7264 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7265 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 } finally {
7267 Binder.restoreCallingIdentity(identity);
7268 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007269 }
7270
7271 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007272 * Get the allowed network types for certain reason.
7273 *
7274 * @param subId the id of the subscription.
7275 * @param reason the reason the allowed network type change is taking place
7276 * @return the allowed network types.
7277 */
7278 @Override
7279 public long getAllowedNetworkTypesForReason(int subId,
7280 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007281 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007282 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007283
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007284 if (!mApp.getResources().getBoolean(
7285 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7286 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7287 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7288 "getAllowedNetworkTypesForReason");
7289 }
joonhunshin4ac60942023-11-15 15:23:39 +00007290
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007291 final long identity = Binder.clearCallingIdentity();
7292 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007293 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007294 } finally {
7295 Binder.restoreCallingIdentity(identity);
7296 }
7297 }
7298
7299 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007300 * Enable/Disable E-UTRA-NR Dual Connectivity
7301 * @param subId subscription id of the sim card
7302 * @param nrDualConnectivityState expected NR dual connectivity state
7303 * This can be passed following states
7304 * <ol>
7305 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7306 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7307 * <li>Disable NR dual connectivity and force secondary cell to be released
7308 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7309 * </ol>
7310 * @return operation result.
7311 */
7312 @Override
7313 public int setNrDualConnectivityState(int subId,
7314 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7316 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007317 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007318 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7319 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7320 }
7321
Sooraj Sasindran37444802020-08-11 10:40:43 -07007322 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7323 final long identity = Binder.clearCallingIdentity();
7324 try {
7325 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7326 nrDualConnectivityState, subId,
7327 workSource);
7328 if (DBG) log("enableNRDualConnectivity result: " + result);
7329 return result;
7330 } finally {
7331 Binder.restoreCallingIdentity(identity);
7332 }
7333 }
7334
7335 /**
7336 * Is E-UTRA-NR Dual Connectivity enabled
7337 * @return true if dual connectivity is enabled else false
7338 */
7339 @Override
7340 public boolean isNrDualConnectivityEnabled(int subId) {
7341 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007342 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007343 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007344 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007345 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7346 return false;
7347 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007348 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7349 final long identity = Binder.clearCallingIdentity();
7350 try {
7351 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7352 null, subId, workSource);
7353 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7354 return isEnabled;
7355 } finally {
7356 Binder.restoreCallingIdentity(identity);
7357 }
7358 }
7359
7360 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007361 * Set the allowed network types of the device and
7362 * provide the reason triggering the allowed network change.
7363 *
7364 * @param subId the id of the subscription.
7365 * @param reason the reason the allowed network type change is taking place
7366 * @param allowedNetworkTypes the allowed network types.
7367 * @return true on success; false on any failure.
7368 */
7369 @Override
7370 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007371 @TelephonyManager.AllowedNetworkTypesReason int reason,
7372 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7374 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007375 // If the caller only has carrier privileges, then they should not be able to override
7376 // any network types which were set for security reasons.
7377 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7378 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007379 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007380 throw new SecurityException(
7381 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007382 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007383 }
joonhunshin4ac60942023-11-15 15:23:39 +00007384
7385 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7386 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7387
SongFerngWang3ef3e072020-12-21 16:41:52 +08007388 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007389 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007390 return false;
7391 }
7392 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7393 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007394 return false;
7395 }
7396
Jack Yu5b494332023-01-23 18:18:04 +00007397 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7398 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007399
Jack Yue37dd262022-12-16 11:53:37 -08007400 Phone phone = getPhone(subId);
7401 if (phone == null) {
7402 return false;
7403 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007404
Jack Yue37dd262022-12-16 11:53:37 -08007405 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007406 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007407 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007408 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007409
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007410 final long identity = Binder.clearCallingIdentity();
7411 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007412 Boolean success = (Boolean) sendRequest(
7413 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7414 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7415
7416 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7417 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007418 } finally {
7419 Binder.restoreCallingIdentity(identity);
7420 }
7421 }
7422
7423 /**
Miaoa84611c2019-03-15 09:21:10 +08007424 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007425 *
Miaoa84611c2019-03-15 09:21:10 +08007426 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007427 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007428 * @hide
7429 */
7430 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007431 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007432 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007433
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07007434 if (!mApp.getResources().getBoolean(
7435 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7436 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7437 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7438 }
joonhunshin4ac60942023-11-15 15:23:39 +00007439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007441 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442 try {
Miaoa84611c2019-03-15 09:21:10 +08007443 if (phone != null) {
7444 return phone.hasMatchedTetherApnSetting();
7445 } else {
7446 return false;
7447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448 } finally {
7449 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007450 }
Junda Liu475951f2014-11-07 16:45:03 -08007451 }
7452
7453 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007454 * Get the user enabled state of Mobile Data.
7455 *
7456 * TODO: remove and use isUserDataEnabled.
7457 * This can't be removed now because some vendor codes
7458 * calls through ITelephony directly while they should
7459 * use TelephonyManager.
7460 *
7461 * @return true on enabled
7462 */
7463 @Override
7464 public boolean getDataEnabled(int subId) {
7465 return isUserDataEnabled(subId);
7466 }
7467
7468 /**
7469 * Get whether mobile data is enabled per user setting.
7470 *
7471 * There are other factors deciding whether mobile data is actually enabled, but they are
7472 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007473 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007474 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7475 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007476 *
7477 * @return {@code true} if data is enabled else {@code false}
7478 */
7479 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007480 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007481 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007482 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007483 try {
7484 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7485 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007486 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007487 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7488 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007489 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007491 mApp, subId, functionName);
7492
Robert Greenwalt646120a2014-05-23 11:54:03 -07007493 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494
7495 final long identity = Binder.clearCallingIdentity();
7496 try {
Jack Yu285100e2022-12-02 22:48:35 -08007497 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7499 Phone phone = PhoneFactory.getPhone(phoneId);
7500 if (phone != null) {
7501 boolean retVal = phone.isUserDataEnabled();
7502 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7503 return retVal;
7504 } else {
7505 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7506 return false;
7507 }
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007510 }
7511 }
7512
7513 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007514 * Checks if the device is capable of mobile data by considering whether whether the
7515 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7516 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007517 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007518 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007519 */
7520 @Override
7521 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007522 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007523 try {
7524 try {
7525 mApp.enforceCallingOrSelfPermission(
7526 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007527 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007528 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007529 try {
7530 mApp.enforceCallingOrSelfPermission(
7531 android.Manifest.permission.READ_PHONE_STATE,
7532 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007533 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007534 mApp.enforceCallingOrSelfPermission(
7535 permission.READ_BASIC_PHONE_STATE, functionName);
7536 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007537 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007538 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007539 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007540 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541
joonhunshin4ac60942023-11-15 15:23:39 +00007542 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7543 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 final long identity = Binder.clearCallingIdentity();
7546 try {
Jack Yu285100e2022-12-02 22:48:35 -08007547 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007549 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007550 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007551 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 return retVal;
7553 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007554 if (DBG) {
7555 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7556 + subId + " retVal=false");
7557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 return false;
7559 }
7560 } finally {
7561 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007562 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007563 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007564
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007565 /**
7566 * Check if data is enabled for a specific reason
7567 * @param subId Subscription index
7568 * @param reason the reason the data enable change is taking place
7569 * @return {@code true} if the overall data is enabled; {@code false} if not.
7570 */
7571 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007572 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007573 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007574 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007575 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007576 try {
7577 mApp.enforceCallingOrSelfPermission(
7578 android.Manifest.permission.ACCESS_NETWORK_STATE,
7579 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007580 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007581 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7582 functionName);
7583 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007584 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007585 try {
7586 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007587 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007588 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007590 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007591 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007592 }
7593
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007594 if (!mApp.getResources().getBoolean(
7595 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7596 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7597 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
7598 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007599
7600 final long identity = Binder.clearCallingIdentity();
7601 try {
Jack Yu285100e2022-12-02 22:48:35 -08007602 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007603 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007604 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007605 + " reason=" + reason);
7606 }
7607 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007608 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007609 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007610 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007611 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007612 return retVal;
7613 } else {
7614 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007615 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007616 + subId + " retVal=false");
7617 }
7618 return false;
7619 }
7620 } finally {
7621 Binder.restoreCallingIdentity(identity);
7622 }
7623 }
7624
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007625 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007626 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007627 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7628 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7629
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007630 // No permission needed; this only lets the caller inspect their own status.
7631 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007632 }
Junda Liu29340342014-07-10 15:23:27 -07007633
7634 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007635 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007636 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007637
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007638 if (!mApp.getResources().getBoolean(
7639 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7640 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7641 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7642 "getCarrierPrivilegeStatusForUid");
7643 }
joonhunshin4ac60942023-11-15 15:23:39 +00007644
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007645 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7646 }
7647
7648 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7649 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007650 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007651 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007652 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7653 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007654 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7655 if (cpt == null) {
7656 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007657 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7658 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007659 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007660 }
7661
7662 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007663 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007664 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007665
7666 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7667 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7668
chen xuf7e9fe82019-05-09 19:31:02 -07007669 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007670 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007671 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007672 Phone phone = getPhone(subId);
7673 if (phone == null) {
7674 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7675 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7676 }
7677 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7678 if (cpt == null) {
7679 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007680 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7681 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007682 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007683 }
7684
7685 @Override
7686 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007687 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007688
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007689 if (!mApp.getResources().getBoolean(
7690 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7691 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7692 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7693 "checkCarrierPrivilegesForPackageAnyPhone");
7694 }
joonhunshin4ac60942023-11-15 15:23:39 +00007695
Rambo Wange7209ce2022-02-23 13:41:02 -08007696 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7697 }
7698
7699 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007700 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007701 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007702 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007703 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007704 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7705 Phone phone = PhoneFactory.getPhone(phoneId);
7706 if (phone == null) {
7707 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007708 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007709 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7710 if (cpt == null) {
7711 continue;
7712 }
7713 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007714 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7715 break;
7716 }
7717 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007718 return result;
Junda Liu29340342014-07-10 15:23:27 -07007719 }
Derek Tan89e89d42014-07-08 17:00:10 -07007720
7721 @Override
Junda Liue64de782015-04-16 17:19:16 -07007722 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007723 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007724
7725 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7726 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7727 "getCarrierPackageNamesForIntentAndPhone");
7728
Rambo Wang8a247eb2022-02-08 21:11:18 +00007729 Phone phone = PhoneFactory.getPhone(phoneId);
7730 if (phone == null) {
7731 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007732 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007733 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7734 if (cpt == null) {
7735 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007736 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007737 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007738 }
7739
Amith Yamasani6e118872016-02-19 12:53:51 -08007740 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007741 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007742 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Yan Yan965c84f2024-09-24 18:14:17 -07007743
7744 enforceTelephonyFeatureWithException(
7745 getCurrentPackageName(),
7746 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7747 "getPackagesWithCarrierPrivileges");
7748
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007749 Phone phone = PhoneFactory.getPhone(phoneId);
7750 if (phone == null) {
7751 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007752 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007753 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7754 if (cpt == null) {
7755 return Collections.emptyList();
7756 }
7757 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007758 }
7759
chen xuf7e9fe82019-05-09 19:31:02 -07007760 @Override
7761 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007762 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007763
7764 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7765 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7766 "getPackagesWithCarrierPrivilegesForAllPhones");
7767
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007768 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007769 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007770 try {
7771 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7772 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7773 }
7774 } finally {
7775 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007776 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007777 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007778 }
7779
Rambo Wang6812ffb2022-03-15 16:54:17 -07007780 @Override
7781 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7782 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7783
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007784 if (!mApp.getResources().getBoolean(
7785 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7786 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7787 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7788 "getCarrierServicePackageNameForLogicalSlot");
7789 }
joonhunshin4ac60942023-11-15 15:23:39 +00007790
Rambo Wang6812ffb2022-03-15 16:54:17 -07007791 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7792 if (phone == null) {
7793 return null;
7794 }
7795 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7796 if (cpt == null) {
7797 return null;
7798 }
7799 return cpt.getCarrierServicePackageName();
7800 }
7801
Wink Savilleb564aae2014-10-23 10:18:09 -07007802 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007803 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007804 UiccPort port = phone == null ? null : phone.getUiccPort();
7805 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007806 return null;
7807 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007808 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007809 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007810 return null;
7811 }
7812 return iccId;
7813 }
7814
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007815 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007816 public void setCallComposerStatus(int subId, int status) {
7817 enforceModifyPermission();
7818
joonhunshin4ac60942023-11-15 15:23:39 +00007819 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7820 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7821
Shuo Qiane4e11672020-12-15 22:15:33 -08007822 final long identity = Binder.clearCallingIdentity();
7823 try {
7824 Phone phone = getPhone(subId);
7825 if (phone != null) {
7826 Phone defaultPhone = phone.getImsPhone();
7827 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7828 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7829 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007830 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7831 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007832 }
7833 }
Shuo Qian284ae752020-12-22 19:10:14 -08007834 } catch (ImsException e) {
7835 throw new ServiceSpecificException(e.getCode());
7836 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007837 Binder.restoreCallingIdentity(identity);
7838 }
7839 }
7840
7841 @Override
7842 public int getCallComposerStatus(int subId) {
7843 enforceReadPrivilegedPermission("getCallComposerStatus");
7844
joonhunshin4ac60942023-11-15 15:23:39 +00007845 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7846 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7847
Shuo Qiane4e11672020-12-15 22:15:33 -08007848 final long identity = Binder.clearCallingIdentity();
7849 try {
7850 Phone phone = getPhone(subId);
7851 if (phone != null) {
7852 Phone defaultPhone = phone.getImsPhone();
7853 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7854 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7855 return imsPhone.getCallComposerStatus();
7856 }
7857 }
7858 } finally {
7859 Binder.restoreCallingIdentity(identity);
7860 }
7861 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7862 }
7863
7864 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007865 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7866 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007867 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007868 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007869
joonhunshin4ac60942023-11-15 15:23:39 +00007870 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7871 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7872 "setLine1NumberForDisplayForSubscriber");
7873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007874 final long identity = Binder.clearCallingIdentity();
7875 try {
7876 final String iccId = getIccId(subId);
7877 final Phone phone = getPhone(subId);
7878 if (phone == null) {
7879 return false;
7880 }
arunvoddub1365e62024-07-31 09:42:31 +00007881 if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) {
7882 Rlog.e(LOG_TAG, "Number is too long");
7883 return false;
7884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885 final String subscriberId = phone.getSubscriberId();
7886
7887 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007888 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007889 + subscriberId + " to " + number);
7890 }
7891
7892 if (TextUtils.isEmpty(iccId)) {
7893 return false;
7894 }
7895
7896 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7897
7898 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7899 if (alphaTag == null) {
7900 editor.remove(alphaTagPrefKey);
7901 } else {
7902 editor.putString(alphaTagPrefKey, alphaTag);
7903 }
7904
7905 // Record both the line number and IMSI for this ICCID, since we need to
7906 // track all merged IMSIs based on line number
7907 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7908 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7909 if (number == null) {
7910 editor.remove(numberPrefKey);
7911 editor.remove(subscriberPrefKey);
7912 } else {
7913 editor.putString(numberPrefKey, number);
7914 editor.putString(subscriberPrefKey, subscriberId);
7915 }
7916
7917 editor.commit();
7918 return true;
7919 } finally {
7920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007921 }
Derek Tan7226c842014-07-02 17:42:23 -07007922 }
7923
7924 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007925 public String getLine1NumberForDisplay(int subId, String callingPackage,
7926 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007927 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007929 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007930 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007931 return null;
7932 }
Derek Tan97ebb422014-09-05 16:55:38 -07007933
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007934 if (!mApp.getResources().getBoolean(
7935 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7936 enforceTelephonyFeatureWithException(callingPackage,
7937 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7938 }
joonhunshin4ac60942023-11-15 15:23:39 +00007939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007940 final long identity = Binder.clearCallingIdentity();
7941 try {
7942 String iccId = getIccId(subId);
7943 if (iccId != null) {
7944 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7945 if (DBG_MERGE) {
7946 log("getLine1NumberForDisplay returning "
7947 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7948 }
7949 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7952 return null;
7953 } finally {
7954 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007955 }
Derek Tan7226c842014-07-02 17:42:23 -07007956 }
7957
7958 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007959 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7960 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007962 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007963 return null;
7964 }
Derek Tan97ebb422014-09-05 16:55:38 -07007965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007966 final long identity = Binder.clearCallingIdentity();
7967 try {
7968 String iccId = getIccId(subId);
7969 if (iccId != null) {
7970 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7971 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7972 }
7973 return null;
7974 } finally {
7975 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007976 }
Derek Tan7226c842014-07-02 17:42:23 -07007977 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007978
7979 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007980 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7981 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007982 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7983 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007985 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007986 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007987 return null;
7988 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007989
Jordan Liub49b04b2019-05-06 14:45:15 -07007990 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7991 // the process, where TelephonyManager was instantiated.
7992 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007993 final long identity = Binder.clearCallingIdentity();
7994 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007995 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 final TelephonyManager tele = TelephonyManager.from(context);
7997 final SubscriptionManager sub = SubscriptionManager.from(context);
7998
7999 // Figure out what subscribers are currently active
8000 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001
Jordan Liub49b04b2019-05-06 14:45:15 -07008002 // Only consider subs which match the current subId
8003 // This logic can be simplified. See b/131189269 for progress.
8004 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008005 activeSubscriberIds.add(tele.getSubscriberId(subId));
8006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008007
8008 // First pass, find a number override for an active subscriber
8009 String mergeNumber = null;
8010 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8011 for (String key : prefs.keySet()) {
8012 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8013 final String subscriberId = (String) prefs.get(key);
8014 if (activeSubscriberIds.contains(subscriberId)) {
8015 final String iccId = key.substring(
8016 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8017 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8018 mergeNumber = (String) prefs.get(numberKey);
8019 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008020 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008021 + " for active subscriber " + subscriberId);
8022 }
8023 if (!TextUtils.isEmpty(mergeNumber)) {
8024 break;
8025 }
8026 }
8027 }
8028 }
8029
8030 // Shortcut when no active merged subscribers
8031 if (TextUtils.isEmpty(mergeNumber)) {
8032 return null;
8033 }
8034
8035 // Second pass, find all subscribers under that line override
8036 final ArraySet<String> result = new ArraySet<>();
8037 for (String key : prefs.keySet()) {
8038 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8039 final String number = (String) prefs.get(key);
8040 if (mergeNumber.equals(number)) {
8041 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8042 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8043 final String subscriberId = (String) prefs.get(subscriberKey);
8044 if (!TextUtils.isEmpty(subscriberId)) {
8045 result.add(subscriberId);
8046 }
8047 }
8048 }
8049 }
8050
8051 final String[] resultArray = result.toArray(new String[result.size()]);
8052 Arrays.sort(resultArray);
8053 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008054 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8056 }
8057 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008058 } finally {
8059 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008060 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008061 }
8062
8063 @Override
zoey chen38003472019-12-13 17:16:31 +08008064 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8065 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008066
joonhunshin4ac60942023-11-15 15:23:39 +00008067 enforceTelephonyFeatureWithException(callingPackage,
8068 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8069
Malcolm Chen6ca97372019-07-01 16:28:21 -07008070 final long identity = Binder.clearCallingIdentity();
8071 try {
8072 final TelephonyManager telephonyManager = mApp.getSystemService(
8073 TelephonyManager.class);
8074 String subscriberId = telephonyManager.getSubscriberId(subId);
8075 if (subscriberId == null) {
8076 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008077 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008078 + subId);
8079 }
8080 return null;
8081 }
8082
Jack Yu3beaf9d2023-04-14 09:17:27 -07008083 final SubscriptionInfo info = getSubscriptionManagerService()
8084 .getSubscriptionInfo(subId);
8085 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008086 // If it doesn't belong to any group, return just subscriberId of itself.
8087 if (groupUuid == null) {
8088 return new String[]{subscriberId};
8089 }
8090
8091 // Get all subscriberIds from the group.
8092 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008093 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8094 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8095 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008096 for (SubscriptionInfo subInfo : groupInfos) {
8097 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8098 if (subscriberId != null) {
8099 mergedSubscriberIds.add(subscriberId);
8100 }
8101 }
8102
8103 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8104 } finally {
8105 Binder.restoreCallingIdentity(identity);
8106
8107 }
8108 }
8109
8110 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008111 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008112 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008113 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008114
joonhunshin4ac60942023-11-15 15:23:39 +00008115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8116 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 final long identity = Binder.clearCallingIdentity();
8119 try {
8120 final Phone phone = getPhone(subId);
8121 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8122 } finally {
8123 Binder.restoreCallingIdentity(identity);
8124 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008125 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008126
8127 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008128 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008129 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8130 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008131 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8132 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133
8134 final long identity = Binder.clearCallingIdentity();
8135 try {
8136 final Phone phone = getPhone(subId);
8137 if (phone == null) {
8138 return false;
8139 }
8140 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8141 cdmaNonRoamingList);
8142 } finally {
8143 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008144 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008145 }
8146
8147 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008148 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008149 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008150 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008151 if (phone == null) {
8152 return raf;
8153 }
8154
Shuo Qiandee53402020-05-29 14:08:15 -07008155 try {
8156 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008157 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008158 mApp, phone.getSubId(), "getRadioAccessFamily");
8159 } catch (SecurityException e) {
8160 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8161 throw e;
8162 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008163
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008164 if (!mApp.getResources().getBoolean(
8165 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8166 enforceTelephonyFeatureWithException(callingPackage,
8167 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8168 }
joonhunshin4ac60942023-11-15 15:23:39 +00008169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170 final long identity = Binder.clearCallingIdentity();
8171 try {
chen xub97461a2018-10-26 14:17:57 -07008172 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 } finally {
8174 Binder.restoreCallingIdentity(identity);
8175 }
chen xub97461a2018-10-26 14:17:57 -07008176 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008177 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008178
8179 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008180 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008181 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Jack Yub6e8bad2024-09-01 19:56:34 -07008182 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8183 "Invalid package:" + callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00008184 enforceTelephonyFeatureWithException(callingPackage,
8185 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8186
Hall Liu82694d52020-12-11 18:22:04 -08008187 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008188 List<String> dialerRoleHolders;
Jack Yub6e8bad2024-09-01 19:56:34 -07008189 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8190 UserHandle.of(ActivityManager.getCurrentUser()));
Hall Liu82694d52020-12-11 18:22:04 -08008191 if (!dialerRoleHolders.contains(callingPackage)) {
8192 throw new SecurityException("App must be the dialer role holder to"
8193 + " upload a call composer pic");
8194 }
8195
8196 Executors.newSingleThreadExecutor().execute(() -> {
8197 ByteArrayOutputStream output = new ByteArrayOutputStream(
8198 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8199 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8200 boolean readUntilEnd = false;
8201 int totalBytesRead = 0;
8202 byte[] buffer = new byte[16 * 1024];
8203 while (true) {
8204 int numRead;
8205 try {
8206 numRead = input.read(buffer);
8207 } catch (IOException e) {
8208 try {
8209 fd.checkError();
8210 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8211 null);
8212 } catch (IOException e1) {
8213 // This means that the other side closed explicitly with an error. If this
8214 // happens, log and ignore.
8215 loge("Remote end of call composer picture pipe closed: " + e1);
8216 }
8217 break;
8218 }
8219 if (numRead == -1) {
8220 readUntilEnd = true;
8221 break;
8222 }
8223 totalBytesRead += numRead;
8224 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8225 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8226 try {
8227 input.close();
8228 } catch (IOException e) {
8229 // ignore
8230 }
8231 break;
8232 }
8233 output.write(buffer, 0, numRead);
8234 }
8235 // Generally, the remote end will close the file descriptors. The only case where we
8236 // close is above, where the picture size is too big.
8237
8238 try {
8239 fd.checkError();
8240 } catch (IOException e) {
8241 loge("Remote end for call composer closed with an error: " + e);
8242 return;
8243 }
8244
Hall Liuaa4211e2021-01-20 15:43:39 -08008245 if (!readUntilEnd) {
8246 loge("Did not finish reading entire image; aborting");
8247 return;
8248 }
Hall Liu82694d52020-12-11 18:22:04 -08008249
Hall Liuaa4211e2021-01-20 15:43:39 -08008250 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8251 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8252 new CallComposerPictureTransfer.Factory() {},
8253 imageData,
8254 (result) -> {
8255 if (result.first != null) {
8256 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8257 Bundle outputResult = new Bundle();
8258 outputResult.putParcelable(
8259 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8260 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8261 outputResult);
8262 } else {
8263 callback.send(result.second, null);
8264 }
8265 }
8266 );
Hall Liu82694d52020-12-11 18:22:04 -08008267 });
8268 }
8269
8270 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008271 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008272 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008273 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274
joonhunshin4ac60942023-11-15 15:23:39 +00008275 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8276 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 final long identity = Binder.clearCallingIdentity();
8279 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008280 ImsManager.getInstance(defaultPhone.getContext(),
8281 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282 } finally {
8283 Binder.restoreCallingIdentity(identity);
8284 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008285 }
8286
8287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008288 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008289 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8291 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008292 return false;
8293 }
Svet Ganovb320e182015-04-16 12:30:10 -07008294
joonhunshin4ac60942023-11-15 15:23:39 +00008295 enforceTelephonyFeatureWithException(callingPackage,
8296 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 // Check the user preference and the system-level IMS setting. Even if the user has
8301 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8302 // In the long run, we may instead need to check if there exists a connection service
8303 // which can support video calling.
8304 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008305 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008306 return imsManager.isVtEnabledByPlatform()
8307 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8308 && imsManager.isVtEnabledByUser();
8309 } finally {
8310 Binder.restoreCallingIdentity(identity);
8311 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008312 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008313
Andrew Leea1239f22015-03-02 17:44:07 -08008314 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008315 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8316 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008318 mApp, subId, callingPackage, callingFeatureId,
8319 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008320 return false;
8321 }
8322
joonhunshin4ac60942023-11-15 15:23:39 +00008323 enforceTelephonyFeatureWithException(callingPackage,
8324 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008326 final long identity = Binder.clearCallingIdentity();
8327 try {
8328 CarrierConfigManager configManager =
8329 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008330 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8332 } finally {
8333 Binder.restoreCallingIdentity(identity);
8334 }
Andrew Leea1239f22015-03-02 17:44:07 -08008335 }
8336
8337 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008338 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008340 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 return false;
8342 }
8343
joonhunshin4ac60942023-11-15 15:23:39 +00008344 enforceTelephonyFeatureWithException(callingPackage,
8345 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008347 final long identity = Binder.clearCallingIdentity();
8348 try {
8349 CarrierConfigManager configManager =
8350 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008351 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008352 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8353 } finally {
8354 Binder.restoreCallingIdentity(identity);
8355 }
Andrew Leea1239f22015-03-02 17:44:07 -08008356 }
8357
Andrew Lee9431b832015-03-09 18:46:45 -07008358 @Override
8359 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008360 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008361 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008362 }
8363
8364 @Override
8365 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008366 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8367 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369 final long identity = Binder.clearCallingIdentity();
8370 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008371 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372 } finally {
8373 Binder.restoreCallingIdentity(identity);
8374 }
Andrew Lee9431b832015-03-09 18:46:45 -07008375 }
8376
Hall Liuf6668912018-10-31 17:05:23 -07008377 /**
8378 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8379 * support for the feature and device firmware support.
8380 *
8381 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8382 */
8383 @Override
8384 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008385 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8386 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008388 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008389 final Phone phone = getPhone(subscriptionId);
8390 if (phone == null) {
8391 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8392 return false;
8393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008394 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008395 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008397 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8398 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8399 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008400 return isCarrierSupported && isDeviceSupported;
8401 } finally {
8402 Binder.restoreCallingIdentity(identity);
8403 }
Hall Liu98187582018-01-22 19:15:32 -08008404 }
8405
Hall Liuf6668912018-10-31 17:05:23 -07008406 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008407 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8408 * RTT setting, will return true if the device and carrier both support RTT.
8409 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008410 */
8411 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412 final long identity = Binder.clearCallingIdentity();
8413 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008414 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8415 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8416 return false;
8417 }
8418 }
8419
Hall Liu5bab75c2019-12-11 23:58:20 +00008420 boolean isRttSupported = isRttSupported(subscriptionId);
8421 boolean isUserRttSettingOn = Settings.Secure.getInt(
8422 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8423 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8424 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8425 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008426 } finally {
8427 Binder.restoreCallingIdentity(identity);
8428 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008429 }
8430
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008431 @Deprecated
8432 @Override
8433 public String getDeviceId(String callingPackage) {
8434 return getDeviceIdWithFeature(callingPackage, null);
8435 }
8436
Sanket Padawe7310cc72015-01-14 09:53:20 -08008437 /**
8438 * Returns the unique device ID of phone, for example, the IMEI for
8439 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8440 *
8441 * <p>Requires Permission:
8442 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8443 */
8444 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008445 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008446 try {
8447 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8448 } catch (SecurityException se) {
8449 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8450 throw new SecurityException("Package " + callingPackage + " does not belong to "
8451 + Binder.getCallingUid());
8452 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008453 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008454 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008455 return null;
8456 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008457 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008458 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008459 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008460 return null;
8461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008462
8463 final long identity = Binder.clearCallingIdentity();
8464 try {
8465 return phone.getDeviceId();
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
8468 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008469 }
8470
Ping Sunc67b7c22016-03-02 19:16:45 +08008471 /**
8472 * {@hide}
8473 * Returns the IMS Registration Status on a particular subid
8474 *
8475 * @param subId
8476 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008477 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008478 Phone phone = getPhone(subId);
8479 if (phone != null) {
8480 return phone.isImsRegistered();
8481 } else {
8482 return false;
8483 }
8484 }
8485
Santos Cordon7a1885b2015-02-03 11:15:19 -08008486 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008487 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008488 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008490 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008491 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8492 }
8493 final long identity = Binder.clearCallingIdentity();
8494 try {
8495 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8496 } finally {
8497 Binder.restoreCallingIdentity(identity);
8498 }
8499 }
8500
8501 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008502 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008503 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008504 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008505 mApp,
8506 subscriptionId,
8507 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8508 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008509
8510 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8511 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8512
Tyler Gunnf70ed162019-04-03 15:28:53 -07008513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 Phone phone = getPhone(subscriptionId);
8516 if (phone == null) {
8517 return null;
8518 }
8519 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
8522 }
8523 }
8524
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008525 /**
8526 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008527 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008528 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 Phone phone = getPhone(subId);
8532 if (phone != null) {
8533 return phone.isWifiCallingEnabled();
8534 } else {
8535 return false;
8536 }
8537 } finally {
8538 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008539 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008540 }
8541
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008542 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008543 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008544 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008545 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008546 final long identity = Binder.clearCallingIdentity();
8547 try {
8548 Phone phone = getPhone(subId);
8549 if (phone != null) {
8550 return phone.isVideoEnabled();
8551 } else {
8552 return false;
8553 }
8554 } finally {
8555 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008556 }
8557 }
8558
8559 /**
8560 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8561 * defined in {@link ImsRegistrationImplBase}.
8562 */
8563 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008564 final long identity = Binder.clearCallingIdentity();
8565 try {
8566 Phone phone = getPhone(subId);
8567 if (phone != null) {
8568 return phone.getImsRegistrationTech();
8569 } else {
8570 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8571 }
8572 } finally {
8573 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008574 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008575 }
8576
Stuart Scott8eef64f2015-04-08 15:13:54 -07008577 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008578 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008579 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008580
8581 enforceTelephonyFeatureWithException(callingPackage,
8582 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8583
Stuart Scott981d8582015-04-21 14:09:50 -07008584 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8585 return;
8586 }
Kai Shif70f46f2021-03-03 13:59:46 -08008587 Phone defaultPhone = getDefaultPhone();
8588 if (defaultPhone != null) {
8589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8590 mApp, getDefaultPhone().getSubId(), "factoryReset");
8591 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008592 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008593
Svet Ganovcc087f82015-05-12 20:35:54 -07008594 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008595 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8596 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008597 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008598 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008599 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008600 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008601 cleanUpAllowedNetworkTypes(phone, subId);
TAKAHASHI Uichiroc4b07452022-08-29 16:03:11 +09008602
Rambo Wang71f6aa62024-02-23 20:16:22 +00008603 setDataRoamingEnabled(subId, phone == null ? false
8604 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
TAKAHASHI Uichiroc4b07452022-08-29 16:03:11 +09008605 getPhone(subId).resetCarrierKeysForImsiEncryption(true);
Svet Ganovcc087f82015-05-12 20:35:54 -07008606 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008607 // There has been issues when Sms raw table somehow stores orphan
8608 // fragments. They lead to garbled message when new fragments come
8609 // in and combined with those stale ones. In case this happens again,
8610 // user can reset all network settings which will clean up this table.
8611 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008612 // Clean up IMS settings as well here.
8613 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008614 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008615 ImsManager.getInstance(mApp, slotId).factoryReset();
8616 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008617
Kai Shif70f46f2021-03-03 13:59:46 -08008618 if (defaultPhone == null) {
8619 return;
8620 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008621 // Erase modem config if erase modem on network setting is enabled.
8622 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8623 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8624 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008625 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008626 }
Kai Shif70f46f2021-03-03 13:59:46 -08008627
8628 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008629 } finally {
8630 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008631 }
8632 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008633
SongFerngWangfd89b102021-05-27 22:44:54 +08008634 @VisibleForTesting
8635 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8636 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8637 return;
8638 }
8639 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8640 RILConstants.PREFERRED_NETWORK_MODE);
8641 SubscriptionManager.setSubscriptionProperty(subId,
8642 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8643 "user=" + defaultNetworkType);
8644 phone.loadAllowedNetworksFromSubscriptionDatabase();
8645 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8646 defaultNetworkType, null);
8647 }
8648
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008649 private void cleanUpSmsRawTable(Context context) {
8650 ContentResolver resolver = context.getContentResolver();
8651 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8652 resolver.delete(uri, null, null);
8653 }
8654
Narayan Kamath1c496c22015-04-16 14:40:19 +01008655 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008656 public String getSimLocaleForSubscriber(int subId) {
8657 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008658
8659 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8660 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8661
chen xu5d3637b2019-01-21 23:31:38 -08008662 final Phone phone = getPhone(subId);
8663 if (phone == null) {
8664 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008665 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008666 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008667 final long identity = Binder.clearCallingIdentity();
8668 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008669 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8670 phone.getContext().getOpPackageName(),
8671 phone.getContext().getAttributionTag());
8672 if (info == null) {
8673 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8674 return null;
chen xu6291c472019-02-04 12:55:53 -08008675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008676 // Try and fetch the locale from the carrier properties or from the SIM language
8677 // preferences (EF-PL and EF-LI)...
8678 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008679 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008680 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8681 if (localeFromDefaultSim != null) {
8682 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8683 if (DBG) log("Using locale from subId: " + subId + " locale: "
8684 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008685 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008686 } else {
8687 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008688 }
8689 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008691 // The SIM language preferences only store a language (e.g. fr = French), not an
8692 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8693 // the SIM and carrier preferences does not include a country we add the country
8694 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008695 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008696 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008697 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008698 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008699 }
8700
8701 if (DBG) log("No locale found - returning null");
8702 return null;
8703 } finally {
8704 Binder.restoreCallingIdentity(identity);
8705 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008706 }
8707
tom hsu0b59d292022-09-29 23:49:21 +08008708 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008709 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008710 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008711 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008712 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008713 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8714 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008715 Locale.forLanguageTag(localeTag).getCountry())) {
8716 return localeTag;
8717 }
8718 }
8719 return inputLocale.toLanguageTag();
8720 }
8721
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008722 /**
8723 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8724 */
8725 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008726 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008727 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008728 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008729
Gary Jian3aa9a762022-01-24 16:41:19 +08008730 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8731 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008732
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008733 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008734 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8735 * representing the state of the modem.
8736 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008737 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8738 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008739 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008740 */
8741 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008742 public void requestModemActivityInfo(ResultReceiver result) {
8743 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008744
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07008745 if (!mApp.getResources().getBoolean(
8746 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8747 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8748 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8749 }
joonhunshin4ac60942023-11-15 15:23:39 +00008750
vagdeviaf9a5b92018-08-15 16:01:53 -07008751 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008752
8753 final long identity = Binder.clearCallingIdentity();
8754 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008755 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008756 } finally {
8757 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008758 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008759 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008760
Gary Jian76280a42022-12-07 16:18:33 +08008761 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008762 // less than total activity duration.
8763 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8764 if (info == null) {
8765 return false;
8766 }
8767 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008768 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008769 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8770
Hall Liu49656c02020-10-09 19:00:11 -07008771 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8772
Siddharth Rayb8114062018-06-17 15:02:38 -07008773 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008774 && (info.getSleepTimeMillis() <= activityDurationMs)
8775 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008776 }
8777
Gary Jian3aa9a762022-01-24 16:41:19 +08008778 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8779 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8780 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8781 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8782
8783 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8784 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8785 }
8786
8787 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8788 mLastModemActivityInfo.setReceiveTimeMillis(
8789 rat,
8790 freq,
8791 info.getReceiveTimeMillis(rat, freq)
8792 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8793 }
8794
8795 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8796 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8797 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8798 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8799
8800 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8801 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8802 }
8803 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8804 mLastModemActivityInfo.setReceiveTimeMillis(
8805 rat,
8806 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8807 }
8808
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008809 /**
8810 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8811 * @param info recent ModemActivityInfo
8812 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008813 private void mergeModemActivityInfo(ModemActivityInfo info) {
8814 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008815 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008816 boolean matched;
8817 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8818 matched = false;
8819 int rat = info.getSpecificInfoRat(i);
8820 int freq = info.getSpecificInfoFrequencyRange(i);
8821 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8822 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8823 //if it already exists
8824 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8825 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8826 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8827 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8828 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8829 updateLastModemActivityInfo(info, rat, freq);
8830 matched = true;
8831 }
8832 } else {
8833 updateLastModemActivityInfo(info, rat);
8834 matched = true;
8835 }
8836 }
8837 }
8838
8839 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008840 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008841 new ActivityStatsTechSpecificInfo(
8842 rat,
8843 freq,
8844 info.getTransmitTimeMillis(rat, freq),
8845 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008846 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008847 }
8848 }
8849 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8850 mLastModemActivitySpecificInfo =
8851 new ActivityStatsTechSpecificInfo[merged.size()];
8852 merged.toArray(mLastModemActivitySpecificInfo);
8853
8854 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8855 mLastModemActivityInfo.setSleepTimeMillis(
8856 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008857 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008858 mLastModemActivityInfo.setIdleTimeMillis(
8859 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008860 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008861
8862 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008863 new ModemActivityInfo(
8864 mLastModemActivityInfo.getTimestampMillis(),
8865 mLastModemActivityInfo.getSleepTimeMillis(),
8866 mLastModemActivityInfo.getIdleTimeMillis(),
8867 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008868 }
8869
8870 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8871 ActivityStatsTechSpecificInfo[] info) {
8872 int infoSize = info.length;
8873 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8874 for (int i = 0; i < infoSize; i++) {
8875 ret[i] = new ActivityStatsTechSpecificInfo(
8876 info[i].getRat(), info[i].getFrequencyRange(),
8877 info[i].getTransmitTimeMillis(),
8878 (int) info[i].getReceiveTimeMillis());
8879 }
8880 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008881 }
8882
Jack Yu85bd38a2015-11-09 11:34:32 -08008883 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008884 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008885 */
8886 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008887 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8888 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8889 Phone phone = PhoneFactory.getPhone(slotIndex);
8890 if (phone == null) {
8891 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8892 return null;
8893 }
8894
8895 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008897 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008898 return null;
8899 }
8900
joonhunshin4ac60942023-11-15 15:23:39 +00008901 enforceTelephonyFeatureWithException(callingPackage,
8902 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8903
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008904 boolean hasFinePermission = false;
8905 boolean hasCoarsePermission = false;
8906 if (!renounceFineLocationAccess) {
8907 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8908 LocationAccessPolicy.checkLocationPermission(mApp,
8909 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8910 .setCallingPackage(callingPackage)
8911 .setCallingFeatureId(callingFeatureId)
8912 .setCallingPid(Binder.getCallingPid())
8913 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008914 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008915 .setLogAsInfo(true)
8916 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8917 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8918 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8919 .build());
8920 hasFinePermission =
8921 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8922 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008923
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008924 if (!renounceCoarseLocationAccess) {
8925 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8926 LocationAccessPolicy.checkLocationPermission(mApp,
8927 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8928 .setCallingPackage(callingPackage)
8929 .setCallingFeatureId(callingFeatureId)
8930 .setCallingPid(Binder.getCallingPid())
8931 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008932 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008933 .setLogAsInfo(true)
8934 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8935 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8936 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8937 .build());
8938 hasCoarsePermission =
8939 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8940 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008941
Jordan Liu0f2bc442020-11-18 16:47:37 -08008942 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008943 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008944 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8945 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008946 if (subInfo != null && !subInfo.isActive()) {
8947 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008948 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008949 }
8950
Hall Liuf19c44f2018-11-27 14:38:17 -08008951 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008952 boolean isCallingPackageDataService = phone.getDataServicePackages()
8953 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008954
8955 // Scrub out the location info in ServiceState depending on what level of access
8956 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008957 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008958 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8959 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008960 } finally {
8961 Binder.restoreCallingIdentity(identity);
8962 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008963 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008964
8965 /**
8966 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8967 *
8968 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8969 * voicemail ringtone.
8970 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8971 * PhoneAccount.
8972 */
8973 @Override
8974 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008975 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8976 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008978 final long identity = Binder.clearCallingIdentity();
8979 try {
8980 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8981 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008982 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008983 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008985 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8986 } finally {
8987 Binder.restoreCallingIdentity(identity);
8988 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008989 }
8990
8991 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008992 * Sets the per-account voicemail ringtone.
8993 *
8994 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8995 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8996 *
8997 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8998 * voicemail ringtone.
8999 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
9000 * PhoneAccount.
9001 */
9002 @Override
9003 public void setVoicemailRingtoneUri(String callingPackage,
9004 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009005 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009006 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009007 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9008 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9010 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9011 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009013
joonhunshin4ac60942023-11-15 15:23:39 +00009014 enforceTelephonyFeatureWithException(callingPackage,
9015 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
9016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009017 final long identity = Binder.clearCallingIdentity();
9018 try {
9019 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9020 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009021 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009022 }
9023 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9024 } finally {
9025 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009026 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009027 }
9028
9029 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009030 * Returns whether vibration is set for voicemail notification in Phone settings.
9031 *
9032 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9033 * voicemail vibration setting.
9034 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9035 */
9036 @Override
9037 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009038 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9039 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009041 final long identity = Binder.clearCallingIdentity();
9042 try {
9043 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9044 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009045 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009046 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009048 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9049 } finally {
9050 Binder.restoreCallingIdentity(identity);
9051 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009052 }
9053
Youhan Wange64578a2016-05-02 15:32:42 -07009054 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009055 * Sets the per-account voicemail vibration.
9056 *
9057 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9058 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9059 *
9060 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9061 * voicemail vibration setting.
9062 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9063 * specific PhoneAccount.
9064 */
9065 @Override
9066 public void setVoicemailVibrationEnabled(String callingPackage,
9067 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009068 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009069 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009070 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9071 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9073 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9074 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009075 }
9076
joonhunshin4ac60942023-11-15 15:23:39 +00009077 enforceTelephonyFeatureWithException(callingPackage,
9078 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009080 final long identity = Binder.clearCallingIdentity();
9081 try {
9082 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9083 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009084 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009085 }
9086 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9087 } finally {
9088 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009089 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009090 }
9091
9092 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009093 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9094 *
9095 * @throws SecurityException if the caller does not have the required permission
9096 */
arunvoddud7401012022-12-15 16:08:12 +00009097 @VisibleForTesting
9098 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009099 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009100 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009101 }
9102
9103 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009104 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9105 * permission.
9106 *
9107 * @throws SecurityException if the caller does not have the required permission
9108 */
9109 private void enforceSendSmsPermission() {
9110 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9111 }
9112
9113 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009114 * Make sure either called from same process as self (phone) or IPC caller has interact across
9115 * users permission.
9116 *
9117 * @throws SecurityException if the caller does not have the required permission
9118 */
9119 private void enforceInteractAcrossUsersPermission(String message) {
9120 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9121 }
9122
9123 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009124 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009125 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009126 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009127 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009128 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009129 final long identity = Binder.clearCallingIdentity();
9130 try {
9131 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009132 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009133 if (componentName == null) {
9134 throw new SecurityException(
9135 "Caller not current active visual voicemail package[null]");
9136 }
9137 String vvmPackage = componentName.getPackageName();
9138 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009139 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009140 }
9141 } finally {
9142 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009143 }
9144 }
9145
9146 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009147 * Return the application ID for the app type.
9148 *
9149 * @param subId the subscription ID that this request applies to.
9150 * @param appType the uicc app type.
9151 * @return Application ID for specificied app type, or null if no uicc.
9152 */
9153 @Override
9154 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009155 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009156
9157 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9158 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9159
Youhan Wange64578a2016-05-02 15:32:42 -07009160 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009161
9162 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009163 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009164 if (phone == null) {
9165 return null;
9166 }
9167 String aid = null;
9168 try {
Tomasz Wasilczyk58e46ca2024-12-06 12:09:51 -08009169 UiccCardApplication app = UiccController.getInstance()
9170 .getUiccPort(phone.getPhoneId()).getApplicationByType(appType);
9171 if (app == null) return null;
9172 aid = app.getAid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009173 } catch (Exception e) {
Tomasz Wasilczyk58e46ca2024-12-06 12:09:51 -08009174 Log.e(LOG_TAG, "Not getting aid", e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009175 }
9176 return aid;
9177 } finally {
9178 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009179 }
Youhan Wange64578a2016-05-02 15:32:42 -07009180 }
9181
Youhan Wang4001d252016-05-11 10:29:41 -07009182 /**
9183 * Return the Electronic Serial Number.
9184 *
9185 * @param subId the subscription ID that this request applies to.
9186 * @return ESN or null if error.
9187 */
9188 @Override
9189 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009190 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009191 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009192
9193 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009194 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009195 if (phone == null) {
9196 return null;
9197 }
9198 String esn = null;
9199 try {
9200 esn = phone.getEsn();
9201 } catch (Exception e) {
Tomasz Wasilczyk58e46ca2024-12-06 12:09:51 -08009202 Log.e(LOG_TAG, "Not getting ESN", e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009203 }
9204 return esn;
9205 } finally {
9206 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009207 }
Youhan Wang4001d252016-05-11 10:29:41 -07009208 }
9209
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009210 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009211 * Return the Preferred Roaming List Version.
9212 *
9213 * @param subId the subscription ID that this request applies to.
9214 * @return PRLVersion or null if error.
9215 */
9216 @Override
9217 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009218 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009219
9220 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9221 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9222
Youhan Wang66ad5d72016-07-18 17:56:58 -07009223 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009224
9225 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009226 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009227 if (phone == null) {
9228 return null;
9229 }
9230 String cdmaPrlVersion = null;
9231 try {
9232 cdmaPrlVersion = phone.getCdmaPrlVersion();
9233 } catch (Exception e) {
9234 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9235 }
9236 return cdmaPrlVersion;
9237 } finally {
9238 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009239 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009240 }
9241
9242 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009243 * Get snapshot of Telephony histograms
9244 * @return List of Telephony histograms
9245 * @hide
9246 */
9247 @Override
9248 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9250 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009251
9252 final long identity = Binder.clearCallingIdentity();
9253 try {
9254 return RIL.getTelephonyRILTimingHistograms();
9255 } finally {
9256 Binder.restoreCallingIdentity(identity);
9257 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009258 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009259
9260 /**
9261 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009262 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9263 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009264 * Require system privileges. In the future we may add this to carrier APIs.
9265 *
Michele Berionne482f8202018-11-27 18:57:59 -08009266 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009267 */
9268 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009269 @TelephonyManager.SetCarrierRestrictionResult
9270 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009271 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009272
9273 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9274 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9275
vagdeviaf9a5b92018-08-15 16:01:53 -07009276 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009277
Michele Berionne482f8202018-11-27 18:57:59 -08009278 if (carrierRestrictionRules == null) {
9279 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009280 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009282 final long identity = Binder.clearCallingIdentity();
9283 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009284 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009285 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009286 } finally {
9287 Binder.restoreCallingIdentity(identity);
9288 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009289 }
9290
9291 /**
9292 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009293 * Get the allowed carrier list and the excluded carrier list, including the priority between
9294 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009295 * Require system privileges. In the future we may add this to carrier APIs.
9296 *
Michele Berionne482f8202018-11-27 18:57:59 -08009297 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009298 */
9299 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009300 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009301 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009302
9303 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9304 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9305
vagdeviaf9a5b92018-08-15 16:01:53 -07009306 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009307
9308 final long identity = Binder.clearCallingIdentity();
9309 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009310 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9311 if (response instanceof CarrierRestrictionRules) {
9312 return (CarrierRestrictionRules) response;
9313 }
9314 // Response is an Exception of some kind,
9315 // which is signalled to the user as a NULL retval
9316 return null;
9317 } catch (Exception e) {
9318 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9319 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009320 } finally {
9321 Binder.restoreCallingIdentity(identity);
9322 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009323 }
9324
fionaxu59545b42016-05-25 15:53:37 -07009325 /**
arunvoddud7401012022-12-15 16:08:12 +00009326 * Fetches the carrier restriction status of the device and sends the status to the caller
9327 * through the callback.
9328 *
9329 * @param callback The callback that will be used to send the result.
9330 * @throws SecurityException if the caller does not have the required permission/privileges or
9331 * the caller is not allowlisted.
9332 */
9333 @Override
9334 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
arunvoddu181c74f2024-08-19 14:21:29 +00009335 String functionName = "getCarrierRestrictionStatus";
joonhunshin4ac60942023-11-15 15:23:39 +00009336 enforceTelephonyFeatureWithException(packageName,
arunvoddu181c74f2024-08-19 14:21:29 +00009337 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName);
9338 try {
9339 mApp.enforceCallingOrSelfPermission(
9340 android.Manifest.permission.READ_BASIC_PHONE_STATE,
9341 functionName);
9342 } catch (SecurityException e) {
9343 mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE,
9344 functionName);
9345 }
Steve Statia28b7cb32024-03-11 23:58:50 +00009346 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9347 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009348 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9349 throw new SecurityException("Not an authorized caller");
9350 }
9351 final long identity = Binder.clearCallingIdentity();
9352 try {
9353 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009354 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009355 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9356 } finally {
9357 Binder.restoreCallingIdentity(identity);
9358 }
9359 }
9360
arunvoddu567f2b42023-04-25 17:22:00 +00009361 @Override
9362 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9363 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9364 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9365 return allowListInfo.getShaIdList(pkgName, carrierId);
9366 }
9367
arunvoddud7401012022-12-15 16:08:12 +00009368 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009369 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009370 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009371 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009372 }
9373
9374 /**
fionaxu59545b42016-05-25 15:53:37 -07009375 * Action set from carrier signalling broadcast receivers to enable/disable radio
9376 * @param subId the subscription ID that this action applies to.
9377 * @param enabled control enable or disable radio.
9378 * {@hide}
9379 */
9380 @Override
9381 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9382 enforceModifyPermission();
9383 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009384
9385 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009386 if (phone == null) {
9387 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9388 return;
9389 }
9390 try {
9391 phone.carrierActionSetRadioEnabled(enabled);
9392 } catch (Exception e) {
9393 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009394 } finally {
9395 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009396 }
9397 }
9398
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009399 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009400 * Enable or disable Voice over NR (VoNR)
9401 * @param subId the subscription ID that this action applies to.
9402 * @param enabled enable or disable VoNR.
9403 * @return operation result.
9404 */
9405 @Override
9406 public int setVoNrEnabled(int subId, boolean enabled) {
9407 enforceModifyPermission();
9408 final Phone phone = getPhone(subId);
9409
9410 final long identity = Binder.clearCallingIdentity();
9411 if (phone == null) {
9412 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9413 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9414 }
9415
9416 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9417 try {
9418 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9419 workSource);
9420 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009421
9422 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9423 if (DBG) {
9424 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9425 }
9426 SubscriptionManager.setSubscriptionProperty(
9427 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9428 (enabled ? "1" : "0"));
9429 }
9430
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009431 return result;
9432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435 }
9436
9437 /**
9438 * Is voice over NR enabled
9439 * @return true if VoNR is enabled else false
9440 */
9441 @Override
9442 public boolean isVoNrEnabled(int subId) {
9443 enforceReadPrivilegedPermission("isVoNrEnabled");
9444 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9445 final long identity = Binder.clearCallingIdentity();
9446 try {
9447 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9448 null, subId, workSource);
9449 if (DBG) log("isVoNrEnabled: " + isEnabled);
9450 return isEnabled;
9451 } finally {
9452 Binder.restoreCallingIdentity(identity);
9453 }
9454 }
9455
9456 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009457 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9458 * network status based on which carrier apps could apply actions accordingly,
9459 * enable/disable default url handler for example.
9460 *
9461 * @param subId the subscription ID that this action applies to.
9462 * @param report control start/stop reporting the default network status.
9463 * {@hide}
9464 */
9465 @Override
9466 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9467 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009468
9469 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9470 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9471 "carrierActionReportDefaultNetworkStatus");
9472
fionaxu8da9cb12017-05-23 15:02:46 -07009473 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009474
9475 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009476 if (phone == null) {
9477 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9478 return;
9479 }
9480 try {
9481 phone.carrierActionReportDefaultNetworkStatus(report);
9482 } catch (Exception e) {
9483 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009484 } finally {
9485 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009486 }
9487 }
9488
9489 /**
fionaxud9622282017-07-17 17:51:30 -07009490 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9491 * @param subId the subscription ID that this action applies to.
9492 * {@hide}
9493 */
9494 @Override
9495 public void carrierActionResetAll(int subId) {
9496 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009497
9498 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9499 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9500
fionaxud9622282017-07-17 17:51:30 -07009501 final Phone phone = getPhone(subId);
9502 if (phone == null) {
9503 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9504 return;
9505 }
9506 try {
9507 phone.carrierActionResetAll();
9508 } catch (Exception e) {
9509 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9510 }
9511 }
9512
9513 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009514 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9515 * bug report is being generated.
9516 */
9517 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009518 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009519 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9520 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009521 writer.println("Permission Denial: can't dump Phone from pid="
9522 + Binder.getCallingPid()
9523 + ", uid=" + Binder.getCallingUid()
9524 + "without permission "
9525 + android.Manifest.permission.DUMP);
9526 return;
9527 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009528 try {
9529 DumpsysHandler.dump(mApp, fd, writer, args);
9530 } catch (Exception e) {
9531 writer.println("Failed to dump phone information: " + e);
9532 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009533 }
Jack Yueb89b242016-06-22 13:27:47 -07009534
Brad Ebingerdac2f002018-04-03 15:17:52 -07009535 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009536 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9537 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9538 @NonNull String[] args) {
9539 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9540 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009541 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009542 }
9543
Jack Yueb89b242016-06-22 13:27:47 -07009544 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009545 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009546 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009547 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009548 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009549 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009550 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009551 */
9552 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009553 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009554 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009555 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9556 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9557 try {
9558 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009559 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009560 } catch (SecurityException se) {
9561 enforceModifyPermission();
9562 }
9563 } else {
9564 enforceModifyPermission();
9565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009566
joonhunshin4ac60942023-11-15 15:23:39 +00009567 enforceTelephonyFeatureWithException(callingPackage,
9568 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9569
Nate Myren116695d2024-02-09 09:36:01 -08009570 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009571 final long identity = Binder.clearCallingIdentity();
9572 try {
Nate Myren116695d2024-02-09 09:36:01 -08009573 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9574 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009575 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009576 callingUid, callingPackage, null, null);
9577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009578 Phone phone = getPhone(subId);
9579 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009580 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9581 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009582 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009583 phone.getDataSettingsManager().setDataEnabled(
9584 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009586 }
9587 } finally {
9588 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009589 }
9590 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009591
9592 /**
9593 * Get Client request stats
9594 * @return List of Client Request Stats
9595 * @hide
9596 */
9597 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009598 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9599 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009601 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009602 return null;
9603 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009604 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009606 final long identity = Binder.clearCallingIdentity();
9607 try {
9608 if (phone != null) {
9609 return phone.getClientRequestStats();
9610 }
9611
9612 return null;
9613 } finally {
9614 Binder.restoreCallingIdentity(identity);
9615 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009616 }
9617
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009618 private WorkSource getWorkSource(int uid) {
Jack Yube3fa442024-09-16 14:39:45 -07009619 PackageManager pm;
9620 if (mFeatureFlags.hsumPackageManager()) {
9621 pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0)
9622 .getPackageManager();
9623 } else {
9624 pm = mApp.getPackageManager();
9625 }
9626
9627 String packageName = pm.getNameForUid(uid);
Jack Yu86374492024-09-16 13:05:44 -07009628 if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) {
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009629 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9630 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9631 // exception. ROOT_UID seems not to have a valid package name returned by
9632 // PackageManager, so just fake it here to avoid issues when running telephony shell
9633 // commands that plumb through the RIL as root, like so:
9634 // $ adb root
9635 // $ adb shell cmd phone ...
9636 packageName = "root";
9637 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009638 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009639 }
Jack Yueb4124c2017-02-16 15:32:43 -08009640
9641 /**
Grace Chen70990072017-03-24 17:21:30 -07009642 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009643 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009644 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009645 * @param state State of SIM (power down, power up, pass through)
9646 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9647 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9648 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009649 *
9650 **/
9651 @Override
Grace Chen70990072017-03-24 17:21:30 -07009652 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009653 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009654
9655 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9656 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9657
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009658 Phone phone = PhoneFactory.getPhone(slotIndex);
9659
vagdeviaf9a5b92018-08-15 16:01:53 -07009660 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009662 final long identity = Binder.clearCallingIdentity();
9663 try {
9664 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009665 phone.setSimPowerState(state, null, workSource);
9666 }
9667 } finally {
9668 Binder.restoreCallingIdentity(identity);
9669 }
9670 }
9671
9672 /**
9673 * Set SIM card power state.
9674 *
9675 * @param slotIndex SIM slot id.
9676 * @param state State of SIM (power down, power up, pass through)
9677 * @param callback callback to trigger after success or failure
9678 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9679 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9680 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9681 *
9682 **/
9683 @Override
9684 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9685 IIntegerConsumer callback) {
9686 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009687
9688 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9689 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9690 "setSimPowerStateForSlotWithCallback");
9691
Jordan Liu109698e2020-11-24 14:50:34 -08009692 Phone phone = PhoneFactory.getPhone(slotIndex);
9693
9694 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9695
9696 final long identity = Binder.clearCallingIdentity();
9697 try {
9698 if (phone != null) {
9699 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9700 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009701 }
9702 } finally {
9703 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009704 }
9705 }
Shuo Qiandd210312017-04-12 22:11:33 +00009706
Tyler Gunn65d45c22017-06-05 11:22:26 -07009707 private boolean isUssdApiAllowed(int subId) {
9708 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009709 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009710 if (configManager == null) {
9711 return false;
9712 }
9713 PersistableBundle pb = configManager.getConfigForSubId(subId);
9714 if (pb == null) {
9715 return false;
9716 }
9717 return pb.getBoolean(
9718 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9719 }
9720
Shuo Qiandd210312017-04-12 22:11:33 +00009721 /**
Ling Mac28f0212023-03-24 16:07:15 -07009722 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009723 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009724 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009725 */
goneil9c5f4872017-12-05 14:07:56 -08009726 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009727 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009728 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009729
9730 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9731 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009733 final long identity = Binder.clearCallingIdentity();
9734 try {
Ling Mac28f0212023-03-24 16:07:15 -07009735 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009736 } finally {
9737 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009738 }
9739 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009740
9741 /**
9742 * Get the current signal strength information for the given subscription.
9743 * Because this information is not updated when the device is in a low power state
9744 * it should not be relied-upon to be current.
9745 * @param subId Subscription index
9746 * @return the most recent cached signal strength info from the modem
9747 */
9748 @Override
9749 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009750 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9751 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009753 final long identity = Binder.clearCallingIdentity();
9754 try {
9755 Phone p = getPhone(subId);
9756 if (p == null) {
9757 return null;
9758 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009760 return p.getSignalStrength();
9761 } finally {
9762 Binder.restoreCallingIdentity(identity);
9763 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009764 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009765
Pengquan Meng77b7f132018-08-22 14:49:57 -07009766 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009767 * Get the current modem radio state for the given slot.
9768 * @param slotIndex slot index.
9769 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009770 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009771 * @return the current radio power state from the modem
9772 */
9773 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009774 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009775 Phone phone = PhoneFactory.getPhone(slotIndex);
9776 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009777 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9778 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009779 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9780 }
9781
joonhunshin4ac60942023-11-15 15:23:39 +00009782 enforceTelephonyFeatureWithException(callingPackage,
9783 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9784
Chen Xuf792fd62018-10-17 17:54:36 +00009785 final long identity = Binder.clearCallingIdentity();
9786 try {
9787 return phone.getRadioPowerState();
9788 } finally {
9789 Binder.restoreCallingIdentity(identity);
9790 }
9791 }
9792 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9793 }
9794
9795 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009796 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9797 *
9798 * <p>Requires one of the following permissions:
9799 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009800 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009801 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9802 * privileges.
9803 *
9804 * @param subId subscription id
9805 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9806 * {@code false}.
9807 */
9808 @Override
9809 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009810 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009811 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009812 try {
9813 mApp.enforceCallingOrSelfPermission(
9814 android.Manifest.permission.ACCESS_NETWORK_STATE,
9815 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009816 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009817 mApp.enforceCallingOrSelfPermission(
9818 permission.READ_BASIC_PHONE_STATE, functionName);
9819 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009820 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009821 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009822 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009823 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009824
joonhunshin4ac60942023-11-15 15:23:39 +00009825 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9826 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9827
Pengquan Menga1bb6272018-09-06 09:59:22 -07009828 boolean isEnabled = false;
9829 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009830 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009831 Phone phone = getPhone(subId);
9832 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009833 } finally {
9834 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009835 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009836 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009837 }
9838
9839
9840 /**
9841 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9842 *
9843 * <p> Requires permission:
9844 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9845 * privileges.
9846 *
9847 * @param subId subscription id
9848 * @param isEnabled {@code true} means enable, {@code false} means disable.
9849 */
9850 @Override
9851 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9853 mApp, subId, "setDataRoamingEnabled");
9854
joonhunshin4ac60942023-11-15 15:23:39 +00009855 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9856 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9857
Pengquan Menga1bb6272018-09-06 09:59:22 -07009858 final long identity = Binder.clearCallingIdentity();
9859 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009860 Phone phone = getPhone(subId);
9861 if (phone != null) {
9862 phone.setDataRoamingEnabled(isEnabled);
9863 }
9864 } finally {
9865 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009866 }
9867 }
9868
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009869 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009870 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009871 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009872 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009873 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009874
joonhunshin4ac60942023-11-15 15:23:39 +00009875 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9876 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9877
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009878 boolean isAllowed = true;
9879 final long identity = Binder.clearCallingIdentity();
9880 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009881 Phone phone = getPhone(subId);
9882 if (phone != null) {
9883 isAllowed = phone.isCspPlmnEnabled();
9884 }
9885 } finally {
9886 Binder.restoreCallingIdentity(identity);
9887 }
9888 return isAllowed;
9889 }
9890
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009891 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9892 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009893 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009894 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009895 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009896 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9897 if (phone == null) {
9898 return false;
9899 }
9900 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9901 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9902 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009903 }
9904
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009905 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009906 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009907 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009908 mApp.getSystemService(AppOpsManager.class)
9909 .checkPackage(Binder.getCallingUid(), callingPackage);
9910
Jordan Liu1e142fc2019-04-22 15:10:43 -07009911 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009912 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009913 try {
9914 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009915 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009916 } catch (SecurityException e) {
9917 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9918 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009919 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009920 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009921 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009922 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009923 }
joonhunshin4ac60942023-11-15 15:23:39 +00009924
9925 enforceTelephonyFeatureWithException(callingPackage,
9926 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9927
sandeepjsb6c87872021-09-27 15:34:44 +00009928 // checking compatibility, if calling app's target SDK is T and beyond.
9929 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9930 Binder.getCallingUid())) {
9931 isIccIdAccessRestricted = true;
9932 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009933 final long identity = Binder.clearCallingIdentity();
9934 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009935 UiccController uiccController = UiccController.getInstance();
9936 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009937 if (hasReadPermission) {
9938 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009939 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009940
9941 // Remove private info if the caller doesn't have access
9942 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9943 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009944 //setting the value after compatibility check
9945 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009946 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9947 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009948 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009949 if (card == null) {
9950 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009951 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009952 continue;
9953 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009954 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9955 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009956 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009957 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009958 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009959 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9960 for (UiccPortInfo portInfo : portInfos) {
9961 UiccPort port = uiccController.getUiccPortForSlot(
9962 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9963 if (port == null) {
9964 // assume no access if port is null
9965 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9966 continue;
9967 }
9968 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9969 uiccPortInfos.add(portInfo);
9970 } else {
9971 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9972 }
9973 }
9974 filteredInfos.add(new UiccCardInfo(
9975 cardInfo.isEuicc(),
9976 cardInfo.getCardId(),
9977 null,
9978 cardInfo.getPhysicalSlotIndex(),
9979 cardInfo.isRemovable(),
9980 cardInfo.isMultipleEnabledProfilesSupported(),
9981 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009982 }
9983 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009984 } finally {
9985 Binder.restoreCallingIdentity(identity);
9986 }
9987 }
9988
sandeepjsb6c87872021-09-27 15:34:44 +00009989 /**
9990 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9991 * generally private and require carrier privileges to view.
9992 *
9993 * @hide
9994 */
9995 @NonNull
9996 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9997 List<UiccPortInfo> portinfo = new ArrayList<>();
9998 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9999 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
10000 }
10001 return new UiccCardInfo(
10002 cardInfo.isEuicc(),
10003 cardInfo.getCardId(),
10004 null,
10005 cardInfo.getPhysicalSlotIndex(),
10006 cardInfo.isRemovable(),
10007 cardInfo.isMultipleEnabledProfilesSupported(),
10008 portinfo
10009 );
10010 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010011
sandeepjsb6c87872021-09-27 15:34:44 +000010012 /**
10013 * @hide
10014 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10015 * These values are generally private and require carrier privileges to view.
10016 */
10017 @NonNull
10018 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10019 return new UiccPortInfo(
10020 UiccPortInfo.ICCID_REDACTED,
10021 portInfo.getPortIndex(),
10022 portInfo.getLogicalSlotIndex(),
10023 portInfo.isActive()
10024 );
10025 }
10026 @Override
10027 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010028 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010029 mApp.getSystemService(AppOpsManager.class)
10030 .checkPackage(Binder.getCallingUid(), callingPackage);
10031
sandeepjsb6c87872021-09-27 15:34:44 +000010032 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010033
Aman Guptaf3c90b32022-03-17 04:54:16 +000010034 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10035 // we are reading iccId which is PII data.
10036 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010037
joonhunshin4ac60942023-11-15 15:23:39 +000010038 enforceTelephonyFeatureWithException(callingPackage,
10039 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10040
sandeepjsb6c87872021-09-27 15:34:44 +000010041 // checking compatibility, if calling app's target SDK is T and beyond.
10042 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10043 Binder.getCallingUid())) {
10044 isLogicalSlotAccessRestricted = true;
10045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010046 final long identity = Binder.clearCallingIdentity();
10047 try {
10048 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010049 if (slots == null || slots.length == 0) {
10050 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010051 return null;
10052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010053 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10054 for (int i = 0; i < slots.length; i++) {
10055 UiccSlot slot = slots[i];
10056 if (slot == null) {
10057 continue;
10058 }
10059
Jordan Liu7be7e652019-05-06 18:55:02 +000010060 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010061 UiccCard card = slot.getUiccCard();
10062 if (card != null) {
10063 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010064 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010065 cardId = slot.getEid();
10066 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010067 // If cardId is null, use iccId of default port as cardId.
10068 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010070 }
10071
Jordan Liu857451f2019-05-09 16:35:35 -070010072 if (cardId != null) {
10073 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10074 // if cardId is an EID, it's all digits so this is fine
10075 cardId = IccUtils.stripTrailingFs(cardId);
10076 }
10077
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010078 int cardState = 0;
10079 switch (slot.getCardState()) {
10080 case CARDSTATE_ABSENT:
10081 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10082 break;
10083 case CARDSTATE_PRESENT:
10084 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10085 break;
10086 case CARDSTATE_ERROR:
10087 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10088 break;
10089 case CARDSTATE_RESTRICTED:
10090 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10091 break;
10092 default:
10093 break;
10094
10095 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010096 List<UiccPortInfo> portInfos = new ArrayList<>();
10097 int[] portIndexes = slot.getPortList();
10098 for (int portIdx : portIndexes) {
10099 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010100 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010101 portInfos.add(new UiccPortInfo(iccId, portIdx,
10102 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010103 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010104 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010105 slot.isEuicc(),
10106 cardId,
10107 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010108 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010109 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010110 //setting the value after compatibility check
10111 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010112 }
10113 return infos;
10114 } finally {
10115 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010116 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010117 }
10118
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010119 /* Returns null if doesn't have read permission or carrier privilege access. */
10120 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10121 boolean hasReadPermission) {
10122 String iccId = slot.getIccId(portIndex);
10123 if (hasReadPermission) { // if has read permission
10124 return iccId;
10125 } else {
10126 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10127 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10128 // if no read permission, checking carrier privilege access
10129 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10130 return iccId;
10131 }
10132 }
10133 }
10134 // No read permission or carrier privilege access.
10135 return UiccPortInfo.ICCID_REDACTED;
10136 }
10137
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010138 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010139 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010140 public boolean switchSlots(int[] physicalSlots) {
10141 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010142
joonhunshin4ac60942023-11-15 15:23:39 +000010143 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10144 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10145
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010146 final long identity = Binder.clearCallingIdentity();
10147 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010148 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10149 for (int i = 0; i < physicalSlots.length; i++) {
10150 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10151 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10152 physicalSlots[i], i));
10153 }
10154 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010155 } finally {
10156 Binder.restoreCallingIdentity(identity);
10157 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010158 }
Jack Yu4c988042018-02-27 15:30:01 -080010159
10160 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010161 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10162 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10163 enforceModifyPermission();
10164
joonhunshin4ac60942023-11-15 15:23:39 +000010165 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10166 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10167
sandeepjsb6c87872021-09-27 15:34:44 +000010168 final long identity = Binder.clearCallingIdentity();
10169 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010170 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010171 } finally {
10172 Binder.restoreCallingIdentity(identity);
10173 }
10174 }
10175
10176 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010177 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010178 enforceTelephonyFeatureWithException(callingPackage,
10179 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10180
Jordan Liu7de49fa2018-12-06 14:48:49 -080010181 final long identity = Binder.clearCallingIdentity();
10182 try {
10183 return UiccController.getInstance().getCardIdForDefaultEuicc();
10184 } finally {
10185 Binder.restoreCallingIdentity(identity);
10186 }
10187 }
10188
Pengquan Meng85728fb2018-03-12 16:31:21 -070010189 /**
goneil47ffb6e2018-04-06 15:40:58 -070010190 * A test API to reload the UICC profile.
10191 *
10192 * <p>Requires that the calling app has permission
10193 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10194 * @hide
10195 */
10196 @Override
10197 public void refreshUiccProfile(int subId) {
10198 enforceModifyPermission();
10199
10200 final long identity = Binder.clearCallingIdentity();
10201 try {
10202 Phone phone = getPhone(subId);
10203 if (phone == null) {
10204 return;
10205 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010206 UiccPort uiccPort = phone.getUiccPort();
10207 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010208 return;
10209 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010210 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010211 if (uiccProfile == null) {
10212 return;
10213 }
10214 uiccProfile.refresh();
10215 } finally {
10216 Binder.restoreCallingIdentity(identity);
10217 }
10218 }
10219
10220 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010221 * Returns false if the mobile data is disabled by default, otherwise return true.
10222 */
10223 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010224 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010225 }
10226
10227 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010228 * Returns the default network type for the given {@code subId}, if the default network type is
10229 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10230 */
10231 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010232 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010233 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010234 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10235 return list.get(phoneId);
10236 }
10237 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010238 }
fionaxua13278b2018-03-21 00:08:13 -070010239
10240 @Override
10241 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010242 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010243 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010244
10245 final long identity = Binder.clearCallingIdentity();
10246 try {
10247 final Phone phone = getPhone(subId);
10248 if (phone == null) {
10249 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10250 return;
10251 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010252 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10253 if (cpt != null) {
10254 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10255 }
10256 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010257 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10258 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010259 if (carrierPrivilegeRules == null) {
10260 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10261 } else {
10262 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010264 } finally {
10265 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010266 }
fionaxua13278b2018-03-21 00:08:13 -070010267 }
10268
10269 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010270 public void setCarrierServicePackageOverride(
10271 int subId, String carrierServicePackage, String callingPackage) {
10272 TelephonyPermissions.enforceShellOnly(
10273 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10274
Benedict Wong66477622023-02-03 23:30:57 +000010275 final long identity = Binder.clearCallingIdentity();
10276 try {
10277 final Phone phone = getPhone(subId);
10278 if (phone == null || phone.getSubId() != subId) {
10279 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10280 throw new IllegalArgumentException("No phone for subid");
10281 }
10282 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10283 if (cpt == null) {
10284 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10285 throw new IllegalStateException("No CPT for phone");
10286 }
10287 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10288 } finally {
10289 Binder.restoreCallingIdentity(identity);
10290 }
10291 }
10292
10293 @Override
fionaxua13278b2018-03-21 00:08:13 -070010294 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010295 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010296
10297 final long identity = Binder.clearCallingIdentity();
10298 try {
10299 final Phone phone = getPhone(subId);
10300 if (phone == null) {
10301 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10302 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10303 }
10304 return phone.getCarrierIdListVersion();
10305 } finally {
10306 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010307 }
fionaxua13278b2018-03-21 00:08:13 -070010308 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010309
10310 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010311 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10312 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010314 mApp, subId, callingPackage, callingFeatureId,
10315 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010316 return -1;
10317 }
10318
10319 final long identity = Binder.clearCallingIdentity();
10320 try {
10321 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10322 } finally {
10323 Binder.restoreCallingIdentity(identity);
10324 }
10325 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010326
10327 @Override
10328 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010329 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010330 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010331 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010332
joonhunshin4ac60942023-11-15 15:23:39 +000010333 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10334 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10335
Pengquan Menga1bb6272018-09-06 09:59:22 -070010336 final long identity = Binder.clearCallingIdentity();
10337 try {
10338 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10339 } finally {
10340 Binder.restoreCallingIdentity(identity);
10341 }
10342 }
10343
10344 @Override
10345 public boolean setCdmaRoamingMode(int subId, int mode) {
10346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10347 mApp, subId, "setCdmaRoamingMode");
10348
joonhunshin4ac60942023-11-15 15:23:39 +000010349 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10350 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10351
Pengquan Menga1bb6272018-09-06 09:59:22 -070010352 final long identity = Binder.clearCallingIdentity();
10353 try {
10354 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10355 } finally {
10356 Binder.restoreCallingIdentity(identity);
10357 }
10358 }
10359
10360 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010361 public int getCdmaSubscriptionMode(int subId) {
10362 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010363 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010364 mApp, subId, "getCdmaSubscriptionMode");
10365
joonhunshin4ac60942023-11-15 15:23:39 +000010366 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10367 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10368
Sarah Chinbaab1432020-10-28 13:46:24 -070010369 final long identity = Binder.clearCallingIdentity();
10370 try {
10371 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10372 } finally {
10373 Binder.restoreCallingIdentity(identity);
10374 }
10375 }
10376
10377 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010378 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10380 mApp, subId, "setCdmaSubscriptionMode");
10381
joonhunshin4ac60942023-11-15 15:23:39 +000010382 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10383 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10384
Pengquan Menga1bb6272018-09-06 09:59:22 -070010385 final long identity = Binder.clearCallingIdentity();
10386 try {
10387 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10388 } finally {
10389 Binder.restoreCallingIdentity(identity);
10390 }
10391 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010392
sqianc5eccab2018-10-19 18:46:41 -070010393 @Override
sqian8c685422019-02-22 15:55:18 -080010394 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010395 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010397 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10398 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010399 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10400 }
joonhunshin4ac60942023-11-15 15:23:39 +000010401
10402 enforceTelephonyFeatureWithException(callingPackage,
10403 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10404
sqian11b7a0e2018-12-05 18:48:28 -080010405 final long identity = Binder.clearCallingIdentity();
10406 try {
sqian854d44b2018-12-12 16:48:18 -080010407 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10408 for (Phone phone: PhoneFactory.getPhones()) {
10409 if (phone.getEmergencyNumberTracker() != null
10410 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10411 emergencyNumberListInternal.put(
10412 phone.getSubId(),
10413 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10414 }
sqian11b7a0e2018-12-05 18:48:28 -080010415 }
sqian854d44b2018-12-12 16:48:18 -080010416 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010417 } finally {
10418 Binder.restoreCallingIdentity(identity);
10419 }
sqianc5eccab2018-10-19 18:46:41 -070010420 }
10421
10422 @Override
sqian8c685422019-02-22 15:55:18 -080010423 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010424 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010425 if (!exactMatch) {
10426 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010427 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010428 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010429 }
joonhunshin4ac60942023-11-15 15:23:39 +000010430
Tomasz Wasilczykef763582024-09-17 13:50:32 -070010431 if (!mApp.getResources().getBoolean(
10432 com.android.internal.R.bool.config_force_phone_globals_creation)) {
10433 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10434 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10435 }
joonhunshin4ac60942023-11-15 15:23:39 +000010436
sqian11b7a0e2018-12-05 18:48:28 -080010437 final long identity = Binder.clearCallingIdentity();
10438 try {
sqian854d44b2018-12-12 16:48:18 -080010439 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010440 //Note: we ignore passed in param exactMatch. We can remove it once
10441 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010442 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010443 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010444 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010445 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010446 }
sqian11b7a0e2018-12-05 18:48:28 -080010447 }
10448 return false;
10449 } finally {
10450 Binder.restoreCallingIdentity(identity);
10451 }
10452 }
10453
sqianf4ca7ed2019-01-15 18:32:07 -080010454 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010455 * Start emergency callback mode for GsmCdmaPhone for testing.
10456 */
10457 @Override
10458 public void startEmergencyCallbackMode() {
10459 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10460 "startEmergencyCallbackMode");
10461 enforceModifyPermission();
10462 final long identity = Binder.clearCallingIdentity();
10463 try {
10464 for (Phone phone : PhoneFactory.getPhones()) {
10465 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10466 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10467 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10468 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10469 gsmCdmaPhone.obtainMessage(
10470 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10471 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10472 }
10473 }
10474 } finally {
10475 Binder.restoreCallingIdentity(identity);
10476 }
10477 }
10478
10479 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010480 * Update emergency number list for test mode.
10481 */
10482 @Override
10483 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10484 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10485 "updateEmergencyNumberListTestMode");
10486
10487 final long identity = Binder.clearCallingIdentity();
10488 try {
10489 for (Phone phone: PhoneFactory.getPhones()) {
10490 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10491 if (tracker != null) {
10492 tracker.executeEmergencyNumberTestModeCommand(action, num);
10493 }
10494 }
10495 } finally {
10496 Binder.restoreCallingIdentity(identity);
10497 }
10498 }
10499
10500 /**
10501 * Get the full emergency number list for test mode.
10502 */
10503 @Override
10504 public List<String> getEmergencyNumberListTestMode() {
10505 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10506 "getEmergencyNumberListTestMode");
10507
10508 final long identity = Binder.clearCallingIdentity();
10509 try {
10510 Set<String> emergencyNumbers = new HashSet<>();
10511 for (Phone phone: PhoneFactory.getPhones()) {
10512 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10513 if (tracker != null) {
10514 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10515 emergencyNumbers.add(num.getNumber());
10516 }
10517 }
10518 }
10519 return new ArrayList<>(emergencyNumbers);
10520 } finally {
10521 Binder.restoreCallingIdentity(identity);
10522 }
10523 }
10524
chen xud6b45bd2018-10-30 22:27:10 -070010525 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010526 public int getEmergencyNumberDbVersion(int subId) {
10527 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10528
joonhunshin4ac60942023-11-15 15:23:39 +000010529 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10530 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10531
Shuo Qian3b6ee772019-11-13 17:43:31 -080010532 final long identity = Binder.clearCallingIdentity();
10533 try {
10534 final Phone phone = getPhone(subId);
10535 if (phone == null) {
10536 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10537 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10538 }
10539 return phone.getEmergencyNumberDbVersion();
10540 } finally {
10541 Binder.restoreCallingIdentity(identity);
10542 }
10543 }
10544
10545 @Override
10546 public void notifyOtaEmergencyNumberDbInstalled() {
10547 enforceModifyPermission();
10548
joonhunshin4ac60942023-11-15 15:23:39 +000010549 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10550 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10551
Shuo Qian3b6ee772019-11-13 17:43:31 -080010552 final long identity = Binder.clearCallingIdentity();
10553 try {
10554 for (Phone phone: PhoneFactory.getPhones()) {
10555 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10556 if (tracker != null) {
10557 tracker.updateOtaEmergencyNumberDatabase();
10558 }
10559 }
10560 } finally {
10561 Binder.restoreCallingIdentity(identity);
10562 }
10563 }
10564
10565 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010566 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010567 enforceActiveEmergencySessionPermission();
10568
joonhunshin4ac60942023-11-15 15:23:39 +000010569 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10570 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10571
Shuo Qian3b6ee772019-11-13 17:43:31 -080010572 final long identity = Binder.clearCallingIdentity();
10573 try {
10574 for (Phone phone: PhoneFactory.getPhones()) {
10575 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10576 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010577 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10578 }
10579 }
10580 } finally {
10581 Binder.restoreCallingIdentity(identity);
10582 }
10583 }
10584
10585 @Override
10586 public void resetOtaEmergencyNumberDbFilePath() {
10587 enforceActiveEmergencySessionPermission();
10588
joonhunshin4ac60942023-11-15 15:23:39 +000010589 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10590 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10591
Shuo Qianc373f112020-03-05 17:55:34 -080010592 final long identity = Binder.clearCallingIdentity();
10593 try {
10594 for (Phone phone: PhoneFactory.getPhones()) {
10595 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10596 if (tracker != null) {
10597 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010598 }
10599 }
10600 } finally {
10601 Binder.restoreCallingIdentity(identity);
10602 }
10603 }
10604
10605 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010606 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10607 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10608 Phone phone = getPhone(subId);
10609 if (phone == null) {
10610 return null;
10611 }
10612 final long identity = Binder.clearCallingIdentity();
10613 try {
10614 UiccProfile profile = UiccController.getInstance()
10615 .getUiccProfileForPhone(phone.getPhoneId());
10616 if (profile != null) {
10617 return profile.getCertsFromCarrierPrivilegeAccessRules();
10618 }
10619 } finally {
10620 Binder.restoreCallingIdentity(identity);
10621 }
10622 return null;
10623 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010624
10625 /**
10626 * Enable or disable a modem stack.
10627 */
10628 @Override
10629 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10630 enforceModifyPermission();
10631
joonhunshin4ac60942023-11-15 15:23:39 +000010632 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10633 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10634
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010635 final long identity = Binder.clearCallingIdentity();
10636 try {
10637 Phone phone = PhoneFactory.getPhone(slotIndex);
10638 if (phone == null) {
10639 return false;
10640 } else {
10641 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10642 }
10643 } finally {
10644 Binder.restoreCallingIdentity(identity);
10645 }
10646 }
Michelecea4cf22018-12-21 15:00:11 -080010647
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010648 /**
10649 * Whether a modem stack is enabled or not.
10650 */
10651 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010652 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10653 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010654 Phone phone = PhoneFactory.getPhone(slotIndex);
10655 if (phone == null) return false;
10656
10657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010658 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10659 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010660 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10661 }
10662
joonhunshin4ac60942023-11-15 15:23:39 +000010663 enforceTelephonyFeatureWithException(callingPackage,
10664 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10665
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010666 final long identity = Binder.clearCallingIdentity();
10667 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010668 try {
10669 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10670 } catch (NoSuchElementException ex) {
10671 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10672 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010673 } finally {
10674 Binder.restoreCallingIdentity(identity);
10675 }
10676 }
10677
Michelecea4cf22018-12-21 15:00:11 -080010678 @Override
Michele0ea7d782019-03-19 14:58:42 -070010679 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010680 enforceModifyPermission();
10681
joonhunshin4ac60942023-11-15 15:23:39 +000010682 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10683 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10684
Michelecea4cf22018-12-21 15:00:11 -080010685 final long identity = Binder.clearCallingIdentity();
10686 try {
10687 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010688 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010689 .commit();
10690 } finally {
10691 Binder.restoreCallingIdentity(identity);
10692 }
10693 }
10694
10695 @Override
Michele0ea7d782019-03-19 14:58:42 -070010696 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010697 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010699 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10700 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010701 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010702 }
Michelecea4cf22018-12-21 15:00:11 -080010703
joonhunshin4ac60942023-11-15 15:23:39 +000010704 enforceTelephonyFeatureWithException(callingPackage,
10705 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10706
Michelecea4cf22018-12-21 15:00:11 -080010707 final long identity = Binder.clearCallingIdentity();
10708 try {
Michele0ea7d782019-03-19 14:58:42 -070010709 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010710 } finally {
10711 Binder.restoreCallingIdentity(identity);
10712 }
10713 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010714
Michele0ea7d782019-03-19 14:58:42 -070010715 @TelephonyManager.IsMultiSimSupportedResult
10716 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010717 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10718 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10719 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010720 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10721 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010722 }
10723 // Check if the hardware supports multisim functionality. If usage of multisim is not
10724 // supported by the modem, indicate that it is restricted.
10725 PhoneCapability staticCapability =
10726 mPhoneConfigurationManager.getStaticPhoneCapability();
10727 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010728 loge("isMultiSimSupportedInternal: no static configuration available");
10729 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010730 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010731 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010732 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10733 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010734 }
10735 // Check if support of multiple SIMs is restricted by carrier
10736 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010737 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010738 }
10739
Michele0ea7d782019-03-19 14:58:42 -070010740 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010741 }
10742
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010743 /**
10744 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010745 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10746 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10747 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010748 * @param numOfSims number of active sims we want to switch to
10749 */
10750 @Override
10751 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010752 if (numOfSims == 1) {
10753 enforceModifyPermission();
10754 } else {
10755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10756 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10757 }
joonhunshin4ac60942023-11-15 15:23:39 +000010758
10759 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10760 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10761
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010762 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010763
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010764 try {
Michele30b57b22019-03-01 12:01:14 -080010765 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010766 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010767 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10768 return;
10769 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010770 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10771 } finally {
10772 Binder.restoreCallingIdentity(identity);
10773 }
10774 }
10775
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010776 @Override
10777 public boolean isApplicationOnUicc(int subId, int appType) {
10778 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010779
10780 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10781 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10782
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010783 Phone phone = getPhone(subId);
10784 if (phone == null) {
10785 return false;
10786 }
10787 final long identity = Binder.clearCallingIdentity();
10788 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010789 UiccPort uiccPort = phone.getUiccPort();
10790 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010791 return false;
10792 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010793 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010794 if (uiccProfile == null) {
10795 return false;
10796 }
10797 if (TelephonyManager.APPTYPE_SIM <= appType
10798 && appType <= TelephonyManager.APPTYPE_ISIM) {
10799 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10800 }
10801 return false;
10802 } finally {
10803 Binder.restoreCallingIdentity(identity);
10804 }
10805 }
10806
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010807 /**
chen xub4baa772019-04-03 10:23:41 -070010808 * Get whether making changes to modem configurations will trigger reboot.
10809 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010810 */
10811 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010812 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10813 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010815 mApp, subId, callingPackage, callingFeatureId,
10816 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010817 return false;
10818 }
joonhunshin4ac60942023-11-15 15:23:39 +000010819
10820 enforceTelephonyFeatureWithException(callingPackage,
10821 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10822 "doesSwitchMultiSimConfigTriggerReboot");
10823
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010824 final long identity = Binder.clearCallingIdentity();
10825 try {
10826 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10827 } finally {
10828 Binder.restoreCallingIdentity(identity);
10829 }
10830 }
10831
Nathan Harold29f5f052019-02-15 13:41:57 -080010832 private void updateModemStateMetrics() {
10833 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10834 // TODO: check the state for each modem if the api is ready.
10835 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10836 }
10837
Pengquan Meng3889a572019-01-23 11:16:29 -080010838 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010839 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010840 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010841 // Verify that the callingPackage belongs to the calling UID
10842 mApp.getSystemService(AppOpsManager.class)
10843 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010844
10845 enforceTelephonyFeatureWithException(callingPackage,
10846 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10847
Pengquan Meng3889a572019-01-23 11:16:29 -080010848 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010849 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010850 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010851 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10852 if (slotInfos != null) {
10853 for (int i = 0; i < slotInfos.length; i++) {
10854 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10855 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10856 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10857 portInfo.getLogicalSlotIndex()));
10858 }
10859 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010860 }
10861 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010862 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010863 } finally {
10864 Binder.restoreCallingIdentity(identity);
10865 }
10866 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010867
10868 /**
10869 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010870 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010871 */
jimsunf9ec1622022-09-13 21:18:43 +080010872 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010873 @Override
10874 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010875 return getHalVersion(HAL_SERVICE_RADIO);
10876 }
10877
10878 /**
10879 * Get the HAL Version of a specific service
10880 */
10881 @Override
10882 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010883 Phone phone = getDefaultPhone();
10884 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010885 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010886 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10887 return hv.major * 100 + hv.minor;
10888 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010889
10890 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010891 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010892 *
10893 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010894 */
10895 @Override
sangyun097dcf72024-01-04 10:35:49 +090010896 public @Nullable String getCurrentPackageName() {
Jack Yube3fa442024-09-16 14:39:45 -070010897 if (mFeatureFlags.hsumPackageManager()) {
10898 PackageManager pm = mApp.getBaseContext().createContextAsUser(
10899 Binder.getCallingUserHandle(), 0).getPackageManager();
10900 if (pm == null) return null;
10901 String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid());
10902 return (callingUids == null) ? null : callingUids[0];
10903 }
10904 if (mPackageManager == null) return null;
10905 String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid());
10906 return (callingUids == null) ? null : callingUids[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010907 }
10908
10909 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010910 * @return The calling package name or "phone" if the caller is the phone process. This is done
10911 * because multiple Phone has multiple packages in it and the first element in the array is not
10912 * actually always the caller.
10913 * Note: This is for logging purposes only and should not be used for security checks.
10914 */
10915 private String getCurrentPackageNameOrPhone() {
Jack Yube3fa442024-09-16 14:39:45 -070010916 PackageManager pm;
10917 if (mFeatureFlags.hsumPackageManager()) {
10918 pm = mApp.getBaseContext().createContextAsUser(
10919 Binder.getCallingUserHandle(), 0).getPackageManager();
10920 } else {
10921 pm = mApp.getPackageManager();
10922 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010923 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10924 if (uidName != null && !uidName.isEmpty()) return uidName;
10925 return getCurrentPackageName();
10926 }
10927
10928 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010929 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10930 * corresponding network requests on a subId.
10931 *
10932 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010933 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010934 * 2) APN is un-metered for this subscription, or
10935 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010936 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010937 *
10938 * @return whether data is allowed for a apn type.
10939 *
10940 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010941 */
10942 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010943 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010944 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10945 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010946
joonhunshin4ac60942023-11-15 15:23:39 +000010947 enforceTelephonyFeatureWithException(callingPackage,
10948 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10949
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010950 // Now that all security checks passes, perform the operation as ourselves.
10951 final long identity = Binder.clearCallingIdentity();
10952 try {
10953 Phone phone = getPhone(subId);
10954 if (phone == null) return false;
10955
Jack Yu27422a52022-03-21 10:38:05 -070010956 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010957 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010958 isMetered = phone.getDataNetworkController().getDataConfigManager()
10959 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10960 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010961 isDataEnabled = (phone.getDataSettingsManager() != null)
10962 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010963 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010964 } finally {
10965 Binder.restoreCallingIdentity(identity);
10966 }
10967 }
10968
10969 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010970 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010971 enforceReadPrivilegedPermission("isApnMetered");
10972
joonhunshin4ac60942023-11-15 15:23:39 +000010973 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10974 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10975
Malcolm Chene5ad5792019-04-18 13:51:02 -070010976 // Now that all security checks passes, perform the operation as ourselves.
10977 final long identity = Binder.clearCallingIdentity();
10978 try {
10979 Phone phone = getPhone(subId);
10980 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010981 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10982 DataUtils.apnTypeToNetworkCapability(apnType),
10983 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010984 } finally {
10985 Binder.restoreCallingIdentity(identity);
10986 }
10987 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010988
10989 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010990 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10991 int subscriptionId, IBooleanConsumer resultCallback) {
10992 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010993
10994 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10995 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10996
Hall Liu73f5d362020-01-20 13:42:00 -080010997 long token = Binder.clearCallingIdentity();
10998 try {
10999 Phone phone = getPhone(subscriptionId);
11000 if (phone == null) {
11001 try {
11002 if (resultCallback != null) {
11003 resultCallback.accept(false);
11004 }
11005 } catch (RemoteException e) {
11006 // ignore
11007 }
11008 return;
11009 }
11010 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
11011 Pair.create(specifiers, (x) -> {
11012 try {
11013 if (resultCallback != null) {
11014 resultCallback.accept(x);
11015 }
11016 } catch (RemoteException e) {
11017 // ignore
11018 }
11019 });
11020 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
11021 } finally {
11022 Binder.restoreCallingIdentity(token);
11023 }
11024 }
11025
11026 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080011027 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
11028 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070011029 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080011030 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000011031
11032 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11033 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
11034
Sarah Chin679c08a2020-11-18 13:39:35 -080011035 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11036 final long identity = Binder.clearCallingIdentity();
11037 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080011038 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
11039 if (result instanceof IllegalStateException) {
11040 throw (IllegalStateException) result;
11041 }
11042 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011043 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11044 return specifiers;
11045 } finally {
11046 Binder.restoreCallingIdentity(identity);
11047 }
11048 }
11049
11050 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011051 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011052 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011053
11054 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11055 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11056
Jack Yu8b766fc2022-03-21 09:42:33 -070011057 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011058 }
11059
11060 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011061 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11062 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011063 if (callingPackage == null) {
11064 callingPackage = getCurrentPackageName();
11065 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011066 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11067 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011068 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11069 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011070 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11071 }
11072 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11073 Intent intent = new Intent();
11074 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11075 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11076 // Bring up choose default SMS subscription dialog right now
11077 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11078 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
Jack Yu58d04bd2024-09-10 17:32:39 -070011079 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Brad Ebingera63db5f2019-04-23 16:31:13 -070011080 }
chen xud5ca2d52019-05-28 15:20:57 -070011081
11082 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011083 public void showSwitchToManagedProfileDialog() {
11084 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011085 try {
11086 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11087 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11088 // for work telephony.
11089 Intent intent = new Intent(Intent.ACTION_SENDTO);
11090 intent.setData(Uri.parse("smsto:"));
11091 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011092 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011093 } catch (ActivityNotFoundException e) {
11094 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11095 Intent intent = new Intent();
11096 intent.setClass(mApp, ErrorDialogActivity.class);
11097 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011098 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011099 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011100 }
11101
11102 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011103 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011104 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11105 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11106
chen xud5ca2d52019-05-28 15:20:57 -070011107 //TODO investigate if this API should require proper permission check in R b/133791609
11108 final long identity = Binder.clearCallingIdentity();
11109 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011110 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11111 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11112 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11113 return carrierUAProfUrl;
11114 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011115 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11116 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011117 } finally {
11118 Binder.restoreCallingIdentity(identity);
11119 }
11120 }
11121
11122 @Override
11123 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011124 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11125 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11126
chen xud5ca2d52019-05-28 15:20:57 -070011127 //TODO investigate if this API should require proper permission check in R b/133791609
11128 final long identity = Binder.clearCallingIdentity();
11129 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011130 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11131 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11132 if (!TextUtils.isEmpty(carrierUserAgent)) {
11133 return carrierUserAgent;
11134 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011135 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11136 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011137 } finally {
11138 Binder.restoreCallingIdentity(identity);
11139 }
11140 }
Jack Yub07d4972019-05-28 16:12:25 -070011141
11142 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011143 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11144 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011145
joonhunshin4ac60942023-11-15 15:23:39 +000011146 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11147 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11148
Jack Yub07d4972019-05-28 16:12:25 -070011149 final long identity = Binder.clearCallingIdentity();
11150 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011151 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011152 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011153
Ling Maf188d502022-09-16 15:22:36 -070011154 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011155 } finally {
11156 Binder.restoreCallingIdentity(identity);
11157 }
11158 }
11159
11160 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011161 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011162 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011163 enforceModifyPermission();
11164
joonhunshin4ac60942023-11-15 15:23:39 +000011165 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11166 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11167
changbettyd5c246e2019-12-24 15:40:37 +080011168 final long identity = Binder.clearCallingIdentity();
11169 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011170 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011171 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011172
Ling Maf188d502022-09-16 15:22:36 -070011173 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011174 } finally {
11175 Binder.restoreCallingIdentity(identity);
11176 }
11177 }
11178
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011179 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011180 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011181 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11182 * otherwise.
11183 */
11184 @Override
11185 public void setCepEnabled(boolean isCepEnabled) {
11186 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11187
11188 final long identity = Binder.clearCallingIdentity();
11189 try {
11190 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11191 for (Phone phone : PhoneFactory.getPhones()) {
11192 Phone defaultPhone = phone.getImsPhone();
11193 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11194 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11195 ImsPhoneCallTracker imsPhoneCallTracker =
11196 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11197 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11198 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11199 + imsPhone.getMsisdn());
11200 }
11201 }
11202 } finally {
11203 Binder.restoreCallingIdentity(identity);
11204 }
11205 }
allenwtsu46dcc572020-01-08 18:24:03 +080011206
11207 /**
11208 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11209 *
11210 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11211 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11212 * before being read.
11213 */
11214 @Override
11215 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11216 isCompressed) {
11217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11218 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011219 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11220 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11221 }
joonhunshin4ac60942023-11-15 15:23:39 +000011222
11223 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11224 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11225 Binder.getCallingUserHandle())) {
11226 if (!isImsAvailableOnDevice()) {
11227 // ProvisioningManager can not handle ServiceSpecificException.
11228 // Throw the IllegalStateException and annotate ProvisioningManager.
11229 throw new IllegalStateException("IMS not available on device.");
11230 }
11231 } else {
11232 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11233 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11234 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011235 }
11236
11237 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011238 try {
Hui Wang761a6682020-10-31 05:12:53 +000011239 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11240 } finally {
11241 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011242 }
11243 }
zoey chene02881a2019-12-30 16:11:23 +080011244
11245 @Override
11246 public boolean isIccLockEnabled(int subId) {
11247 enforceReadPrivilegedPermission("isIccLockEnabled");
11248
joonhunshin4ac60942023-11-15 15:23:39 +000011249 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11250 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11251
zoey chene02881a2019-12-30 16:11:23 +080011252 // Now that all security checks passes, perform the operation as ourselves.
11253 final long identity = Binder.clearCallingIdentity();
11254 try {
11255 Phone phone = getPhone(subId);
11256 if (phone != null && phone.getIccCard() != null) {
11257 return phone.getIccCard().getIccLockEnabled();
11258 } else {
11259 return false;
11260 }
11261 } finally {
11262 Binder.restoreCallingIdentity(identity);
11263 }
11264 }
11265
11266 /**
11267 * Set the ICC pin lock enabled or disabled.
11268 *
11269 * @return an integer representing the status of IccLock enabled or disabled in the following
11270 * three cases:
11271 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11272 * successfully.
11273 * - Positive number and zero for remaining password attempts.
11274 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11275 *
11276 */
11277 @Override
11278 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11279 enforceModifyPermission();
11280
joonhunshin4ac60942023-11-15 15:23:39 +000011281 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11282 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11283
zoey chene02881a2019-12-30 16:11:23 +080011284 Phone phone = getPhone(subId);
11285 if (phone == null) {
11286 return 0;
11287 }
11288 // Now that all security checks passes, perform the operation as ourselves.
11289 final long identity = Binder.clearCallingIdentity();
11290 try {
11291 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11292 new Pair<Boolean, String>(enabled, password), phone, null);
11293 return attemptsRemaining;
11294
11295 } catch (Exception e) {
11296 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11297 } finally {
11298 Binder.restoreCallingIdentity(identity);
11299 }
11300 return 0;
11301 }
11302
11303 /**
11304 * Change the ICC password used in ICC pin lock.
11305 *
11306 * @return an integer representing the status of IccLock changed in the following three cases:
11307 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11308 * - Positive number and zero for remaining password attempts.
11309 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11310 *
11311 */
11312 @Override
11313 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11314 enforceModifyPermission();
11315
joonhunshin4ac60942023-11-15 15:23:39 +000011316 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11317 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11318
zoey chene02881a2019-12-30 16:11:23 +080011319 Phone phone = getPhone(subId);
11320 if (phone == null) {
11321 return 0;
11322 }
11323 // Now that all security checks passes, perform the operation as ourselves.
11324 final long identity = Binder.clearCallingIdentity();
11325 try {
11326 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11327 new Pair<String, String>(oldPassword, newPassword), phone, null);
11328 return attemptsRemaining;
11329
11330 } catch (Exception e) {
11331 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11332 } finally {
11333 Binder.restoreCallingIdentity(identity);
11334 }
11335 return 0;
11336 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011337
11338 /**
11339 * Request for receiving user activity notification
11340 */
11341 @Override
11342 public void requestUserActivityNotification() {
11343 if (!mNotifyUserActivity.get()
11344 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11345 mNotifyUserActivity.set(true);
11346 }
11347 }
11348
11349 /**
11350 * Called when userActivity is signalled in the power manager.
11351 * This is safe to call from any thread, with any window manager locks held or not.
11352 */
11353 @Override
11354 public void userActivity() {
11355 // ***************************************
11356 // * Inherited from PhoneWindowManager *
11357 // ***************************************
11358 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11359 // WITH ITS LOCKS HELD.
11360 //
11361 // This code must be VERY careful about the locks
11362 // it acquires.
11363 // In fact, the current code acquires way too many,
11364 // and probably has lurking deadlocks.
11365
Jack Yu86374492024-09-16 13:05:44 -070011366 if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
Peter Wangdafb9ac2020-01-15 14:13:38 -080011367 throw new SecurityException("Only the OS may call notifyUserActivity()");
11368 }
11369
11370 if (mNotifyUserActivity.getAndSet(false)) {
11371 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11372 USER_ACTIVITY_NOTIFICATION_DELAY);
11373 }
11374 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011375
11376 @Override
11377 public boolean canConnectTo5GInDsdsMode() {
11378 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11379 }
Jack Yud10cdd42020-09-28 20:28:01 -070011380
11381 @Override
11382 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11383 String callingFeatureId) {
11384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11385 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11386 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11387 }
11388
joonhunshin4ac60942023-11-15 15:23:39 +000011389 enforceTelephonyFeatureWithException(callingPackage,
11390 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11391
Jack Yud10cdd42020-09-28 20:28:01 -070011392 Phone phone = getPhone(subId);
11393 if (phone == null) {
11394 throw new RuntimeException("phone is not available");
11395 }
11396 // Now that all security checks passes, perform the operation as ourselves.
11397 final long identity = Binder.clearCallingIdentity();
11398 try {
11399 return phone.getEquivalentHomePlmns();
11400 } finally {
11401 Binder.restoreCallingIdentity(identity);
11402 }
11403 }
Daniel Bright59e67312020-11-13 11:49:37 -080011404
11405 @Override
11406 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011407 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011408 if (!mApp.getResources().getBoolean(
11409 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11410 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11411 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11412 "isRadioInterfaceCapabilitySupported");
11413 }
joonhunshin4ac60942023-11-15 15:23:39 +000011414
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011415 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011416 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011417 if (radioInterfaceCapabilities == null) {
11418 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011419 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011420 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011421 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011422
Hui Wang641e81c2020-10-12 12:14:23 -070011423 @Override
11424 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11425 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011426 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11427 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11428 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11429 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11430 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011431
11432 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11433 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11434
Hui Wang641e81c2020-10-12 12:14:23 -070011435 if (DBG) {
11436 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11437 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11438 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11439 }
11440
11441 if (!SubscriptionManager.isValidSubscriptionId(subId)
11442 || appType < TelephonyManager.APPTYPE_UNKNOWN
11443 || appType > TelephonyManager.APPTYPE_ISIM
11444 || nafUrl == null || securityProtocol == null || callback == null) {
11445 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11446 if (callback != null) {
11447 try {
11448 callback.onAuthenticationFailure(
11449 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11450 } catch (RemoteException exception) {
11451 log("Fail to notify onAuthenticationFailure due to " + exception);
11452 }
11453 return;
11454 }
11455 }
11456
11457 final long token = Binder.clearCallingIdentity();
11458 try {
11459 getGbaManager(subId).bootstrapAuthenticationRequest(
11460 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011461 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011462 } finally {
11463 Binder.restoreCallingIdentity(token);
11464 }
11465 }
11466
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011467 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011468 * Attempts to set the radio power state for all phones for thermal reason.
11469 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011470 * requested radio power state will actually be set. See {@link
11471 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11472 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011473 * @param enable {@code true} if trying to turn radio on.
11474 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11475 * false}.
11476 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011477 private boolean setRadioPowerForThermal(boolean enable) {
11478 boolean isPhoneAvailable = false;
11479 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11480 Phone phone = PhoneFactory.getPhone(i);
11481 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011482 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011483 isPhoneAvailable = true;
11484 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011485 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011486
11487 // return true if successfully informed the phone object about the thermal radio power
11488 // request.
11489 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011490 }
11491
11492 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011493 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011494 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11495 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11496 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11497 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11498 throw new IllegalArgumentException("modem does not support data throttling");
11499 }
11500
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011501 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11502 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011503 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011504 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11505 }
11506
Sarah Chinecc78c42022-03-31 21:16:48 -070011507 setDataEnabledForReason(
11508 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011509
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011510 if (isDataThrottlingSupported) {
11511 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011512 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011513 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11514 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11515 } else if (thermalMitigationResult
11516 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011517 log("Modem likely does not support data throttling on secondary carrier. Data " +
11518 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11519 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011520 }
11521 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011522 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011523
11524 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011525 }
11526
Jack Nudelman644b91a2021-03-12 14:09:48 -080011527 private static List<String> getThermalMitigationAllowlist(Context context) {
11528 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11529 for (String pckg : context.getResources()
11530 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11531 sThermalMitigationAllowlistedPackages.add(pckg);
11532 }
11533 }
11534
11535 return sThermalMitigationAllowlistedPackages;
11536 }
11537
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011538 private boolean isAnyPhoneInEmergencyState() {
11539 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11540 if (tm.isInEmergencyCall()) {
11541 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11542 return true;
11543 }
11544 for (Phone phone : PhoneFactory.getPhones()) {
11545 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11546 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011547 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11548 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011549 return true;
11550 }
11551 }
11552
11553 return false;
11554 }
11555
Jack Nudelman644b91a2021-03-12 14:09:48 -080011556 /**
11557 * Used by shell commands to add an authorized package name for thermal mitigation.
11558 * @param packageName name of package to be allowlisted
11559 * @param context
11560 */
11561 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11562 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11563 sThermalMitigationAllowlistedPackages.add(packageName);
11564 }
11565
11566 /**
11567 * Used by shell commands to remove an authorized package name for thermal mitigation.
11568 * @param packageName name of package to remove from allowlist
11569 * @param context
11570 */
11571 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11572 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11573 sThermalMitigationAllowlistedPackages.remove(packageName);
11574 }
11575
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011576 /**
11577 * Thermal mitigation request to control functionalities at modem.
11578 *
11579 * @param subId the id of the subscription.
11580 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011581 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011582 *
11583 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11584 */
11585 @Override
11586 @ThermalMitigationResult
11587 public int sendThermalMitigationRequest(
11588 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011589 ThermalMitigationRequest thermalMitigationRequest,
11590 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011591 enforceModifyPermission();
11592
Jack Nudelman644b91a2021-03-12 14:09:48 -080011593 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011594
11595 enforceTelephonyFeatureWithException(callingPackage,
11596 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11597
Jack Nudelman644b91a2021-03-12 14:09:48 -080011598 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11599 .contains(callingPackage)) {
11600 throw new SecurityException("Calling package must be configured in the device config. "
11601 + "calling package: " + callingPackage);
11602 }
11603
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011604 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11605 final long identity = Binder.clearCallingIdentity();
11606
11607 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11608 try {
11609 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11610 switch (thermalMitigationAction) {
11611 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11612 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011613 handleDataThrottlingRequest(subId,
11614 thermalMitigationRequest.getDataThrottlingRequest(),
11615 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011616 break;
11617 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11618 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11619 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11620 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11621 }
11622
11623 // Ensure that radio is on. If not able to power on due to phone being
11624 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011625 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011626 thermalMitigationResult =
11627 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11628 break;
11629 }
11630
11631 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011632 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011633 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11634 break;
11635 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11636 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11637 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11638 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11639 }
11640
11641 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11642 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011643 Phone phone = getPhone(subId);
11644 if (phone == null) {
11645 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011646 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011647 break;
11648 }
11649
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011650 TelephonyConnectionService service =
11651 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011652 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011653 Log.e(LOG_TAG, "An emergency call is pending");
11654 thermalMitigationResult =
11655 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11656 break;
11657 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011658 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011659 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011660 break;
11661 }
11662 } else {
11663 thermalMitigationResult =
11664 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11665 break;
11666 }
11667
11668 // Turn radio off. If not able to power off due to phone being unavailable,
11669 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011670 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011671 thermalMitigationResult =
11672 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11673 break;
11674 }
11675 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011676 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011677 break;
11678 default:
11679 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11680 + "not exist. Requested action: " + thermalMitigationAction);
11681 }
11682 } catch (IllegalArgumentException e) {
11683 throw e;
11684 } catch (Exception e) {
11685 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11686 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11687 } finally {
11688 Binder.restoreCallingIdentity(identity);
11689 }
11690
11691 if (DBG) {
11692 log("thermalMitigationRequest returning with thermalMitigationResult: "
11693 + thermalMitigationResult);
11694 }
11695
11696 return thermalMitigationResult;
11697 }
Hui Wang641e81c2020-10-12 12:14:23 -070011698
11699 /**
11700 * Set the GbaService Package Name that Telephony will bind to.
11701 *
11702 * @param subId The sim that the GbaService is associated with.
11703 * @param packageName The name of the package to be replaced with.
11704 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11705 */
11706 @Override
11707 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11708 enforceModifyPermission();
Jack Yu02533f12024-10-03 18:44:32 -070011709 int userId = ActivityManager.getCurrentUser();
Hui Wang641e81c2020-10-12 12:14:23 -070011710 final long identity = Binder.clearCallingIdentity();
11711 try {
Jack Yu02533f12024-10-03 18:44:32 -070011712 return getGbaManager(subId).overrideServicePackage(packageName, userId);
Hui Wang641e81c2020-10-12 12:14:23 -070011713 } finally {
11714 Binder.restoreCallingIdentity(identity);
11715 }
11716 }
11717
11718 /**
11719 * Return the package name of the currently bound GbaService.
11720 *
11721 * @param subId The sim that the GbaService is associated with.
11722 * @return the package name of the GbaService configuration, null if GBA is not supported.
11723 */
11724 @Override
11725 public String getBoundGbaService(int subId) {
11726 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11727
11728 final long identity = Binder.clearCallingIdentity();
11729 try {
11730 return getGbaManager(subId).getServicePackage();
11731 } finally {
11732 Binder.restoreCallingIdentity(identity);
11733 }
11734 }
11735
11736 /**
11737 * Set the release time for telephony to unbind GbaService.
11738 *
11739 * @param subId The sim that the GbaService is associated with.
11740 * @param interval The release time to unbind GbaService by millisecond.
11741 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11742 */
11743 @Override
11744 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11745 enforceModifyPermission();
11746
11747 final long identity = Binder.clearCallingIdentity();
11748 try {
11749 return getGbaManager(subId).overrideReleaseTime(interval);
11750 } finally {
11751 Binder.restoreCallingIdentity(identity);
11752 }
11753 }
11754
11755 /**
11756 * Return the release time for telephony to unbind GbaService.
11757 *
11758 * @param subId The sim that the GbaService is associated with.
11759 * @return The release time to unbind GbaService by millisecond.
11760 */
11761 @Override
11762 public int getGbaReleaseTime(int subId) {
11763 enforceReadPrivilegedPermission("getGbaReleaseTime");
11764
11765 final long identity = Binder.clearCallingIdentity();
11766 try {
11767 return getGbaManager(subId).getReleaseTime();
11768 } finally {
11769 Binder.restoreCallingIdentity(identity);
11770 }
11771 }
11772
11773 private GbaManager getGbaManager(int subId) {
11774 GbaManager instance = GbaManager.getInstance(subId);
11775 if (instance == null) {
11776 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11777 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11778 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11779 }
11780 return instance;
11781 }
Hui Wang761a6682020-10-31 05:12:53 +000011782
11783 /**
11784 * indicate whether the device and the carrier can support
11785 * RCS VoLTE single registration.
11786 */
11787 @Override
11788 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011789 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11790 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11791 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11792 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011793
11794 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11795 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11796 }
11797
11798 final long identity = Binder.clearCallingIdentity();
11799 try {
11800 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11801 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011802 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11803 if (isCapable != null) {
11804 return isCapable;
11805 }
Hui Wang761a6682020-10-31 05:12:53 +000011806 }
Hui Wang67af90e2021-06-04 16:57:15 -070011807 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11808 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011809 } finally {
11810 Binder.restoreCallingIdentity(identity);
11811 }
11812 }
11813
11814 /**
11815 * Register RCS provisioning callback.
11816 */
11817 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011818 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011819 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011820 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011821 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011822 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11823 permission.READ_PRIVILEGED_PHONE_STATE);
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 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11833 "IMS not available on device.");
11834 }
11835 } else {
11836 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11837 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011838 }
11839
11840 final long identity = Binder.clearCallingIdentity();
11841 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011842 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011843 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011844 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11845 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011846 }
Hui Wang761a6682020-10-31 05:12:53 +000011847 } finally {
11848 Binder.restoreCallingIdentity(identity);
11849 }
11850 }
11851
11852 /**
11853 * Unregister RCS provisioning callback.
11854 */
11855 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011856 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011857 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011858 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011859 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011860 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11861 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011862
11863 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11864 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11865 }
joonhunshin4ac60942023-11-15 15:23:39 +000011866
11867 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11868 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11869 Binder.getCallingUserHandle())) {
11870 if (!isImsAvailableOnDevice()) {
11871 // operation failed silently
11872 Rlog.w(LOG_TAG, "IMS not available on device.");
11873 return;
11874 }
11875 } else {
11876 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11877 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11878 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011879 }
11880
11881 final long identity = Binder.clearCallingIdentity();
11882 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011883 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011884 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011885 } finally {
11886 Binder.restoreCallingIdentity(identity);
11887 }
11888 }
11889
11890 /**
11891 * trigger RCS reconfiguration.
11892 */
11893 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011894 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11895 "triggerRcsReconfiguration",
11896 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011897
11898 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11899 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11900 }
joonhunshin4ac60942023-11-15 15:23:39 +000011901 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11902 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11903 Binder.getCallingUserHandle())) {
11904 if (!isImsAvailableOnDevice()) {
11905 // ProvisioningManager can not handle ServiceSpecificException.
11906 // Throw the IllegalStateException and annotate ProvisioningManager.
11907 throw new IllegalStateException("IMS not available on device.");
11908 }
11909 } else {
11910 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11911 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011912 }
11913
11914 final long identity = Binder.clearCallingIdentity();
11915 try {
11916 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11917 } finally {
11918 Binder.restoreCallingIdentity(identity);
11919 }
11920 }
11921
11922 /**
11923 * Provide the client configuration parameters of the RCS application.
11924 */
11925 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011926 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11927 "setRcsClientConfiguration",
11928 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011929
11930 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11931 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11932 }
joonhunshin4ac60942023-11-15 15:23:39 +000011933 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11934 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11935 Binder.getCallingUserHandle())) {
11936 if (!isImsAvailableOnDevice()) {
11937 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11938 "IMS not available on device.");
11939 }
11940 } else {
11941 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11942 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011943 }
11944
11945 final long identity = Binder.clearCallingIdentity();
11946
11947 try {
11948 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11949 if (configBinder == null) {
11950 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011951 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11952 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011953 } else {
11954 configBinder.setRcsClientConfiguration(rcc);
11955 }
joonhunshin3e154242021-09-17 06:33:39 +000011956
11957 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11958 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011959 } catch (RemoteException e) {
11960 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011961 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11962 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011963 } finally {
11964 Binder.restoreCallingIdentity(identity);
11965 }
11966 }
11967
11968 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011969 * Enables or disables the test mode for RCS VoLTE single registration.
11970 */
11971 @Override
11972 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11973 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11974 "setRcsSingleRegistrationTestModeEnabled");
11975
11976 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11977 }
11978
11979 /**
11980 * Gets the test mode for RCS VoLTE single registration.
11981 */
11982 @Override
11983 public boolean getRcsSingleRegistrationTestModeEnabled() {
11984 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11985 "getRcsSingleRegistrationTestModeEnabled");
11986
11987 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11988 }
11989
11990 /**
Hui Wang761a6682020-10-31 05:12:53 +000011991 * Overrides the config of RCS VoLTE single registration enabled for the device.
11992 */
11993 @Override
11994 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11995 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11996 "setDeviceSingleRegistrationEnabledOverride");
11997 enforceModifyPermission();
11998
11999 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12000 : Boolean.parseBoolean(enabledStr);
12001 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000012002 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000012003 }
12004
12005 /**
Tyler Gunn92479152021-01-20 16:30:10 -080012006 * Sends a device to device communication message. Only usable via shell.
12007 * @param message message to send.
12008 * @param value message value.
12009 */
12010 @Override
12011 public void sendDeviceToDeviceMessage(int message, int value) {
12012 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080012013 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080012014 enforceModifyPermission();
12015
12016 final long identity = Binder.clearCallingIdentity();
12017 try {
12018 TelephonyConnectionService service =
12019 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12020 if (service == null) {
12021 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
12022 return;
12023 }
12024 service.sendTestDeviceToDeviceMessage(message, value);
12025 } finally {
12026 Binder.restoreCallingIdentity(identity);
12027 }
12028 }
12029
Tyler Gunnbabbda02021-02-10 11:05:02 -080012030 /**
12031 * Sets the specified device to device transport active.
12032 * @param transport The transport to set active.
12033 */
12034 @Override
12035 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
12036 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12037 "setActiveDeviceToDeviceTransport");
12038 enforceModifyPermission();
12039
12040 final long identity = Binder.clearCallingIdentity();
12041 try {
12042 TelephonyConnectionService service =
12043 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12044 if (service == null) {
12045 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
12046 return;
12047 }
12048 service.setActiveDeviceToDeviceTransport(transport);
12049 } finally {
12050 Binder.restoreCallingIdentity(identity);
12051 }
12052 }
Tyler Gunn92479152021-01-20 16:30:10 -080012053
Tyler Gunnd4339262021-05-03 14:46:49 -070012054 @Override
12055 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12056 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12057 "setDeviceToDeviceForceEnabled");
12058
12059 final long identity = Binder.clearCallingIdentity();
12060 try {
12061 Arrays.stream(PhoneFactory.getPhones()).forEach(
12062 p -> {
12063 Phone thePhone = p.getImsPhone();
12064 if (thePhone != null && thePhone instanceof ImsPhone) {
12065 ImsPhone imsPhone = (ImsPhone) thePhone;
12066 CallTracker tracker = imsPhone.getCallTracker();
12067 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12068 ImsPhoneCallTracker imsPhoneCallTracker =
12069 (ImsPhoneCallTracker) tracker;
12070 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12071 }
12072 }
12073 }
12074 );
12075 } finally {
12076 Binder.restoreCallingIdentity(identity);
12077 }
12078 }
12079
Tyler Gunn92479152021-01-20 16:30:10 -080012080 /**
Hui Wang761a6682020-10-31 05:12:53 +000012081 * Gets the config of RCS VoLTE single registration enabled for the device.
12082 */
12083 @Override
12084 public boolean getDeviceSingleRegistrationEnabled() {
12085 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12086 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12087 }
12088
12089 /**
12090 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12091 */
12092 @Override
12093 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12094 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12095 "setCarrierSingleRegistrationEnabledOverride");
12096 enforceModifyPermission();
12097
12098 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12099 : Boolean.parseBoolean(enabledStr);
12100 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12101 subId, enabled);
12102 }
12103
12104 /**
12105 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12106 */
12107 @Override
12108 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12109 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12110 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12111 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012112
12113 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012114 * Overrides the ims feature validation result
12115 */
12116 @Override
12117 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12118 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12119 "setImsFeatureValidationOverride");
12120
12121 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12122 : Boolean.parseBoolean(enabledStr);
12123 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12124 subId, enabled);
12125 }
12126
12127 /**
12128 * Gets the ims feature validation override value
12129 */
12130 @Override
12131 public boolean getImsFeatureValidationOverride(int subId) {
12132 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12133 "getImsFeatureValidationOverride");
12134 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12135 }
12136
12137 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012138 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12139 * their mobile plan.
12140 */
12141 @Override
12142 public String getMobileProvisioningUrl() {
12143 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12144 final long identity = Binder.clearCallingIdentity();
12145 try {
12146 return getDefaultPhone().getMobileProvisioningUrl();
12147 } finally {
12148 Binder.restoreCallingIdentity(identity);
12149 }
12150 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012151
James.cf Linbcdf8b32021-01-14 16:44:13 +080012152 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012153 * Get the EAB contact from the EAB database.
12154 */
12155 @Override
12156 public String getContactFromEab(String contact) {
12157 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12158 enforceModifyPermission();
12159 final long identity = Binder.clearCallingIdentity();
12160 try {
12161 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12162 } finally {
12163 Binder.restoreCallingIdentity(identity);
12164 }
12165 }
12166
12167 /**
Calvin Pana1434322021-07-01 19:27:01 +080012168 * Get the EAB capability from the EAB database.
12169 */
12170 @Override
12171 public String getCapabilityFromEab(String contact) {
12172 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12173 enforceModifyPermission();
12174 final long identity = Binder.clearCallingIdentity();
12175 try {
12176 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12177 } finally {
12178 Binder.restoreCallingIdentity(identity);
12179 }
12180 }
12181
12182 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012183 * Remove the EAB contacts from the EAB database.
12184 */
12185 @Override
12186 public int removeContactFromEab(int subId, String contacts) {
12187 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12188 enforceModifyPermission();
12189 final long identity = Binder.clearCallingIdentity();
12190 try {
12191 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12192 } finally {
12193 Binder.restoreCallingIdentity(identity);
12194 }
12195 }
12196
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012197 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012198 public boolean getDeviceUceEnabled() {
12199 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12200 final long identity = Binder.clearCallingIdentity();
12201 try {
12202 return mApp.getDeviceUceEnabled();
12203 } finally {
12204 Binder.restoreCallingIdentity(identity);
12205 }
12206 }
12207
12208 @Override
12209 public void setDeviceUceEnabled(boolean isEnabled) {
12210 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12211 final long identity = Binder.clearCallingIdentity();
12212 try {
12213 mApp.setDeviceUceEnabled(isEnabled);
12214 } finally {
12215 Binder.restoreCallingIdentity(identity);
12216 }
12217 }
12218
Brad Ebinger14d467f2021-02-12 06:18:28 +000012219 /**
12220 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12221 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12222 */
12223 // Used for SHELL command only right now.
12224 @Override
12225 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12226 List<String> featureTags) {
12227 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12228 "addUceRegistrationOverrideShell");
12229 final long identity = Binder.clearCallingIdentity();
12230 try {
12231 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12232 new ArraySet<>(featureTags));
12233 } catch (ImsException e) {
12234 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12235 } finally {
12236 Binder.restoreCallingIdentity(identity);
12237 }
12238 }
12239
12240 /**
12241 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12242 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12243 */
12244 // Used for SHELL command only right now.
12245 @Override
12246 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12247 List<String> featureTags) {
12248 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12249 "removeUceRegistrationOverrideShell");
12250 final long identity = Binder.clearCallingIdentity();
12251 try {
12252 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12253 new ArraySet<>(featureTags));
12254 } catch (ImsException e) {
12255 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12256 } finally {
12257 Binder.restoreCallingIdentity(identity);
12258 }
12259 }
12260
12261 /**
12262 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12263 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12264 */
12265 // Used for SHELL command only right now.
12266 @Override
12267 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12269 "clearUceRegistrationOverrideShell");
12270 final long identity = Binder.clearCallingIdentity();
12271 try {
12272 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12273 } catch (ImsException e) {
12274 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12275 } finally {
12276 Binder.restoreCallingIdentity(identity);
12277 }
12278 }
12279
12280 /**
12281 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12282 */
12283 // Used for SHELL command only right now.
12284 @Override
12285 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12286 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12287 "getLatestRcsContactUceCapabilityShell");
12288 final long identity = Binder.clearCallingIdentity();
12289 try {
12290 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12291 } catch (ImsException e) {
12292 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12293 } finally {
12294 Binder.restoreCallingIdentity(identity);
12295 }
12296 }
12297
12298 /**
12299 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12300 * device does not have an active PUBLISH.
12301 */
12302 // Used for SHELL command only right now.
12303 @Override
12304 public String getLastUcePidfXmlShell(int subId) {
12305 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12306 final long identity = Binder.clearCallingIdentity();
12307 try {
12308 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12309 } catch (ImsException e) {
12310 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12311 } finally {
12312 Binder.restoreCallingIdentity(identity);
12313 }
12314 }
12315
James.cf Line8713a42021-04-29 16:04:26 +080012316 /**
12317 * Remove UCE requests cannot be sent to the network status.
12318 */
12319 // Used for SHELL command only right now.
12320 @Override
12321 public boolean removeUceRequestDisallowedStatus(int subId) {
12322 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12323 final long identity = Binder.clearCallingIdentity();
12324 try {
12325 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12326 } catch (ImsException e) {
12327 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12328 } finally {
12329 Binder.restoreCallingIdentity(identity);
12330 }
12331 }
12332
James.cf Lin18bb9002021-05-25 01:37:38 +080012333 /**
12334 * Remove UCE requests cannot be sent to the network status.
12335 */
12336 // Used for SHELL command only.
12337 @Override
12338 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12339 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12340 final long identity = Binder.clearCallingIdentity();
12341 try {
12342 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12343 } catch (ImsException e) {
12344 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12345 } finally {
12346 Binder.restoreCallingIdentity(identity);
12347 }
12348 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012349
James.cf Lin4b784aa2021-01-31 03:25:15 +080012350 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012351 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12352 String callingPackage) {
12353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12354 mApp, subId, "setSignalStrengthUpdateRequest");
12355
joonhunshin4ac60942023-11-15 15:23:39 +000012356 enforceTelephonyFeatureWithException(callingPackage,
12357 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12358
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012359 final int callingUid = Binder.getCallingUid();
12360 // Verify that tha callingPackage belongs to the calling UID
12361 mApp.getSystemService(AppOpsManager.class)
12362 .checkPackage(callingUid, callingPackage);
12363
Rambo Wang3607f502021-02-01 21:51:40 -080012364 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012365
12366 final long identity = Binder.clearCallingIdentity();
12367 try {
12368 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12369 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12370
12371 if (result instanceof IllegalStateException) {
12372 throw (IllegalStateException) result;
12373 }
12374 } finally {
12375 Binder.restoreCallingIdentity(identity);
12376 }
12377 }
12378
12379 @Override
12380 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12381 String callingPackage) {
12382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12383 mApp, subId, "clearSignalStrengthUpdateRequest");
12384
joonhunshin4ac60942023-11-15 15:23:39 +000012385 enforceTelephonyFeatureWithException(callingPackage,
12386 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12387
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012388 final int callingUid = Binder.getCallingUid();
12389 // Verify that tha callingPackage belongs to the calling UID
12390 mApp.getSystemService(AppOpsManager.class)
12391 .checkPackage(callingUid, callingPackage);
12392
12393 final long identity = Binder.clearCallingIdentity();
12394 try {
12395 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12396 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12397
12398 if (result instanceof IllegalStateException) {
12399 throw (IllegalStateException) result;
12400 }
12401 } finally {
12402 Binder.restoreCallingIdentity(identity);
12403 }
12404 }
12405
Rambo Wang3607f502021-02-01 21:51:40 -080012406 private static void validateSignalStrengthUpdateRequest(Context context,
12407 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012408 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012409 // phone/system process do not have further restriction on request
12410 return;
12411 }
12412
12413 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012414 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012415 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012416 context.enforceCallingOrSelfPermission(
12417 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12418 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012419 }
12420
12421 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012422 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012423 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012424 || info.isEnabled()) {
12425 throw new IllegalArgumentException(
12426 "Only system can set hide fields in SignalThresholdInfo");
12427 }
12428
12429 // Thresholds length for each RAN need in range. This has been validated in
12430 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12431 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12432 final int[] thresholds = info.getThresholds();
12433 Objects.requireNonNull(thresholds);
12434 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12435 || thresholds.length
12436 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12437 throw new IllegalArgumentException(
12438 "thresholds length is out of range: " + thresholds.length);
12439 }
12440 }
12441 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012442
12443 /**
12444 * Gets the current phone capability.
12445 *
12446 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12447 * @return the PhoneCapability which describes the data connection capability of modem.
12448 * It's used to evaluate possible phone config change, for example from single
12449 * SIM device to multi-SIM device.
12450 */
12451 @Override
12452 public PhoneCapability getPhoneCapability() {
12453 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012454
12455 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12456 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12457
SongFerngWang8236caa2021-01-17 21:51:44 +080012458 final long identity = Binder.clearCallingIdentity();
12459 try {
12460 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12461 } finally {
12462 Binder.restoreCallingIdentity(identity);
12463 }
12464 }
Michele Berionne5e411512020-11-13 02:36:59 +000012465
12466 /**
12467 * Prepare TelephonyManager for an unattended reboot. The reboot is
12468 * required to be done shortly after the API is invoked.
12469 */
12470 @Override
12471 @TelephonyManager.PrepareUnattendedRebootResult
12472 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012473 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012474 enforceRebootPermission();
12475
joonhunshin4ac60942023-11-15 15:23:39 +000012476 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12477 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12478
Michele Berionne5e411512020-11-13 02:36:59 +000012479 final long identity = Binder.clearCallingIdentity();
12480 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012481 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012482 } finally {
12483 Binder.restoreCallingIdentity(identity);
12484 }
12485 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012486
12487 /**
12488 * Request to get the current slicing configuration including URSP rules and
12489 * NSSAIs (configured, allowed and rejected).
12490 *
12491 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12492 */
12493 @Override
12494 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012495 TelephonyPermissions
12496 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12497 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012498
joonhunshin4ac60942023-11-15 15:23:39 +000012499 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12500 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12501 "getSlicingConfig");
12502
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012503 final long identity = Binder.clearCallingIdentity();
12504 try {
12505 Phone phone = getDefaultPhone();
12506 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12507 } finally {
12508 Binder.restoreCallingIdentity(identity);
12509 }
12510 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012511
12512 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012513 * Check whether the given premium capability is available for purchase from the carrier.
12514 *
12515 * @param capability The premium capability to check.
12516 * @param subId The subId to check the premium capability for.
12517 *
12518 * @return Whether the given premium capability is available to purchase.
12519 */
12520 @Override
12521 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12522 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12523 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12524 log("Premium capability "
12525 + TelephonyManager.convertPremiumCapabilityToString(capability)
12526 + " is not available for purchase due to missing permissions.");
12527 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12528 + "permission READ_BASIC_PHONE_STATE.");
12529 }
12530
joonhunshin4ac60942023-11-15 15:23:39 +000012531 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12532 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12533
Sarah Chin2ec39f62022-08-31 17:03:26 -070012534 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012535 if (phone == null) {
12536 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12537 return false;
12538 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012539 final long identity = Binder.clearCallingIdentity();
12540 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012541 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012542 .isPremiumCapabilityAvailableForPurchase(capability);
12543 } finally {
12544 Binder.restoreCallingIdentity(identity);
12545 }
12546 }
12547
12548 /**
12549 * Purchase the given premium capability from the carrier.
12550 *
12551 * @param capability The premium capability to purchase.
12552 * @param callback The result of the purchase request.
12553 * @param subId The subId to purchase the premium capability for.
12554 */
12555 @Override
12556 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12557 log("purchasePremiumCapability: capability="
12558 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12559 + getCurrentPackageName());
12560
12561 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12562 mApp, "purchasePremiumCapability")) {
12563 log("purchasePremiumCapability "
12564 + TelephonyManager.convertPremiumCapabilityToString(capability)
12565 + " failed due to missing permissions.");
12566 throw new SecurityException("purchasePremiumCapability requires permission "
12567 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012568 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12569 mApp, "purchasePremiumCapability")) {
12570 log("purchasePremiumCapability "
12571 + TelephonyManager.convertPremiumCapabilityToString(capability)
12572 + " failed due to missing permissions.");
12573 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012574 }
12575
joonhunshin4ac60942023-11-15 15:23:39 +000012576 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12577 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12578
Sarah Chin2ec39f62022-08-31 17:03:26 -070012579 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012580 if (phone == null) {
12581 try {
12582 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12583 callback.accept(result);
12584 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12585 } catch (RemoteException e) {
12586 String logStr = "Purchase premium capability "
12587 + TelephonyManager.convertPremiumCapabilityToString(capability)
12588 + " failed due to RemoteException handling null phone: " + e;
12589 if (DBG) log(logStr);
12590 AnomalyReporter.reportAnomaly(
12591 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12592 }
12593 return;
12594 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012595
12596 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012597 try {
Jack Yube3fa442024-09-16 14:39:45 -070012598 if (mFeatureFlags.hsumPackageManager()) {
12599 callingProcess = mApp.getPackageManager().getApplicationInfoAsUser(
12600 getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName;
12601 } else {
12602 callingProcess = mApp.getPackageManager().getApplicationInfo(
12603 getCurrentPackageName(), 0).processName;
12604 }
Sarah Chin71b3a852022-09-28 15:54:19 -070012605 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012606 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012607 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012608
12609 boolean isVisible = false;
12610 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12611 if (am != null) {
12612 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12613 if (processes != null) {
12614 for (ActivityManager.RunningAppProcessInfo process : processes) {
12615 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012616 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012617 if (process.processName.equals(callingProcess) && process.importance
12618 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12619 isVisible = true;
12620 break;
12621 }
12622 }
12623 }
12624 }
12625
12626 if (!isVisible) {
12627 try {
12628 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12629 callback.accept(result);
12630 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12631 } catch (RemoteException e) {
12632 String logStr = "Purchase premium capability "
12633 + TelephonyManager.convertPremiumCapabilityToString(capability)
12634 + " failed due to RemoteException handling background application: " + e;
12635 if (DBG) log(logStr);
12636 AnomalyReporter.reportAnomaly(
12637 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12638 }
12639 return;
12640 }
12641
Sarah Chin71b3a852022-09-28 15:54:19 -070012642 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012643 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012644 }
12645
12646 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012647 * Register an IMS connection state callback
12648 */
12649 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012650 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12651 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012652 if (feature == ImsFeature.FEATURE_MMTEL) {
12653 // ImsMmTelManager
12654 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12655 TelephonyPermissions
12656 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12657 mApp, subId, "registerImsStateCallback");
12658 } else if (feature == ImsFeature.FEATURE_RCS) {
12659 // ImsRcsManager or SipDelegateManager
12660 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12661 Binder.getCallingUid(), "registerImsStateCallback",
12662 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12663 Manifest.permission.READ_PRECISE_PHONE_STATE,
12664 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12665 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12666 }
12667
12668 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12669 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12670 "IMS not available on device.");
12671 }
12672
12673 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12674 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12675 }
12676
12677 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12678 if (controller == null) {
12679 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12680 "IMS not available on device.");
12681 }
12682
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012683 if (callingPackage == null) {
12684 callingPackage = getCurrentPackageName();
12685 }
12686
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012687 final long token = Binder.clearCallingIdentity();
12688 try {
12689 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012690 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012691 } catch (ImsException e) {
12692 throw new ServiceSpecificException(e.getCode());
12693 } finally {
12694 Binder.restoreCallingIdentity(token);
12695 }
12696 }
12697
12698 /**
12699 * Unregister an IMS connection state callback
12700 */
12701 @Override
12702 public void unregisterImsStateCallback(IImsStateCallback cb) {
12703 final long token = Binder.clearCallingIdentity();
12704 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12705 if (controller == null) {
12706 return;
12707 }
12708 try {
12709 controller.unregisterImsStateCallback(cb);
12710 } finally {
12711 Binder.restoreCallingIdentity(token);
12712 }
12713 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012714
12715 /**
12716 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12717 *
12718 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012719 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012720 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012721 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012722 * If there is current registered network this value will be same as the registered cell
12723 * identity. If the device goes out of service the previous cell identity is cached and
12724 * will be returned. If the cache age of the Cell identity is more than 24 hours
12725 * it will be cleared and null will be returned.
12726 *
12727 */
12728 @Override
12729 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12730 String callingFeatureId) {
12731 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12732 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12733 LocationAccessPolicy.checkLocationPermission(mApp,
12734 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12735 .setCallingPackage(callingPackage)
12736 .setCallingFeatureId(callingFeatureId)
12737 .setCallingPid(Binder.getCallingPid())
12738 .setCallingUid(Binder.getCallingUid())
12739 .setMethod("getLastKnownCellIdentity")
12740 .setLogAsInfo(true)
12741 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12742 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12743 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12744 .build());
12745
12746 boolean hasFinePermission =
12747 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12748 if (!hasFinePermission
12749 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12750 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012751 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012752 }
12753
12754 final long identity = Binder.clearCallingIdentity();
12755 try {
Ling Mac28f0212023-03-24 16:07:15 -070012756 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012757 if (sst == null) return null;
12758 return sst.getLastKnownCellIdentity();
12759 } finally {
12760 Binder.restoreCallingIdentity(identity);
12761 }
12762 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012763
jimsun3b9ccac2021-10-26 15:01:23 +080012764 /**
12765 * Sets the modem service class Name that Telephony will bind to.
12766 *
12767 * @param serviceName The class name of the modem service.
12768 * @return true if the operation is succeed, otherwise false.
12769 */
12770 public boolean setModemService(String serviceName) {
12771 Log.d(LOG_TAG, "setModemService - " + serviceName);
12772 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012774 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12775 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012776 return mPhoneConfigurationManager.setModemService(serviceName);
12777 }
12778
12779 /**
12780 * Return the class name of the currently bounded modem service.
12781 *
12782 * @return the class name of the modem service.
12783 */
12784 public String getModemService() {
12785 String result;
12786 Log.d(LOG_TAG, "getModemService");
12787 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12788 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012789 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012790 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12791 "getModemService");
12792 result = mPhoneConfigurationManager.getModemService();
12793 Log.d(LOG_TAG, "result = " + result);
12794 return result;
12795 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012796
Hakjun Choi3ee81112023-12-19 15:40:58 +000012797 /**
12798 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12799 * including carrier config, entitlement server, and config update.
12800 *
12801 * @param subId subId The subscription ID of the carrier.
12802 *
12803 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12804 * be returned.
12805 *
12806 * @throws SecurityException if the caller doesn't have the required permission.
12807 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012808 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12809 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012810 final long identity = Binder.clearCallingIdentity();
12811 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012812 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012813 } finally {
12814 Binder.restoreCallingIdentity(identity);
12815 }
12816 }
12817
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012818 @Override
12819 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12820 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12821 mApp.enforceCallingOrSelfPermission(
12822 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12823 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12824
12825 final long identity = Binder.clearCallingIdentity();
12826 try {
12827 Phone phone = getPhone(subId);
12828 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012829 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12830 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012831 phone.setVoiceServiceStateOverride(hasService);
12832 } finally {
12833 Binder.restoreCallingIdentity(identity);
12834 }
12835 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012836
12837 /**
12838 * set removable eSIM as default eUICC.
12839 *
12840 * @hide
12841 */
12842 @Override
12843 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12844 enforceModifyPermission();
12845 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12846
12847 final long identity = Binder.clearCallingIdentity();
12848 try {
12849 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12850 } finally {
12851 Binder.restoreCallingIdentity(identity);
12852 }
12853 }
12854
12855 /**
12856 * Returns whether the removable eSIM is default eUICC or not.
12857 *
12858 * @hide
12859 */
12860 @Override
12861 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12862 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12863 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12864
12865 final long identity = Binder.clearCallingIdentity();
12866 try {
12867 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12868 } finally {
12869 Binder.restoreCallingIdentity(identity);
12870 }
12871 }
12872
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012873 /**
12874 * Get the component name of the default app to direct respond-via-message intent for the
12875 * user associated with this subscription, update the cache if there is no respond-via-message
12876 * application currently configured for this user.
12877 * @return component name of the app and class to direct Respond Via Message intent to, or
12878 * {@code null} if the functionality is not supported.
12879 * @hide
12880 */
12881 @Override
12882 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12883 boolean updateIfNeeded) {
12884 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012885
joonhunshin4ac60942023-11-15 15:23:39 +000012886 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12887 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12888 "getDefaultRespondViaMessageApplication");
12889
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012890 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12891
Grant Menkeb0372492024-09-19 18:01:29 -070012892 if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){
12893 UserHandle mainUser = null;
12894 Context userContext = null;
12895 final long identity = Binder.clearCallingIdentity();
12896 try {
12897 mainUser = mUserManager.getMainUser();
12898 userContext = context.createContextAsUser(mainUser, 0);
12899 Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser);
12900 } finally {
12901 Binder.restoreCallingIdentity(identity);
12902 }
12903 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext,
12904 updateIfNeeded, mainUser);
12905 } else {
12906 UserHandle userHandle = null;
12907 final long identity = Binder.clearCallingIdentity();
12908 try {
12909 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12910 } finally {
12911 Binder.restoreCallingIdentity(identity);
12912 }
12913 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12914 updateIfNeeded, userHandle);
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012915 }
Grant Menkeb0372492024-09-19 18:01:29 -070012916
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012917 }
Jack Yuf5badd92022-12-08 00:50:53 -080012918
12919 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012920 * Set whether the device is able to connect with null ciphering or integrity
12921 * algorithms. This is a global setting and will apply to all active subscriptions
12922 * and all new subscriptions after this.
12923 *
12924 * @param enabled when true, null cipher and integrity algorithms are allowed.
12925 * @hide
12926 */
12927 @Override
12928 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12929 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12930 enforceModifyPermission();
12931 checkForNullCipherAndIntegritySupport();
12932
12933 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12934 // for listening to these preference changes and applying them immediately.
12935 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12936 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12937 editor.apply();
12938
12939 for (Phone phone: PhoneFactory.getPhones()) {
12940 phone.handleNullCipherEnabledChange();
12941 }
12942 }
12943
12944
12945 /**
12946 * Get whether the device is able to connect with null ciphering or integrity
12947 * algorithms. Note that this retrieves the phone-global preference and not
12948 * the state of the radio.
12949 *
12950 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12951 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12952 * version for this feature.
12953 * @hide
12954 */
12955 @Override
12956 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12957 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12958 enforceReadPermission();
12959 checkForNullCipherAndIntegritySupport();
12960 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12961 }
12962
12963 private void checkForNullCipherAndIntegritySupport() {
12964 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12965 throw new UnsupportedOperationException(
12966 "Null cipher and integrity operations require HAL 2.1 or above");
12967 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012968 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12969 throw new UnsupportedOperationException(
12970 "Null cipher and integrity operations unsupported by modem");
12971 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012972 }
12973
Gil Cukierman06403e12023-11-29 16:33:03 +000012974 private void checkForIdentifierDisclosureNotificationSupport() {
12975 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12976 throw new UnsupportedOperationException(
12977 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12978 + "above");
12979 }
12980 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12981 throw new UnsupportedOperationException(
12982 "Cellular identifier disclosure transparency operations unsupported by modem");
12983 }
12984 }
12985
Michael Groover826b71d2023-12-21 22:08:06 -060012986 private void checkForNullCipherNotificationSupport() {
12987 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12988 throw new UnsupportedOperationException(
12989 "Null cipher notification operations require HAL 2.2 or above");
12990 }
12991 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12992 throw new UnsupportedOperationException(
12993 "Null cipher notification operations unsupported by modem");
12994 }
12995 }
12996
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012997 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012998 * Get the SIM state for the slot index.
12999 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
13000 *
13001 * @return SIM state as the ordinal of {@link IccCardConstants.State}
13002 */
13003 @Override
13004 @SimState
13005 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070013006 if (!mApp.getResources().getBoolean(
13007 com.android.internal.R.bool.config_force_phone_globals_creation)) {
13008 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13009 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
13010 }
joonhunshin4ac60942023-11-15 15:23:39 +000013011
Jack Yuf5badd92022-12-08 00:50:53 -080013012 IccCardConstants.State simState;
13013 if (slotIndex < 0) {
13014 simState = IccCardConstants.State.UNKNOWN;
13015 } else {
13016 Phone phone = null;
13017 try {
13018 phone = PhoneFactory.getPhone(slotIndex);
13019 } catch (IllegalStateException e) {
13020 // ignore
13021 }
13022 if (phone == null) {
13023 simState = IccCardConstants.State.UNKNOWN;
13024 } else {
13025 IccCard icc = phone.getIccCard();
13026 if (icc == null) {
13027 simState = IccCardConstants.State.UNKNOWN;
13028 } else {
13029 simState = icc.getState();
13030 }
13031 }
13032 }
13033 return simState.ordinal();
13034 }
Hui Wang9b5793a2022-12-05 14:38:06 -060013035
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013036 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
13037 boolean enableLogcat,
13038 long logcatStartTimestampMillis, boolean enableTelecomDump,
13039 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013040 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013041 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
13042 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
13043 ecdDataBuilder
13044 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
13045 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013046 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013047 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013048 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013049 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
13050 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013051 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
13052 Executors.newCachedThreadPool(), db,
13053 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013054 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013055 }
13056
13057 /**
13058 * Request telephony to persist state for debugging emergency call failures.
13059 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013060 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013061 * @param enableLogcat whether to collect logcat output
13062 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
13063 * @param enableTelecomDump whether to collect telecom dumpsys
13064 * @param enableTelephonyDump whether to collect telephony dumpsys
13065 */
13066 @Override
13067 @RequiresPermission(android.Manifest.permission.DUMP)
13068 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
13069 long logcatStartTimestampMillis, boolean enableTelecomDump,
13070 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013071 // Verify that the caller has READ_DROPBOX_DATA permission.
13072 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13073 && Flags.enableReadDropboxPermission()) {
13074 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13075 "persistEmergencyCallDiagnosticData");
13076 } else {
13077 // Otherwise, enforce legacy permission.
13078 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13079 "persistEmergencyCallDiagnosticData");
13080 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013081 final long identity = Binder.clearCallingIdentity();
13082 try {
13083 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13084 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13085
13086 } finally {
13087 Binder.restoreCallingIdentity(identity);
13088 }
13089 }
13090
Hui Wang9b5793a2022-12-05 14:38:06 -060013091 /**
13092 * Get current cell broadcast ranges.
13093 */
13094 @Override
13095 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13096 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13097 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13098 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013099
13100 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13101 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13102
Hui Wang9b5793a2022-12-05 14:38:06 -060013103 final long identity = Binder.clearCallingIdentity();
13104 try {
13105 return getPhone(subId).getCellBroadcastIdRanges();
13106 } finally {
13107 Binder.restoreCallingIdentity(identity);
13108 }
13109 }
13110
13111 /**
13112 * Set reception of cell broadcast messages with the list of the given ranges
13113 *
13114 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13115 */
13116 @Override
13117 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13118 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13119 @Nullable IIntegerConsumer callback) {
13120 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13121 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013122
13123 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13124 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13125
Hui Wang9b5793a2022-12-05 14:38:06 -060013126 final long identity = Binder.clearCallingIdentity();
13127 try {
13128 Phone phone = getPhoneFromSubId(subId);
13129 if (DBG) {
13130 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13131 }
13132 phone.setCellBroadcastIdRanges(ranges, result -> {
13133 if (callback != null) {
13134 try {
13135 callback.accept(result);
13136 } catch (RemoteException e) {
13137 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13138 }
13139 }
13140 });
13141 } finally {
13142 Binder.restoreCallingIdentity(identity);
13143 }
13144 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013145
13146 /**
13147 * Returns whether the device supports the domain selection service.
13148 *
13149 * @return {@code true} if the device supports the domain selection service.
13150 */
13151 @Override
13152 public boolean isDomainSelectionSupported() {
13153 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13154 "isDomainSelectionSupported");
13155
13156 final long identity = Binder.clearCallingIdentity();
13157 try {
13158 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13159 } finally {
13160 Binder.restoreCallingIdentity(identity);
13161 }
13162 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013163
13164 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013165 * Returns whether the AOSP domain selection service is supported.
13166 *
13167 * @return {@code true} if the AOSP domain selection service is supported,
13168 * {@code false} otherwise.
13169 */
13170 @Override
13171 public boolean isAospDomainSelectionService() {
13172 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13173 "isAospDomainSelectionService");
13174
13175 final long identity = Binder.clearCallingIdentity();
13176 try {
13177 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13178 String dssComponentName = mApp.getResources().getString(
13179 R.string.config_domain_selection_service_component_name);
13180 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13181 TelephonyDomainSelectionService.class.getName());
13182 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13183 + ", aosp=" + componentName.flattenToString());
13184 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13185 }
13186 } finally {
13187 Binder.restoreCallingIdentity(identity);
13188 }
13189 return false;
13190 }
13191
13192 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013193 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13194 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13195 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013196 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013197 * @param enableSatellite {@code true} to enable the satellite modem and
13198 * {@code false} to disable.
13199 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013200 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013201 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013202 *
13203 * @throws SecurityException if the caller doesn't have the required permission.
13204 */
13205 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013206 public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013207 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013208 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013209 final long identity = Binder.clearCallingIdentity();
13210 try {
13211 if (enableSatellite) {
youngtaecha3a9c8a62024-11-01 20:46:08 +000013212 String caller = "PIM:requestSatelliteEnabled";
Hyosun322782b2024-10-24 11:37:59 +000013213 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13214 @Override
13215 protected void onReceiveResult(int resultCode, Bundle resultData) {
13216 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13217 + ", resultData=" + resultData);
youngtaecha3a9c8a62024-11-01 20:46:08 +000013218 mSatelliteController.decrementResultReceiverCount(caller);
13219
Hyosun322782b2024-10-24 11:37:59 +000013220 boolean isAllowed = false;
13221 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13222 callback::accept);
13223 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13224 if (resultData != null
13225 && resultData.containsKey(
13226 KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13227 isAllowed = resultData.getBoolean(
13228 KEY_SATELLITE_COMMUNICATION_ALLOWED);
13229 } else {
13230 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13231 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013232 } else {
Hyosun322782b2024-10-24 11:37:59 +000013233 result.accept(resultCode);
13234 return;
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013235 }
Sangyun Yun8bb66452024-11-25 15:46:10 +000013236 List<Integer> disallowedReasons =
13237 mSatelliteAccessController.getSatelliteDisallowedReasons();
13238 if (disallowedReasons.stream().anyMatch(r ->
13239 (r == SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP
13240 || r == SATELLITE_DISALLOWED_REASON_NOT_PROVISIONED
13241 || r == SATELLITE_DISALLOWED_REASON_NOT_SUPPORTED))) {
13242 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13243 return;
13244 }
Hyosun322782b2024-10-24 11:37:59 +000013245 if (isAllowed) {
Thomas Nguyendd8e0832024-11-01 00:18:58 +000013246 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13247 @Override
13248 protected void onReceiveResult(int resultCode, Bundle resultData) {
13249 Log.d(LOG_TAG, "updateSystemSelectionChannels resultCode="
13250 + resultCode);
13251 mSatelliteController.requestSatelliteEnabled(
Duke Lee8852e512024-10-06 12:55:43 +090013252 enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyendd8e0832024-11-01 00:18:58 +000013253 }
13254 };
13255 mSatelliteAccessController.updateSystemSelectionChannels(
13256 resultReceiver);
Hyosun322782b2024-10-24 11:37:59 +000013257 } else {
13258 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13259 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013260 }
Hyosun322782b2024-10-24 11:37:59 +000013261 };
13262 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
13263 resultReceiver, true);
youngtaecha3a9c8a62024-11-01 20:46:08 +000013264 mSatelliteController.incrementResultReceiverCount(caller);
Hyosun322782b2024-10-24 11:37:59 +000013265 } else {
13266 // No need to check if satellite is allowed at current location when disabling
13267 // satellite
13268 mSatelliteController.requestSatelliteEnabled(
13269 enableSatellite, enableDemoMode, isEmergency, callback);
13270 }
13271 } finally {
13272 Binder.restoreCallingIdentity(identity);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013273 }
Sarah Chin503828c2023-02-01 23:54:20 -080013274 }
13275
13276 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013277 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013278 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013279 * @param result The result receiver that returns whether the satellite modem is enabled
13280 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013281 *
13282 * @throws SecurityException if the caller doesn't have the required permission.
13283 */
13284 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013285 public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013286 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013287 final long identity = Binder.clearCallingIdentity();
13288 try {
13289 mSatelliteController.requestIsSatelliteEnabled(result);
13290 } finally {
13291 Binder.restoreCallingIdentity(identity);
13292 }
Sarah Chin503828c2023-02-01 23:54:20 -080013293 }
13294
13295 /**
Sarah Chin43457982023-02-15 17:50:38 -080013296 * Request to get whether the satellite service demo mode is enabled.
13297 *
Sarah Chin43457982023-02-15 17:50:38 -080013298 * @param result The result receiver that returns whether the satellite demo mode is enabled
13299 * if the request is successful or an error code if the request failed.
13300 *
13301 * @throws SecurityException if the caller doesn't have the required permission.
13302 */
13303 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013304 public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) {
Sarah Chinabf081b2023-03-09 23:00:57 -080013305 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013306 final long identity = Binder.clearCallingIdentity();
13307 try {
13308 mSatelliteController.requestIsDemoModeEnabled(result);
13309 } finally {
13310 Binder.restoreCallingIdentity(identity);
13311 }
Sarah Chin43457982023-02-15 17:50:38 -080013312 }
13313
13314 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013315 * Request to get whether the satellite service is enabled with emergency mode.
13316 *
Thomas Nguyena8062672024-02-05 14:18:19 -080013317 * @param result The result receiver that returns whether the satellite emergency mode is
13318 * enabled if the request is successful or an error code if the request failed.
13319 *
13320 * @throws SecurityException if the caller doesn't have the required permission.
13321 */
13322 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013323 public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) {
Thomas Nguyena8062672024-02-05 14:18:19 -080013324 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013325 final long identity = Binder.clearCallingIdentity();
13326 try {
13327 mSatelliteController.requestIsEmergencyModeEnabled(result);
13328 } finally {
13329 Binder.restoreCallingIdentity(identity);
13330 }
Thomas Nguyena8062672024-02-05 14:18:19 -080013331 }
13332
13333 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013334 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013335 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013336 * @param result The result receiver that returns whether the satellite service is supported on
13337 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013338 */
13339 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013340 public void requestIsSatelliteSupported(@NonNull ResultReceiver result) {
Hyosun322782b2024-10-24 11:37:59 +000013341 final long identity = Binder.clearCallingIdentity();
13342 try {
13343 mSatelliteController.requestIsSatelliteSupported(result);
13344 } finally {
13345 Binder.restoreCallingIdentity(identity);
13346 }
Sarah Chin503828c2023-02-01 23:54:20 -080013347 }
13348
13349 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013350 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013351 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013352 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13353 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013354 *
13355 * @throws SecurityException if the caller doesn't have required permission.
13356 */
13357 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013358 public void requestSatelliteCapabilities(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013359 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Hyosun322782b2024-10-24 11:37:59 +000013360 final long identity = Binder.clearCallingIdentity();
13361 try {
13362 mSatelliteController.requestSatelliteCapabilities(result);
13363 } finally {
13364 Binder.restoreCallingIdentity(identity);
13365 }
Sarah Chin503828c2023-02-01 23:54:20 -080013366 }
13367
13368 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013369 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013370 * This can be called by the pointing UI when the user starts pointing to the satellite.
13371 * Modem should continue to report the pointing input as the device or satellite moves.
13372 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013373 * @param resultCallback The callback to get the result of the request.
13374 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013375 *
13376 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013377 */
13378 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013379 public void startSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013380 @NonNull IIntegerConsumer resultCallback,
13381 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13382 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013383 final long identity = Binder.clearCallingIdentity();
13384 try {
13385 mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback);
13386 } finally {
13387 Binder.restoreCallingIdentity(identity);
13388 }
Sarah Chineccfbd12023-01-20 19:00:35 -080013389 }
13390
13391 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013392 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013393 * This can be called by the pointing UI when the user stops pointing to the satellite.
13394 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013395 * @param resultCallback The callback to get the result of the request.
13396 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
joonhunshin83da7cd2024-08-22 08:53:35 +000013397 * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013398 *
13399 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013400 */
13401 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013402 public void stopSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013403 @NonNull IIntegerConsumer resultCallback,
13404 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13405 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013406 final long identity = Binder.clearCallingIdentity();
13407 try {
13408 mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback);
13409 } finally {
13410 Binder.restoreCallingIdentity(identity);
13411 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013412 }
13413
13414 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013415 * Register the subscription with a satellite provider.
13416 * This is needed to register the subscription if the provider allows dynamic registration.
13417 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013418 * @param token The token to be used as a unique identifier for provisioning with satellite
13419 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013420 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013421 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013422 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013423 * @return The signal transport used by the caller to cancel the provision request,
13424 * or {@code null} if the request failed.
13425 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013426 * @throws SecurityException if the caller doesn't have the required permission.
13427 */
13428 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013429 @Nullable public ICancellationSignal provisionSatelliteService(
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013430 @NonNull String token, @NonNull byte[] provisionData,
13431 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013432 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013433 final long identity = Binder.clearCallingIdentity();
13434 try {
13435 return mSatelliteController.provisionSatelliteService(token, provisionData,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013436 callback);
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013437 } finally {
13438 Binder.restoreCallingIdentity(identity);
13439 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013440 }
13441
13442 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013443 * Unregister the device/subscription with the satellite provider.
13444 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013445 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013446 * should report as deprovisioned.
13447 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013448 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013449 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013450 *
13451 * @throws SecurityException if the caller doesn't have the required permission.
13452 */
13453 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013454 public void deprovisionSatelliteService(
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013455 @NonNull String token, @NonNull IIntegerConsumer callback) {
13456 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013457 final long identity = Binder.clearCallingIdentity();
13458 try {
13459 mSatelliteController.deprovisionSatelliteService(token, callback);
13460 } finally {
13461 Binder.restoreCallingIdentity(identity);
13462 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013463 }
13464
13465 /**
Sarah Chin43457982023-02-15 17:50:38 -080013466 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013467 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013468 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013469 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013470 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013471 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013472 * @throws SecurityException if the caller doesn't have the required permission.
13473 */
13474 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013475 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013476 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013477 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013478 final long identity = Binder.clearCallingIdentity();
13479 try {
13480 return mSatelliteController.registerForSatelliteProvisionStateChanged(callback);
13481 } finally {
13482 Binder.restoreCallingIdentity(identity);
13483 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013484 }
13485
13486 /**
Sarah Chin43457982023-02-15 17:50:38 -080013487 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013488 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013489 *
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013490 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013491 * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013492 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013493 * @throws SecurityException if the caller doesn't have the required permission.
13494 */
13495 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013496 public void unregisterForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013497 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013498 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013499 final long identity = Binder.clearCallingIdentity();
13500 try {
13501 mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback);
13502 } finally {
13503 Binder.restoreCallingIdentity(identity);
13504 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013505 }
13506
13507 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013508 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013509 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013510 * @param result The result receiver that returns whether the device is provisioned with a
13511 * satellite provider if the request is successful or an error code if the
13512 * request failed.
13513 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013514 * @throws SecurityException if the caller doesn't have the required permission.
13515 */
13516 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013517 public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013518 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Hyosun322782b2024-10-24 11:37:59 +000013519 final long identity = Binder.clearCallingIdentity();
13520 try {
13521 mSatelliteController.requestIsSatelliteProvisioned(result);
13522 } finally {
13523 Binder.restoreCallingIdentity(identity);
13524 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013525 }
13526
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013527 /**
Sarah Chin43457982023-02-15 17:50:38 -080013528 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013529 *
Sarah Chin43457982023-02-15 17:50:38 -080013530 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013531 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013532 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013533 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013534 * @throws SecurityException if the caller doesn't have the required permission.
13535 */
13536 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013537 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(
Hakjun Choid4a52a22023-12-13 09:48:24 +000013538 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013539 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013540 final long identity = Binder.clearCallingIdentity();
13541 try {
13542 return mSatelliteController.registerForSatelliteModemStateChanged(callback);
13543 } finally {
13544 Binder.restoreCallingIdentity(identity);
13545 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013546 }
13547
13548 /**
Sarah Chin43457982023-02-15 17:50:38 -080013549 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013550 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013551 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013552 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013553 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013554 *
13555 * @throws SecurityException if the caller doesn't have the required permission.
13556 */
13557 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013558 public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013559 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013560 final long identity = Binder.clearCallingIdentity();
13561 try {
13562 mSatelliteController.unregisterForModemStateChanged(callback);
13563 } finally {
13564 Binder.restoreCallingIdentity(identity);
13565 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013566 }
13567
13568 /**
13569 * Register to receive incoming datagrams over satellite.
13570 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013571 * @param callback The callback to handle incoming datagrams over satellite.
13572 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013573 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013574 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013575 * @throws SecurityException if the caller doesn't have the required permission.
13576 */
13577 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013578 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013579 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013580 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013581 final long identity = Binder.clearCallingIdentity();
13582 try {
13583 return mSatelliteController.registerForIncomingDatagram(callback);
13584 } finally {
13585 Binder.restoreCallingIdentity(identity);
13586 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013587 }
13588
13589 /**
13590 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013591 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013592 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013593 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013594 * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013595 *
13596 * @throws SecurityException if the caller doesn't have the required permission.
13597 */
13598 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013599 public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013600 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013601 final long identity = Binder.clearCallingIdentity();
13602 try {
13603 mSatelliteController.unregisterForIncomingDatagram(callback);
13604 } finally {
13605 Binder.restoreCallingIdentity(identity);
13606 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013607 }
13608
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013609 /**
13610 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013611 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013612 * This method requests modem to check if there are any pending datagrams to be received over
13613 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013614 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013615 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013616 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013617 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013618 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013619 */
joonhunshin83da7cd2024-08-22 08:53:35 +000013620 public void pollPendingDatagrams(IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013621 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
Hyosun322782b2024-10-24 11:37:59 +000013622 final long identity = Binder.clearCallingIdentity();
13623 try {
13624 mSatelliteController.pollPendingDatagrams(callback);
13625 } finally {
13626 Binder.restoreCallingIdentity(identity);
13627 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013628 }
13629
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013630 /**
13631 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013632 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013633 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13634 * input to this method. Datagram received here will be passed down to modem without any
13635 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013636 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013637 * @param datagramType datagram type indicating whether the datagram is of type
13638 * SOS_SMS or LOCATION_SHARING.
13639 * @param datagram encoded gateway datagram which is encrypted by the caller.
13640 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013641 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13642 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013643 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013644 *
13645 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013646 */
13647 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013648 public void sendDatagram(@SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013649 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13650 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013651 enforceSatelliteCommunicationPermission("sendDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013652 final long identity = Binder.clearCallingIdentity();
13653 try {
13654 mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI,
13655 callback);
13656 } finally {
13657 Binder.restoreCallingIdentity(identity);
13658 }
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013659 }
13660
Sarah Chindf715ec2023-02-13 13:46:24 -080013661 /**
Duke Lee8852e512024-10-06 12:55:43 +090013662 * Returns integer array of disallowed reasons of satellite.
13663 *
13664 * @return Integer array of disallowed reasons of satellite.
13665 *
13666 * @throws SecurityException if the caller doesn't have the required permission.
13667 */
13668 @NonNull public int[] getSatelliteDisallowedReasons() {
13669 enforceSatelliteCommunicationPermission("getSatelliteDisallowedReasons");
13670 final long identity = Binder.clearCallingIdentity();
13671 try {
13672 return mSatelliteAccessController.getSatelliteDisallowedReasons()
13673 .stream().mapToInt(Integer::intValue).toArray();
13674 } finally {
13675 Binder.restoreCallingIdentity(identity);
13676 }
13677 }
13678
13679 /**
13680 * Registers for disallowed reasons change event from satellite service.
13681 *
13682 * @param callback The callback to handle disallowed reasons changed event.
13683 *
13684 * @throws SecurityException if the caller doesn't have the required permission.
13685 */
13686 @Override
13687 public void registerForSatelliteDisallowedReasonsChanged(
13688 @NonNull ISatelliteDisallowedReasonsCallback callback) {
13689 enforceSatelliteCommunicationPermission("registerForSatelliteDisallowedReasonsChanged");
13690 final long identity = Binder.clearCallingIdentity();
13691 try {
13692 mSatelliteAccessController.registerForSatelliteDisallowedReasonsChanged(callback);
13693 } finally {
13694 Binder.restoreCallingIdentity(identity);
13695 }
13696 }
13697
13698 /**
13699 * Unregisters for disallowed reasons change event from satellite service.
13700 * If callback was not registered before, the request will be ignored.
13701 *
13702 * @param callback The callback to handle disallowed reasons changed event.
13703 * {@link #registerForSatelliteDisallowedReasonsChanged(
13704 * ISatelliteDisallowedReasonsCallback)}.
13705 * @throws SecurityException if the caller doesn't have the required permission.
13706 */
13707 @Override
13708 public void unregisterForSatelliteDisallowedReasonsChanged(
13709 @NonNull ISatelliteDisallowedReasonsCallback callback) {
13710 enforceSatelliteCommunicationPermission("unregisterForSatelliteDisallowedReasonsChanged");
13711 final long identity = Binder.clearCallingIdentity();
13712 try {
13713 mSatelliteAccessController.unregisterForSatelliteDisallowedReasonsChanged(callback);
13714 } finally {
13715 Binder.restoreCallingIdentity(identity);
13716 }
13717 }
13718
13719 /**
Sarah Chindf715ec2023-02-13 13:46:24 -080013720 * Request to get whether satellite communication is allowed for the current location.
13721 *
13722 * @param subId The subId of the subscription to check whether satellite communication is
13723 * allowed for the current location for.
13724 * @param result The result receiver that returns whether satellite communication is allowed
13725 * for the current location if the request is successful or an error code
13726 * if the request failed.
13727 *
13728 * @throws SecurityException if the caller doesn't have the required permission.
13729 */
13730 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013731 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013732 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013733 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
Hyosun322782b2024-10-24 11:37:59 +000013734 final long identity = Binder.clearCallingIdentity();
13735 try {
13736 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result,
13737 false);
13738 } finally {
13739 Binder.restoreCallingIdentity(identity);
13740 }
Sarah Chindf715ec2023-02-13 13:46:24 -080013741 }
13742
13743 /**
youngtaechaedc8a1c2024-10-15 09:07:25 +000013744 * Request to get satellite access configuration for the current location.
13745 *
13746 * @param result The result receiver that returns the satellite access configuration
13747 * for the current location if the request is successful or an error code
13748 * if the request failed.
13749 *
13750 * @throws SecurityException if the caller doesn't have the required permission.
13751 */
13752 @Override
13753 public void requestSatelliteAccessConfigurationForCurrentLocation(
13754 @NonNull ResultReceiver result) {
13755 enforceSatelliteCommunicationPermission(
13756 "requestSatelliteAccessConfigurationForCurrentLocation");
13757 final long identity = Binder.clearCallingIdentity();
13758 try {
13759 mSatelliteAccessController
13760 .requestSatelliteAccessConfigurationForCurrentLocation(result);
13761 } finally {
13762 Binder.restoreCallingIdentity(identity);
13763 }
13764 }
13765
13766 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013767 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013768 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013769 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013770 * be visible if the request is successful or an error code if the request failed.
13771 *
13772 * @throws SecurityException if the caller doesn't have the required permission.
13773 */
13774 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013775 public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013776 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Hyosun322782b2024-10-24 11:37:59 +000013777 final long identity = Binder.clearCallingIdentity();
13778 try {
13779 mSatelliteController.requestTimeForNextSatelliteVisibility(result);
13780 } finally {
13781 Binder.restoreCallingIdentity(identity);
13782 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013783 }
13784
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013785 /**
Adrian8e30ad02024-11-21 17:22:29 +000013786 * Request to get the name to display for Satellite subscription.
13787 *
13788 * @param result The result receiver that returns the display name to use for satellite feature
13789 * in the UI for current satellite subscription if the request is successful,
13790 * or an error code if the request failed.
13791 *
13792 * @throws SecurityException if the caller doesn't have the required permission.
13793 */
13794 @Override
13795 public void requestSatelliteDisplayName(@NonNull ResultReceiver result) {
13796 enforceSatelliteCommunicationPermission("requestSatelliteDisplayName");
13797 final long identity = Binder.clearCallingIdentity();
13798 try {
13799 mSatelliteController.requestSatelliteDisplayName(result);
13800 } finally {
13801 Binder.restoreCallingIdentity(identity);
13802 }
13803 }
13804
13805 /**
Daniel Banta99cc7532024-11-15 02:31:08 +000013806 * Request to get the currently selected satellite subscription id.
13807 *
13808 * @param result The result receiver that returns the currently selected satellite subscription
13809 * id if the request is successful or an error code if the request failed.
13810 *
13811 * @throws SecurityException if the caller doesn't have the required permission.
13812 */
13813 @Override
13814 public void requestSelectedNbIotSatelliteSubscriptionId(@NonNull ResultReceiver result) {
13815 enforceSatelliteCommunicationPermission("requestSelectedNbIotSatelliteSubscriptionId");
13816 final long identity = Binder.clearCallingIdentity();
13817 try {
13818 mSatelliteController.requestSelectedNbIotSatelliteSubscriptionId(result);
13819 } finally {
13820 Binder.restoreCallingIdentity(identity);
13821 }
13822 }
13823
13824 /**
Daniel Banta93320242024-11-21 00:34:41 +000013825 * Registers for selected satellite subscription changed event from the satellite service.
13826 *
13827 * @param callback The callback to handle the satellite subscription changed event.
13828 *
13829 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13830 *
13831 * @throws SecurityException if the caller doesn't have required permission.
13832 */
13833 @Override
13834 @SatelliteManager.SatelliteResult
13835 public int registerForSelectedNbIotSatelliteSubscriptionChanged(
13836 @NonNull ISelectedNbIotSatelliteSubscriptionCallback callback) {
13837 enforceSatelliteCommunicationPermission(
13838 "registerForSelectedNbIotSatelliteSubscriptionChanged");
13839 final long identity = Binder.clearCallingIdentity();
13840 try {
13841 return mSatelliteController.registerForSelectedNbIotSatelliteSubscriptionChanged(
13842 callback);
13843 } finally {
13844 Binder.restoreCallingIdentity(identity);
13845 }
13846 }
13847
13848 /**
13849 * Unregisters for selected satellite subscription changed event from the satellite service.
13850 * If callback was not registered before, the request will be ignored.
13851 *
13852 * @param callback The callback that was passed to {@link
13853 * #registerForSelectedNbIotSatelliteSubscriptionChanged(
13854 * ISelectedNbIotSatelliteSubscriptionCallback)}.
13855 *
13856 * @throws SecurityException if the caller doesn't have required permission.
13857 */
13858 @Override
13859 public void unregisterForSelectedNbIotSatelliteSubscriptionChanged(
13860 @NonNull ISelectedNbIotSatelliteSubscriptionCallback callback) {
13861 enforceSatelliteCommunicationPermission(
13862 "unregisterForSelectedNbIotSatelliteSubscriptionChanged");
13863 final long identity = Binder.clearCallingIdentity();
13864 try {
13865 mSatelliteController.unregisterForSelectedNbIotSatelliteSubscriptionChanged(
13866 callback);
13867 } finally {
13868 Binder.restoreCallingIdentity(identity);
13869 }
13870 }
13871
13872 /**
joonhunshin59104152024-09-11 09:55:35 +000013873 * Inform whether the device is aligned with the satellite in both real and demo mode.
Hakjun Choiae365972023-04-25 11:00:31 +000013874 *
joonhunshin59104152024-09-11 09:55:35 +000013875 * @param isAligned {@code true} Device is aligned with the satellite.
13876 * {@code false} Device fails to align with the satellite.
Hakjun Choiae365972023-04-25 11:00:31 +000013877 *
13878 * @throws SecurityException if the caller doesn't have required permission.
13879 */
13880 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13881
joonhunshin83da7cd2024-08-22 08:53:35 +000013882 public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) {
Hyosun322782b2024-10-24 11:37:59 +000013883 enforceSatelliteCommunicationPermission("setDeviceAlignedWithSatellite");
13884 final long identity = Binder.clearCallingIdentity();
13885 try {
13886 mSatelliteController.setDeviceAlignedWithSatellite(isAligned);
13887 } finally {
13888 Binder.restoreCallingIdentity(identity);
13889 }
Hakjun Choiae365972023-04-25 11:00:31 +000013890 }
13891
13892 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013893 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13894 * by modem.
13895 *
13896 * @param subId The subId of the subscription to request for.
13897 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013898 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013899 * operation.
13900 *
13901 * @throws SecurityException if the caller doesn't have required permission.
13902 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013903 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013904 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13905 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013906 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013907 final long identity = Binder.clearCallingIdentity();
13908 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013909 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013910 } finally {
13911 Binder.restoreCallingIdentity(identity);
13912 }
13913 }
13914
13915 /**
13916 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13917 * by modem.
13918 *
13919 * @param subId The subId of the subscription to request for.
13920 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013921 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013922 * operation.
13923 *
13924 * @throws SecurityException if the caller doesn't have required permission.
13925 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013926 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013927 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13928 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013929 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013930 final long identity = Binder.clearCallingIdentity();
13931 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013932 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013933 } finally {
13934 Binder.restoreCallingIdentity(identity);
13935 }
13936 }
13937
13938 /**
13939 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013940 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013941 *
13942 * @param subId The subId of the subscription to request for.
13943 *
13944 * @return Integer array of reasons for disallowing satellite communication.
13945 *
13946 * @throws SecurityException if the caller doesn't have the required permission.
13947 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013948 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013949 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013950 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013951 final long identity = Binder.clearCallingIdentity();
13952 try {
13953 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013954 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013955 return reasonSet.stream().mapToInt(i->i).toArray();
13956 } finally {
13957 Binder.restoreCallingIdentity(identity);
13958 }
13959 }
13960
13961 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013962 * Request to get the signal strength of the satellite connection.
13963 *
Hakjun Choifa3e6172023-09-22 03:56:34 +000013964 * @param result Result receiver to get the error code of the request and the current signal
13965 * strength of the satellite connection.
13966 *
13967 * @throws SecurityException if the caller doesn't have required permission.
13968 */
13969 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013970 public void requestNtnSignalStrength(@NonNull ResultReceiver result) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013971 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13972 final long identity = Binder.clearCallingIdentity();
13973 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000013974 mSatelliteController.requestNtnSignalStrength(result);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013975 } finally {
13976 Binder.restoreCallingIdentity(identity);
13977 }
13978 }
13979
13980 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013981 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13982 * is not successful, a {@link ServiceSpecificException} that contains
13983 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013984 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013985 * @param callback The callback to handle the NTN signal strength changed event. If the
13986 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13987 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13988 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13989 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013990 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013991 * @throws SecurityException If the caller doesn't have the required permission.
13992 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013993 */
13994 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013995 public void registerForNtnSignalStrengthChanged(
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013996 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013997 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13998 final long identity = Binder.clearCallingIdentity();
13999 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000014000 mSatelliteController.registerForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000014001 } finally {
14002 Binder.restoreCallingIdentity(identity);
14003 }
14004 }
14005
14006 /**
14007 * Unregisters for NTN signal strength changed from satellite modem.
14008 * If callback was not registered before, the request will be ignored.
14009 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000014010 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000014011 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000014012 * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)}
Hakjun Choifa3e6172023-09-22 03:56:34 +000014013 *
14014 * @throws SecurityException if the caller doesn't have the required permission.
14015 */
14016 @Override
14017 public void unregisterForNtnSignalStrengthChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014018 @NonNull INtnSignalStrengthCallback callback) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000014019 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
14020 final long identity = Binder.clearCallingIdentity();
14021 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000014022 mSatelliteController.unregisterForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000014023 } finally {
14024 Binder.restoreCallingIdentity(identity);
14025 }
14026 }
14027
14028 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000014029 * Registers for satellite capabilities change event from the satellite service.
14030 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000014031 * @param callback The callback to handle the satellite capabilities changed event.
14032 *
14033 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14034 *
14035 * @throws SecurityException if the caller doesn't have required permission.
14036 */
14037 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000014038 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014039 @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000014040 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000014041 final long identity = Binder.clearCallingIdentity();
14042 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000014043 return mSatelliteController.registerForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000014044 } finally {
14045 Binder.restoreCallingIdentity(identity);
14046 }
14047 }
14048
14049 /**
14050 * Unregisters for satellite capabilities change event from the satellite service.
14051 * If callback was not registered before, the request will be ignored.
14052 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000014053 * @param callback The callback that was passed to.
joonhunshin83da7cd2024-08-22 08:53:35 +000014054 * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000014055 *
14056 * @throws SecurityException if the caller doesn't have required permission.
14057 */
14058 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000014059 public void unregisterForCapabilitiesChanged(
Hakjun Choi3c9303b2023-12-21 06:37:41 +000014060 @NonNull ISatelliteCapabilitiesCallback callback) {
14061 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000014062 final long identity = Binder.clearCallingIdentity();
14063 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000014064 mSatelliteController.unregisterForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000014065 } finally {
14066 Binder.restoreCallingIdentity(identity);
14067 }
14068 }
14069
14070 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000014071 * Registers for the satellite supported state changed.
14072 *
Hakjun Choif92ac752024-03-18 19:34:29 +000014073 * @param callback The callback to handle the satellite supported state changed event.
14074 *
14075 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14076 *
14077 * @throws SecurityException if the caller doesn't have the required permission.
14078 */
14079 @Override
14080 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014081 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000014082 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000014083 final long identity = Binder.clearCallingIdentity();
14084 try {
14085 return mSatelliteController.registerForSatelliteSupportedStateChanged(callback);
14086 } finally {
14087 Binder.restoreCallingIdentity(identity);
14088 }
Hakjun Choif92ac752024-03-18 19:34:29 +000014089 }
14090
14091 /**
14092 * Unregisters for the satellite supported state changed.
14093 * If callback was not registered before, the request will be ignored.
14094 *
Hakjun Choif92ac752024-03-18 19:34:29 +000014095 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000014096 * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}.
Hakjun Choif92ac752024-03-18 19:34:29 +000014097 *
14098 * @throws SecurityException if the caller doesn't have the required permission.
14099 */
14100 @Override
14101 public void unregisterForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014102 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000014103 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000014104 final long identity = Binder.clearCallingIdentity();
14105 try {
14106 mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback);
14107 } finally {
14108 Binder.restoreCallingIdentity(identity);
14109 }
Hakjun Choif92ac752024-03-18 19:34:29 +000014110 }
14111
14112 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014113 * This API can be used by only CTS to update satellite vendor service package name.
14114 *
14115 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000014116 * @param provisioned Whether satellite should be provisioned or not.
14117 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014118 * @return {@code true} if the satellite vendor service is set successfully,
14119 * {@code false} otherwise.
14120 */
Hakjun Choic3393242024-06-26 18:02:08 +000014121 public boolean setSatelliteServicePackageName(String servicePackageName,
14122 String provisioned) {
14123 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
14124 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014125 TelephonyPermissions.enforceShellOnly(
14126 Binder.getCallingUid(), "setSatelliteServicePackageName");
14127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14128 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14129 "setSatelliteServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000014130 final long identity = Binder.clearCallingIdentity();
14131 try {
14132 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
14133 provisioned);
14134 } finally {
14135 Binder.restoreCallingIdentity(identity);
14136 }
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014137 }
14138
14139 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070014140 * This API can be used by only CTS to update satellite gateway service package name.
14141 *
14142 * @param servicePackageName The package name of the satellite gateway service.
14143 * @return {@code true} if the satellite gateway service is set successfully,
14144 * {@code false} otherwise.
14145 */
14146 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
14147 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
14148 TelephonyPermissions.enforceShellOnly(
14149 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
14150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14151 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14152 "setSatelliteGatewayServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000014153 final long identity = Binder.clearCallingIdentity();
14154 try {
14155 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
14156 } finally {
14157 Binder.restoreCallingIdentity(identity);
14158 }
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070014159 }
14160
14161 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070014162 * This API can be used by only CTS to update satellite pointing UI app package and class names.
14163 *
14164 * @param packageName The package name of the satellite pointing UI app.
14165 * @param className The class name of the satellite pointing UI app.
14166 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
14167 * {@code false} otherwise.
14168 */
14169 public boolean setSatellitePointingUiClassName(
14170 @Nullable String packageName, @Nullable String className) {
14171 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
14172 + ", className=" + className);
14173 TelephonyPermissions.enforceShellOnly(
14174 Binder.getCallingUid(), "setSatellitePointingUiClassName");
14175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14176 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000014177 "setSatellitePointingUiClassName");
14178 final long identity = Binder.clearCallingIdentity();
14179 try {
14180 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
14181 } finally {
14182 Binder.restoreCallingIdentity(identity);
14183 }
Thomas Nguyen87dce732023-04-20 18:27:16 -070014184 }
14185
14186 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070014187 * This API can be used by only CTS to update the timeout duration in milliseconds that
14188 * satellite should stay at listening mode to wait for the next incoming page before disabling
14189 * listening mode.
14190 *
14191 * @param timeoutMillis The timeout duration in millisecond.
14192 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14193 */
14194 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
14195 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
14196 TelephonyPermissions.enforceShellOnly(
14197 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
14198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14199 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14200 "setSatelliteListeningTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014201 final long identity = Binder.clearCallingIdentity();
14202 try {
14203 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
14204 } finally {
14205 Binder.restoreCallingIdentity(identity);
14206 }
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070014207 }
14208
14209 /**
joonhunshinf46f0d62024-09-27 14:06:26 +000014210 * This API can be used by only CTS to control ingoring cellular service state event.
14211 *
14212 * @param enabled Whether to enable boolean config.
14213 * @return {@code true} if the value is set successfully, {@code false} otherwise.
14214 */
14215 public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) {
Hyosun322782b2024-10-24 11:37:59 +000014216 Log.d(LOG_TAG, "setSatelliteIgnoreCellularServiceState - " + enabled);
joonhunshinf46f0d62024-09-27 14:06:26 +000014217 TelephonyPermissions.enforceShellOnly(
Hyosun322782b2024-10-24 11:37:59 +000014218 Binder.getCallingUid(), "setSatelliteIgnoreCellularServiceState");
joonhunshinf46f0d62024-09-27 14:06:26 +000014219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14220 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000014221 "setSatelliteIgnoreCellularServiceState");
14222 final long identity = Binder.clearCallingIdentity();
14223 try {
14224 return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled);
14225 } finally {
14226 Binder.restoreCallingIdentity(identity);
14227 }
joonhunshinf46f0d62024-09-27 14:06:26 +000014228 }
14229
14230 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014231 * This API can be used by only CTS to override the timeout durations used by the
14232 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000014233 *
14234 * @param timeoutMillis The timeout duration in millisecond.
14235 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14236 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014237 public boolean setDatagramControllerTimeoutDuration(
14238 boolean reset, int timeoutType, long timeoutMillis) {
14239 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
14240 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000014241 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014242 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000014243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14244 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014245 "setDatagramControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014246 final long identity = Binder.clearCallingIdentity();
14247 try {
14248 return mSatelliteController.setDatagramControllerTimeoutDuration(
14249 reset, timeoutType, timeoutMillis);
14250 } finally {
14251 Binder.restoreCallingIdentity(identity);
14252 }
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014253 }
14254
14255 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014256 * This API can be used by only CTS to override the boolean configs used by the
14257 * DatagramController module.
14258 *
14259 * @param enable Whether to enable or disable boolean config.
14260 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
14261 */
14262 public boolean setDatagramControllerBooleanConfig(
14263 boolean reset, int booleanType, boolean enable) {
14264 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
14265 + ", reset=" + reset + ", enable=" + enable);
14266 TelephonyPermissions.enforceShellOnly(
14267 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
14268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14269 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14270 "ssetDatagramControllerBooleanConfig");
Hyosun322782b2024-10-24 11:37:59 +000014271 final long identity = Binder.clearCallingIdentity();
14272 try {
14273 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType,
14274 enable);
14275 } finally {
14276 Binder.restoreCallingIdentity(identity);
14277 }
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014278 }
14279
14280
14281 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014282 * This API can be used by only CTS to override the timeout durations used by the
14283 * SatelliteController module.
14284 *
14285 * @param timeoutMillis The timeout duration in millisecond.
14286 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14287 */
14288 public boolean setSatelliteControllerTimeoutDuration(
14289 boolean reset, int timeoutType, long timeoutMillis) {
14290 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
14291 + reset + ", timeoutMillis=" + timeoutMillis);
14292 TelephonyPermissions.enforceShellOnly(
14293 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
14294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14295 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14296 "setSatelliteControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014297 final long identity = Binder.clearCallingIdentity();
14298 try {
14299 return mSatelliteController.setSatelliteControllerTimeoutDuration(
14300 reset, timeoutType, timeoutMillis);
14301 } finally {
14302 Binder.restoreCallingIdentity(identity);
14303 }
Hakjun Choiae365972023-04-25 11:00:31 +000014304 }
14305
14306 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014307 * This API can be used in only testing to override connectivity status in monitoring emergency
14308 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
14309 *
14310 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
14311 * of the following values to enable the override:
14312 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
14313 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
14314 * To disable the override, use -1 for handoverType.
14315 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
14316 * delaySeconds after the emergency call starts.
14317 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
14318 */
14319 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
14320 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
14321 TelephonyPermissions.enforceShellOnly(
14322 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
14323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14324 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14325 "setEmergencyCallToSatelliteHandoverType");
Hyosun322782b2024-10-24 11:37:59 +000014326 final long identity = Binder.clearCallingIdentity();
14327 try {
14328 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
14329 handoverType, delaySeconds);
14330 } finally {
14331 Binder.restoreCallingIdentity(identity);
14332 }
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014333 }
14334
14335 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080014336 * This API can be used in only testing to override oem-enabled satellite provision status.
14337 *
14338 * @param reset {@code true} mean the overriding status should not be used, {@code false}
14339 * otherwise.
14340 * @param isProvisioned The overriding provision status.
14341 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
14342 */
14343 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
14344 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
14345 + ", isProvisioned=" + isProvisioned);
14346 TelephonyPermissions.enforceShellOnly(
14347 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
14348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14349 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14350 "setOemEnabledSatelliteProvisionStatus");
Hyosun322782b2024-10-24 11:37:59 +000014351 final long identity = Binder.clearCallingIdentity();
14352 try {
14353 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
14354 } finally {
14355 Binder.restoreCallingIdentity(identity);
14356 }
Thomas Nguyen3d602742024-01-19 11:29:35 -080014357 }
14358
14359 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014360 * This API should be used by only CTS tests to forcefully set telephony country codes.
14361 *
14362 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
14363 */
14364 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
14365 Map cachedNetworkCountryCodes, String locationCountryCode,
14366 long locationCountryCodeTimestampNanos) {
14367 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
14368 + String.join(", ", currentNetworkCountryCodes)
14369 + ", locationCountryCode=" + locationCountryCode
14370 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
14371 + ", reset=" + reset + ", cachedNetworkCountryCodes="
14372 + String.join(", ", cachedNetworkCountryCodes.keySet()));
Hyosun322782b2024-10-24 11:37:59 +000014373 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCountryCodes");
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Hyosun322782b2024-10-24 11:37:59 +000014375 SubscriptionManager.INVALID_SUBSCRIPTION_ID, "setCountryCodes");
14376 final long identity = Binder.clearCallingIdentity();
14377 try {
14378 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(),
14379 mFeatureFlags).setCountryCodes(reset, currentNetworkCountryCodes,
14380 cachedNetworkCountryCodes, locationCountryCode,
14381 locationCountryCodeTimestampNanos);
14382 } finally {
14383 Binder.restoreCallingIdentity(identity);
14384 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014385 }
14386
14387 /**
14388 * This API should be used by only CTS tests to override the overlay configs of satellite
14389 * access controller.
14390 *
14391 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
14392 * otherwise.
14393 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
14394 */
14395 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
14396 String s2CellFile, long locationFreshDurationNanos,
Hakjun Choi364b6ff2024-11-20 07:38:44 +000014397 List<String> satelliteCountryCodes, String satelliteAccessConfigurationFile) {
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014398 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
14399 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
14400 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
14401 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
Hakjun Choi364b6ff2024-11-20 07:38:44 +000014402 ? String.join(", ", satelliteCountryCodes) : null)
14403 + ", satelliteAccessConfigurationFile=" + satelliteAccessConfigurationFile);
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014404 TelephonyPermissions.enforceShellOnly(
14405 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
14406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14407 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14408 "setSatelliteAccessControlOverlayConfigs");
Hyosun322782b2024-10-24 11:37:59 +000014409 final long identity = Binder.clearCallingIdentity();
14410 try {
14411 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset,
Hakjun Choi364b6ff2024-11-20 07:38:44 +000014412 isAllowed, s2CellFile, locationFreshDurationNanos, satelliteCountryCodes,
14413 satelliteAccessConfigurationFile);
Hyosun322782b2024-10-24 11:37:59 +000014414 } finally {
14415 Binder.restoreCallingIdentity(identity);
14416 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014417 }
14418
14419 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000014420 * This API can be used by only CTS to override the cached value for the device overlay config
14421 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
14422 * outgoing satellite datagrams should be sent to modem in demo mode.
14423 *
14424 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
14425 * satellite modem or not.
14426 *
14427 * @return {@code true} if the operation is successful, {@code false} otherwise.
14428 */
14429 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
14430 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14431 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
14432 + "disabled");
14433 return false;
14434 }
14435 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
14436 TelephonyPermissions.enforceShellOnly(
14437 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
14438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14439 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14440 "setShouldSendDatagramToModemInDemoMode");
Hyosun322782b2024-10-24 11:37:59 +000014441 final long identity = Binder.clearCallingIdentity();
14442 try {
14443 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
14444 shouldSendToModemInDemoMode);
14445 } finally {
14446 Binder.restoreCallingIdentity(identity);
14447 }
Hakjun Choibc6ce992023-11-07 16:04:33 +000014448 }
14449
14450 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000014451 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
14452 *
14453 * @param state a state indicates whether satellite access allowed state should be cached and
14454 * the allowed state.
14455 * @return {@code true} if the setting is successful, {@code false} otherwise.
14456 */
14457 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
14458 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14459 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14460 + "oemEnabledSatelliteFlag is disabled");
14461 return false;
14462 }
14463
14464 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14465 + "state=" + state);
14466 TelephonyPermissions.enforceShellOnly(
14467 Binder.getCallingUid(),
14468 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14470 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14471 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
Hyosun322782b2024-10-24 11:37:59 +000014472 final long identity = Binder.clearCallingIdentity();
14473 try {
14474 return mSatelliteAccessController
14475 .setIsSatelliteCommunicationAllowedForCurrentLocationCache(state);
14476 } finally {
14477 Binder.restoreCallingIdentity(identity);
14478 }
Hakjun Choi4a832d12024-05-28 22:23:55 +000014479 }
14480
14481 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014482 * Sets the service defined in ComponentName to be bound.
14483 *
14484 * This should only be used for testing.
14485 * @return {@code true} if the DomainSelectionService to bind to was set,
14486 * {@code false} otherwise.
14487 */
14488 @Override
14489 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14490 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14491
14492 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14493 "setDomainSelectionServiceOverride");
14494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14495 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14496
14497 final long identity = Binder.clearCallingIdentity();
14498 try {
14499 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14500 return DomainSelectionResolver.getInstance()
14501 .setDomainSelectionServiceOverride(componentName);
14502 }
14503 } finally {
14504 Binder.restoreCallingIdentity(identity);
14505 }
14506 return false;
14507 }
14508
14509 /**
14510 * Clears the DomainSelectionService override.
14511 *
14512 * This should only be used for testing.
14513 * @return {@code true} if the DomainSelectionService override was cleared,
14514 * {@code false} otherwise.
14515 */
14516 @Override
14517 public boolean clearDomainSelectionServiceOverride() {
14518 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14519
14520 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14521 "clearDomainSelectionServiceOverride");
14522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14523 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14524
14525 final long identity = Binder.clearCallingIdentity();
14526 try {
14527 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14528 return DomainSelectionResolver.getInstance()
14529 .clearDomainSelectionServiceOverride();
14530 }
14531 } finally {
14532 Binder.restoreCallingIdentity(identity);
14533 }
14534 return false;
14535 }
14536
14537 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014538 * Enable or disable notifications sent for cellular identifier disclosure events.
14539 *
14540 * Disclosure events are defined as instances where a device has sent a cellular identifier
14541 * on the Non-access stratum (NAS) before a security context is established. As a result the
14542 * identifier is sent in the clear, which has privacy implications for the user.
14543 *
14544 * @param enable if notifications about disclosure events should be enabled
14545 * @throws SecurityException if the caller does not have the required privileges
14546 * @throws UnsupportedOperationException if the modem does not support this feature.
14547 */
14548 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014549 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014550 enforceModifyPermission();
14551 checkForIdentifierDisclosureNotificationSupport();
14552
14553 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14554 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14555 editor.apply();
14556
14557 // Each phone instance is responsible for updating its respective modem immediately
14558 // after we've made a preference change.
14559 for (Phone phone : PhoneFactory.getPhones()) {
14560 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14561 }
14562 }
14563
14564 /**
14565 * Get whether or not cellular identifier disclosure notifications are enabled.
14566 *
14567 * @throws SecurityException if the caller does not have the required privileges
14568 * @throws UnsupportedOperationException if the modem does not support this feature.
14569 */
14570 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014571 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014572 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14573 checkForIdentifierDisclosureNotificationSupport();
14574 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14575 }
14576
14577 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014578 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14579 * are in use by the cellular modem.
14580 *
14581 * @throws IllegalStateException if the Telephony process is not currently available
14582 * @throws SecurityException if the caller does not have the required privileges
14583 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14584 * and integrity algorithms in use
14585 * @hide
14586 */
14587 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014588 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014589 enforceModifyPermission();
14590 checkForNullCipherNotificationSupport();
14591
14592 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14593 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14594 editor.apply();
14595
14596 // Each phone instance is responsible for updating its respective modem immediately
14597 // after a preference change.
14598 for (Phone phone : PhoneFactory.getPhones()) {
14599 phone.handleNullCipherNotificationPreferenceChanged();
14600 }
14601 }
14602
14603 /**
14604 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14605 * cellular modem.
14606 *
14607 * @throws IllegalStateException if the Telephony process is not currently available
14608 * @throws SecurityException if the caller does not have the required privileges
14609 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14610 * and integrity algorithms in use
14611 * @hide
14612 */
14613 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14614 public boolean isNullCipherNotificationsEnabled() {
14615 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14616 checkForNullCipherNotificationSupport();
14617 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14618 }
14619
14620 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014621 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14622 *
14623 * <p>This method behaves in one of the following ways:
14624 * <ul>
14625 * <li>return true : if the calling package has the appop permission {@link
14626 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14627 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14628 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14629 * Owner device identifier access check, or the calling package has carrier privileges</>
14630 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14631 * </ul>
14632 */
14633 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14634 String callingPackage, @Nullable String callingFeatureId, String message) {
14635 for (Phone phone : PhoneFactory.getPhones()) {
14636 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14637 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14638 return true;
14639 }
14640 }
14641 return false;
14642 }
arunvoddud7401012022-12-15 16:08:12 +000014643
14644 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014645 * @return The subscription manager service instance.
14646 */
14647 public SubscriptionManagerService getSubscriptionManagerService() {
14648 return SubscriptionManagerService.getInstance();
14649 }
14650
14651 /**
arunvoddud7401012022-12-15 16:08:12 +000014652 * Class binds the consumer[callback] and carrierId.
14653 */
14654 private static class CallerCallbackInfo {
14655 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014656 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014657
Steve Statia28b7cb32024-03-11 23:58:50 +000014658 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014659 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014660 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014661 }
14662
14663 public Consumer<Integer> getConsumer() {
14664 return mConsumer;
14665 }
14666
Steve Statia28b7cb32024-03-11 23:58:50 +000014667 public Set<Integer> getCarrierIds() {
14668 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014669 }
14670 }
joonhunshin4ac60942023-11-15 15:23:39 +000014671
14672 /*
14673 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14674 * But the context that is passed in is unused if the phone app is already alive.
14675 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14676 */
14677 @VisibleForTesting
14678 public void setPackageManager(PackageManager packageManager) {
14679 mPackageManager = packageManager;
14680 }
14681
14682 /*
Nate Myren453c3472024-03-13 11:28:11 -070014683 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14684 * But the context that is passed in is unused if the phone app is already alive.
14685 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14686 */
14687 @VisibleForTesting
14688 public void setAppOpsManager(AppOpsManager appOps) {
14689 mAppOps = appOps;
14690 }
14691
14692 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014693 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14694 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14695 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14696 */
14697 @VisibleForTesting
14698 public void setFeatureFlags(FeatureFlags featureFlags) {
14699 mFeatureFlags = featureFlags;
14700 }
14701
14702 /**
14703 * Make sure the device has required telephony feature
14704 *
14705 * @throws UnsupportedOperationException if the device does not have required telephony feature
14706 */
14707 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14708 @NonNull String telephonyFeature, @NonNull String methodName) {
14709 if (callingPackage == null || mPackageManager == null) {
14710 return;
14711 }
14712
14713 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14714 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014715 Binder.getCallingUserHandle())
14716 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14717 // Skip to check associated telephony feature,
14718 // if compatibility change is not enabled for the current process or
14719 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014720 return;
14721 }
14722
14723 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14724 throw new UnsupportedOperationException(
14725 methodName + " is unsupported without " + telephonyFeature);
14726 }
14727 }
youngtaecha5d483d52024-04-29 17:05:45 +000014728
14729 /**
14730 * Registers for the satellite communication allowed state changed.
14731 *
14732 * @param subId The subId of the subscription to register for the satellite communication
14733 * allowed state changed.
14734 * @param callback The callback to handle the satellite communication allowed
14735 * state changed event.
14736 *
14737 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14738 *
14739 * @throws SecurityException if the caller doesn't have the required permission.
14740 */
14741 @Override
14742 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14743 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14744 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014745 final long identity = Binder.clearCallingIdentity();
14746 try {
14747 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14748 subId, callback);
14749 } finally {
14750 Binder.restoreCallingIdentity(identity);
14751 }
youngtaecha5d483d52024-04-29 17:05:45 +000014752 }
14753
14754 /**
14755 * Unregisters for the satellite communication allowed state changed.
14756 * If callback was not registered before, the request will be ignored.
14757 *
14758 * @param subId The subId of the subscription to unregister for the satellite communication
14759 * allowed state changed.
14760 * @param callback The callback that was passed to
14761 * {@link #registerForCommunicationAllowedStateChanged(int,
14762 * ISatelliteCommunicationAllowedStateCallback)}. *
14763 * @throws SecurityException if the caller doesn't have the required permission.
14764 */
14765 @Override
14766 public void unregisterForCommunicationAllowedStateChanged(
14767 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14768 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014769 final long identity = Binder.clearCallingIdentity();
14770 try {
14771 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId,
14772 callback);
14773 } finally {
14774 Binder.restoreCallingIdentity(identity);
14775 }
youngtaecha5d483d52024-04-29 17:05:45 +000014776 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014777
14778 /**
14779 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14780 *
14781 * @param subId The subId of the subscription to the satellite session stats for.
14782 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14783 * if the request is successful or an error code if the request failed.
14784 *
14785 * @throws SecurityException if the caller doesn't have required permission.
14786 */
14787 @Override
14788 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14789 enforceModifyPermission();
14790 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014791 final long identity = Binder.clearCallingIdentity();
14792 try {
14793 mSatelliteController.requestSatelliteSessionStats(subId, result);
14794 } finally {
14795 Binder.restoreCallingIdentity(identity);
14796 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014797 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014798
14799 /**
14800 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14801 *
14802 * @param result The result receiver, which returns the list of prioritized satellite tokens
14803 * to be used for provision if the request is successful or an error code if the request failed.
14804 *
14805 * @throws SecurityException if the caller doesn't have the required permission.
14806 */
14807 @Override
Hyosun6dbe8542024-08-15 02:52:48 +000014808 public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) {
14809 enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014810 final long identity = Binder.clearCallingIdentity();
14811 try {
14812 mSatelliteController.requestSatelliteSubscriberProvisionStatus(result);
14813 } finally {
14814 Binder.restoreCallingIdentity(identity);
14815 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014816 }
14817
14818 /**
14819 * Deliver the list of provisioned satellite subscriber ids.
14820 *
14821 * @param list List of provisioned satellite subscriber ids.
14822 * @param result The result receiver that returns whether deliver success or fail.
14823 *
14824 * @throws SecurityException if the caller doesn't have the required permission.
14825 */
14826 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014827 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014828 @NonNull ResultReceiver result) {
14829 enforceSatelliteCommunicationPermission("provisionSatellite");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014830 final long identity = Binder.clearCallingIdentity();
14831 try {
14832 mSatelliteController.provisionSatellite(list, result);
14833 } finally {
14834 Binder.restoreCallingIdentity(identity);
14835 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014836 }
Hyosund6aaf062024-08-23 23:02:10 +000014837
14838 /**
Hyosun Kim578cdcd2024-09-24 13:29:19 +000014839 * Deliver the list of deprovisioned satellite subscriber ids.
14840 *
14841 * @param list List of deprovisioned satellite subscriber ids.
14842 * @param result The result receiver that returns whether deliver success or fail.
14843 *
14844 * @throws SecurityException if the caller doesn't have the required permission.
14845 */
14846 @Override
14847 public void deprovisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
14848 @NonNull ResultReceiver result) {
14849 enforceSatelliteCommunicationPermission("deprovisionSatellite");
14850 final long identity = Binder.clearCallingIdentity();
14851 try {
14852 mSatelliteController.deprovisionSatellite(list, result);
14853 } finally {
14854 Binder.restoreCallingIdentity(identity);
14855 }
14856 }
14857
Aishwarya Mallampatia646bc12024-11-08 23:33:24 +000014858
14859 /**
14860 * Inform whether application supports NTN SMS in satellite mode.
14861 *
14862 * This method is used by default messaging application to inform framework whether it supports
14863 * NTN SMS or not.
14864 *
14865 * @param ntnSmsSupported {@code true} If application supports NTN SMS, else {@code false}.
14866 *
14867 * @throws SecurityException if the caller doesn't have required permission.
14868 */
14869 @Override
14870 public void setNtnSmsSupported(boolean ntnSmsSupported) {
14871 enforceSatelliteCommunicationPermission("setNtnSmsSupported");
14872 enforceSendSmsPermission();
Aishwarya Mallampatidcd19f32024-11-22 17:26:54 +000014873
14874 final long identity = Binder.clearCallingIdentity();
14875 try {
14876 mSatelliteController.setNtnSmsSupportedByMessagesApp(ntnSmsSupported);
14877 } finally {
14878 Binder.restoreCallingIdentity(identity);
14879 }
Aishwarya Mallampatia646bc12024-11-08 23:33:24 +000014880 }
14881
Hyosun Kim578cdcd2024-09-24 13:29:19 +000014882 /**
Hyosund6aaf062024-08-23 23:02:10 +000014883 * This API can be used by only CTS to override the cached value for the device overlay config
14884 * value :
14885 * config_satellite_gateway_service_package and
14886 * config_satellite_carrier_roaming_esos_provisioned_class.
14887 * These values are set before sending an intent to broadcast there are any change to list of
14888 * subscriber informations.
14889 *
14890 * @param name the name is one of the following that constitute an intent.
14891 * Component package name, or component class name.
14892 * @return {@code true} if the setting is successful, {@code false} otherwise.
14893 */
14894 @Override
14895 public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) {
14896 if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
14897 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:"
14898 + " carrierRoamingNbIotNtn is disabled");
14899 return false;
14900 }
14901 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent");
14902 TelephonyPermissions.enforceShellOnly(
14903 Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent");
14904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14905 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14906 "setSatelliteSubscriberIdListChangedIntentComponent");
14907 final long identity = Binder.clearCallingIdentity();
14908 try {
14909 return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name);
14910 } finally {
14911 Binder.restoreCallingIdentity(identity);
14912 }
14913 }
Jack Yu26735292024-09-25 14:33:49 -070014914
14915 /**
14916 * This API can be used by only CTS to override the Euicc UI component.
14917 *
14918 * @param componentName ui component to be launched for testing. {@code null} to reset.
14919 *
14920 * @hide
14921 */
14922 @Override
14923 public void setTestEuiccUiComponent(@Nullable ComponentName componentName) {
14924 enforceModifyPermission();
14925 log("setTestEuiccUiComponent: " + componentName);
14926 mTestEuiccUiComponent = componentName;
14927 }
14928
14929 /**
14930 * This API can be used by only CTS to retrieve the Euicc UI component.
14931 *
14932 * @return Euicc UI component. {@code null} if not available.
14933 * @hide
14934 */
14935 @Override
14936 @Nullable
14937 public ComponentName getTestEuiccUiComponent() {
14938 enforceReadPrivilegedPermission("getTestEuiccUiComponent");
14939 return mTestEuiccUiComponent;
14940 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014941
14942 /**
14943 * This API can be used only for test purpose to override the carrier roaming Ntn eligibility
14944 *
14945 * @param state to update Ntn Eligibility.
14946 * @param resetRequired to reset the overridden flag in satellite controller.
14947 * @return {@code true} if the shell command is successful, {@code false} otherwise.
14948 */
14949 public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state,
14950 boolean resetRequired) {
Hyosun322782b2024-10-24 11:37:59 +000014951 final long identity = Binder.clearCallingIdentity();
14952 try {
14953 return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state,
14954 resetRequired);
14955 } finally {
14956 Binder.restoreCallingIdentity(identity);
14957 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014958 }
jinjeongc29c54e2024-11-15 08:11:18 +000014959
14960 /**
14961 * Returns carrier id maps to the passing {@link CarrierIdentifier}.
14962 *
14963 * @param carrierIdentifier {@link CarrierIdentifier}.
14964 *
14965 * @return carrier id from passing {@link CarrierIdentifier} or UNKNOWN_CARRIER_ID
14966 * if the carrier cannot be identified
14967 */
14968 public int getCarrierIdFromIdentifier(@NonNull CarrierIdentifier carrierIdentifier) {
14969 enforceReadPrivilegedPermission("getCarrierIdFromIdentifier");
14970 enforceTelephonyFeatureWithException(getCurrentPackageName(),
14971 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromIdentifier");
14972
14973 final long identity = Binder.clearCallingIdentity();
14974 try {
14975 return CarrierResolver.getCarrierIdFromIdentifier(mApp, carrierIdentifier);
14976 } finally {
14977 Binder.restoreCallingIdentity(identity);
14978 }
14979 }
Jack Yufa8ed012023-02-11 15:42:28 -080014980}