blob: bafcc6f76b58551bafd766794ded46149d4822d4 [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:
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -0800960 if (mFeatureFlags.cleanupCdma()) break;
Jake Hambye994d462014-02-03 13:10:13 -0800961 request = (MainThreadRequest) msg.obj;
962 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800963 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800964 break;
965
966 case EVENT_NV_WRITE_CDMA_PRL_DONE:
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -0800967 if (mFeatureFlags.cleanupCdma()) break;
Jake Hambye994d462014-02-03 13:10:13 -0800968 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
969 break;
970
chen xu6dac5ab2018-10-26 17:39:23 -0700971 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800972 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700973 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800974 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800975 break;
976
chen xu6dac5ab2018-10-26 17:39:23 -0700977 case EVENT_RESET_MODEM_CONFIG_DONE:
978 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800979 break;
980
Sooraj Sasindran37444802020-08-11 10:40:43 -0700981 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
982 request = (MainThreadRequest) msg.obj;
983 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
984 request);
985 Phone phone = getPhoneFromRequest(request);
986 if (phone != null) {
987 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
988 } else {
989 loge("isNRDualConnectivityEnabled: No phone object");
990 request.result = false;
991 notifyRequester(request);
992 }
993 break;
994 }
995
996 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 if (ar.exception == null && ar.result != null) {
1000 request.result = ar.result;
1001 } else {
1002 // request.result must be set to something non-null
1003 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001004 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001005 request.result = ar.result;
1006 } else {
1007 request.result = false;
1008 }
1009 if (ar.result == null) {
1010 loge("isNRDualConnectivityEnabled: Empty response");
1011 } else if (ar.exception instanceof CommandException) {
1012 loge("isNRDualConnectivityEnabled: CommandException: "
1013 + ar.exception);
1014 } else {
1015 loge("isNRDualConnectivityEnabled: Unknown exception");
1016 }
1017 }
1018 notifyRequester(request);
1019 break;
1020
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001021 case CMD_IS_VONR_ENABLED: {
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1024 request);
1025 Phone phone = getPhoneFromRequest(request);
1026 if (phone != null) {
1027 phone.isVoNrEnabled(onCompleted, request.workSource);
1028 } else {
1029 loge("isVoNrEnabled: No phone object");
1030 request.result = false;
1031 notifyRequester(request);
1032 }
1033 break;
1034 }
1035
1036 case EVENT_IS_VONR_ENABLED_DONE:
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
1039 if (ar.exception == null && ar.result != null) {
1040 request.result = ar.result;
1041 } else {
1042 // request.result must be set to something non-null
1043 // for the calling thread to unblock
1044 if (ar.result != null) {
1045 request.result = ar.result;
1046 } else {
1047 request.result = false;
1048 }
1049 if (ar.result == null) {
1050 loge("isVoNrEnabled: Empty response");
1051 } else if (ar.exception instanceof CommandException) {
1052 loge("isVoNrEnabled: CommandException: "
1053 + ar.exception);
1054 } else {
1055 loge("isVoNrEnabled: Unknown exception");
1056 }
1057 }
1058 notifyRequester(request);
1059 break;
1060
Sooraj Sasindran37444802020-08-11 10:40:43 -07001061 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1062 request = (MainThreadRequest) msg.obj;
1063 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1064 Phone phone = getPhoneFromRequest(request);
1065 if (phone != null) {
1066 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1067 request.workSource);
1068 } else {
1069 loge("enableNrDualConnectivity: No phone object");
1070 request.result =
1071 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1072 notifyRequester(request);
1073 }
1074 break;
1075 }
1076
1077 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1078 ar = (AsyncResult) msg.obj;
1079 request = (MainThreadRequest) ar.userObj;
1080 if (ar.exception == null) {
1081 request.result =
1082 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1083 } else {
1084 request.result =
1085 TelephonyManager
1086 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1087 if (ar.exception instanceof CommandException) {
1088 CommandException.Error error =
1089 ((CommandException) (ar.exception)).getCommandError();
1090 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1091 request.result =
1092 TelephonyManager
1093 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001094 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1095 request.result =
1096 TelephonyManager
1097 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001098 }
1099 loge("enableNrDualConnectivity" + ": CommandException: "
1100 + ar.exception);
1101 } else {
1102 loge("enableNrDualConnectivity" + ": Unknown exception");
1103 }
1104 }
1105 notifyRequester(request);
1106 break;
1107 }
1108
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001109 case CMD_ENABLE_VONR: {
1110 request = (MainThreadRequest) msg.obj;
1111 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1112 Phone phone = getPhoneFromRequest(request);
1113 if (phone != null) {
1114 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1115 request.workSource);
1116 } else {
1117 loge("setVoNrEnabled: No phone object");
1118 request.result =
1119 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1120 notifyRequester(request);
1121 }
1122 break;
1123 }
1124
1125 case EVENT_ENABLE_VONR_DONE: {
1126 ar = (AsyncResult) msg.obj;
1127 request = (MainThreadRequest) ar.userObj;
1128 if (ar.exception == null) {
1129 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1130 } else {
1131 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1132 if (ar.exception instanceof CommandException) {
1133 CommandException.Error error =
1134 ((CommandException) (ar.exception)).getCommandError();
1135 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1136 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1137 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1138 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1139 } else {
1140 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1141 }
1142 loge("setVoNrEnabled" + ": CommandException: "
1143 + ar.exception);
1144 } else {
1145 loge("setVoNrEnabled" + ": Unknown exception");
1146 }
1147 }
1148 notifyRequester(request);
1149 break;
1150 }
1151
SongFerngWang3ef3e072020-12-21 16:41:52 +08001152 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001153 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001154 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1155 request);
1156 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001157 break;
1158
SongFerngWang3ef3e072020-12-21 16:41:52 +08001159 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001160 ar = (AsyncResult) msg.obj;
1161 request = (MainThreadRequest) ar.userObj;
1162 if (ar.exception == null && ar.result != null) {
1163 request.result = ar.result; // Integer
1164 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301165 // request.result must be set to something non-null
1166 // for the calling thread to unblock
1167 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001168 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001169 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001170 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001171 loge("getAllowedNetworkTypesBitmask: CommandException: "
1172 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001173 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001174 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001175 }
1176 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001177 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001178 break;
1179
SongFerngWang3ef3e072020-12-21 16:41:52 +08001180 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001181 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001182 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1183 request);
1184 Pair<Integer, Long> reasonWithNetworkTypes =
1185 (Pair<Integer, Long>) request.argument;
1186 getPhoneFromRequest(request).setAllowedNetworkTypes(
1187 reasonWithNetworkTypes.first,
1188 reasonWithNetworkTypes.second,
1189 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001190 break;
1191
SongFerngWang3ef3e072020-12-21 16:41:52 +08001192 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1193 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001194 break;
1195
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001196 case CMD_SET_VOICEMAIL_NUMBER:
1197 request = (MainThreadRequest) msg.obj;
1198 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1199 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001200 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1201 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001202 break;
1203
1204 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1205 handleNullReturnEvent(msg, "setVoicemailNumber");
1206 break;
1207
Stuart Scott54788802015-03-30 13:18:01 -07001208 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1211 request);
1212 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1213 break;
1214
1215 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1216 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1217 break;
1218
Shishir Agrawal302c8692015-06-19 13:49:39 -07001219 case CMD_PERFORM_NETWORK_SCAN:
1220 request = (MainThreadRequest) msg.obj;
1221 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1222 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1223 break;
1224
Hall Liu27d24262020-09-18 19:04:59 -07001225 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001226 request = (MainThreadRequest) msg.obj;
1227 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001228 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1229 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1230 request.argument;
1231 int callForwardingReason = args.first;
1232 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001233 break;
Hall Liu27d24262020-09-18 19:04:59 -07001234 }
1235 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001236 ar = (AsyncResult) msg.obj;
1237 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001238 TelephonyManager.CallForwardingInfoCallback callback =
1239 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1240 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001241 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001242 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001243 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1244 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1245 // Service Class is a bit mask per 3gpp 27.007. Search for
1246 // any service for voice call.
1247 if ((callForwardInfo.serviceClass
1248 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001249 callForwardingInfo = new CallForwardingInfo(
1250 callForwardInfo.status
1251 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001252 callForwardInfo.reason,
1253 callForwardInfo.number,
1254 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001255 break;
1256 }
1257 }
1258 // Didn't find a call forward info for voice call.
1259 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001260 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1261 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001262 }
Hall Liu27d24262020-09-18 19:04:59 -07001263 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001264 } else {
1265 if (ar.result == null) {
1266 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1267 }
1268 if (ar.exception != null) {
1269 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1270 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001271 int errorCode = TelephonyManager
1272 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 if (ar.exception instanceof CommandException) {
1274 CommandException.Error error =
1275 ((CommandException) (ar.exception)).getCommandError();
1276 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001277 errorCode = TelephonyManager
1278 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001279 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001280 errorCode = TelephonyManager
1281 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001282 }
1283 }
Hall Liu27d24262020-09-18 19:04:59 -07001284 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001285 }
Shuo Qian4a594052020-01-23 11:59:30 -08001286 break;
Hall Liu27d24262020-09-18 19:04:59 -07001287 }
Shuo Qian4a594052020-01-23 11:59:30 -08001288
Hall Liu27d24262020-09-18 19:04:59 -07001289 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001290 request = (MainThreadRequest) msg.obj;
1291 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001292 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001293 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001294 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1295 request.argument).first;
1296 request.phone.setCallForwardingOption(
1297 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001298 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001299 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001300 callForwardingInfoToSet.getReason(),
1301 callForwardingInfoToSet.getNumber(),
1302 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1303 break;
Hall Liu27d24262020-09-18 19:04:59 -07001304 }
Shuo Qian4a594052020-01-23 11:59:30 -08001305
Hall Liu27d24262020-09-18 19:04:59 -07001306 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001307 ar = (AsyncResult) msg.obj;
1308 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001309 Consumer<Integer> callback =
1310 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1311 request.argument).second;
1312 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001313 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001314 int errorCode = TelephonyManager.CallForwardingInfoCallback
1315 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001316 if (ar.exception instanceof CommandException) {
1317 CommandException.Error error =
1318 ((CommandException) (ar.exception)).getCommandError();
1319 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001320 errorCode = TelephonyManager.CallForwardingInfoCallback
1321 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001322 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001323 errorCode = TelephonyManager.CallForwardingInfoCallback
1324 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001325 }
1326 }
1327 callback.accept(errorCode);
1328 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001329 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001330 }
Shuo Qian4a594052020-01-23 11:59:30 -08001331 break;
Hall Liu27d24262020-09-18 19:04:59 -07001332 }
Shuo Qian4a594052020-01-23 11:59:30 -08001333
Hall Liu27d24262020-09-18 19:04:59 -07001334 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001335 request = (MainThreadRequest) msg.obj;
1336 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1337 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1338 break;
Hall Liu27d24262020-09-18 19:04:59 -07001339 }
Shuo Qian4a594052020-01-23 11:59:30 -08001340
Hall Liu27d24262020-09-18 19:04:59 -07001341 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001342 ar = (AsyncResult) msg.obj;
1343 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001344 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001345 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001346 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001347 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001348 // Service Class is a bit mask per 3gpp 27.007.
1349 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001350 if (callForwardResults.length > 1
1351 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001352 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001353 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001354 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1355 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001356 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001357 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001358 }
1359 } else {
1360 if (ar.result == null) {
1361 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1362 }
1363 if (ar.exception != null) {
1364 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1365 }
1366 if (ar.exception instanceof CommandException) {
1367 CommandException.Error error =
1368 ((CommandException) (ar.exception)).getCommandError();
1369 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001370 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001371 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001372 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1373 callWaitingStatus =
1374 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001375 }
1376 }
1377 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001378 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001379 break;
Hall Liu27d24262020-09-18 19:04:59 -07001380 }
Shuo Qian4a594052020-01-23 11:59:30 -08001381
Hall Liu27d24262020-09-18 19:04:59 -07001382 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001383 request = (MainThreadRequest) msg.obj;
1384 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001385 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1386 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001387 break;
Hall Liu27d24262020-09-18 19:04:59 -07001388 }
Shuo Qian4a594052020-01-23 11:59:30 -08001389
Hall Liu27d24262020-09-18 19:04:59 -07001390 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001391 ar = (AsyncResult) msg.obj;
1392 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001393 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1394 Consumer<Integer> callback =
1395 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1396 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001397 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001398 if (ar.exception instanceof CommandException) {
1399 CommandException.Error error =
1400 ((CommandException) (ar.exception)).getCommandError();
1401 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1402 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001403 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1404 callback.accept(
1405 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001406 } else {
1407 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1408 }
1409 } else {
1410 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1411 }
1412 } else {
1413 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1414 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001415 }
Shuo Qian4a594052020-01-23 11:59:30 -08001416 break;
Hall Liu27d24262020-09-18 19:04:59 -07001417 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001418 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 CellNetworkScanResult cellScanResult;
1422 if (ar.exception == null && ar.result != null) {
1423 cellScanResult = new CellNetworkScanResult(
1424 CellNetworkScanResult.STATUS_SUCCESS,
1425 (List<OperatorInfo>) ar.result);
1426 } else {
1427 if (ar.result == null) {
1428 loge("getCellNetworkScanResults: Empty response");
1429 }
1430 if (ar.exception != null) {
1431 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1432 }
1433 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1434 if (ar.exception instanceof CommandException) {
1435 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001436 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001437 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1438 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1439 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1440 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1441 }
1442 }
1443 cellScanResult = new CellNetworkScanResult(errorCode, null);
1444 }
1445 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001446 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001447 break;
1448
1449 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1450 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001451 ManualNetworkSelectionArgument selArg =
1452 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001453 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1454 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001455 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1456 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001457 break;
1458
1459 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 if (ar.exception == null) {
1463 request.result = true;
1464 } else {
1465 request.result = false;
1466 loge("setNetworkSelectionModeManual " + ar.exception);
1467 }
1468 notifyRequester(request);
1469 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001470 break;
1471
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001472 case CMD_GET_MODEM_ACTIVITY_INFO:
1473 request = (MainThreadRequest) msg.obj;
1474 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001475 if (defaultPhone != null) {
1476 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001477 } else {
1478 ResultReceiver result = (ResultReceiver) request.argument;
1479 Bundle bundle = new Bundle();
1480 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001481 new ModemActivityInfo(0, 0, 0,
1482 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001483 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001484 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001485 break;
1486
Hall Liud0f208c2020-10-14 16:54:44 -07001487 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001488 ar = (AsyncResult) msg.obj;
1489 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001490 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001491 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001492 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001493 if (mLastModemActivityInfo == null) {
1494 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1495 mLastModemActivitySpecificInfo[0] =
1496 new ActivityStatsTechSpecificInfo(
1497 0,
1498 0,
1499 new int[ModemActivityInfo.getNumTxPowerLevels()],
1500 0);
1501 mLastModemActivityInfo =
1502 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1503 }
1504
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001505 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001506 // Update the last modem activity info and the result of the request.
1507 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1508 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001509 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001510 } else {
1511 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001512 }
Kai Shi917fdc62022-11-28 14:01:02 -08001513 // This is needed to decouple ret from mLastModemActivityInfo
1514 // We don't want to return mLastModemActivityInfo which is updated
1515 // inside mergeModemActivityInfo()
1516 ret = new ModemActivityInfo(
1517 mLastModemActivityInfo.getTimestampMillis(),
1518 mLastModemActivityInfo.getSleepTimeMillis(),
1519 mLastModemActivityInfo.getIdleTimeMillis(),
1520 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001521
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001522 } else {
1523 if (ar.result == null) {
1524 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001525 error = TelephonyManager.ModemActivityInfoException
1526 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001527 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001528 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001529 error = TelephonyManager.ModemActivityInfoException
1530 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001531 } else {
1532 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001533 error = TelephonyManager.ModemActivityInfoException
1534 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001535 }
1536 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001537 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001538 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001539 bundle.putParcelable(
1540 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001541 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001542 } else {
1543 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1544 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001545 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001546 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001547 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001548 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001549
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001550 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001551 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001552 CarrierRestrictionRules argument =
1553 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001554 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001555 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001556 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001557 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001558
1559 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1560 ar = (AsyncResult) msg.obj;
1561 request = (MainThreadRequest) ar.userObj;
1562 if (ar.exception == null && ar.result != null) {
1563 request.result = ar.result;
1564 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001565 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1566 if (ar.exception instanceof CommandException) {
1567 loge("setAllowedCarriers: CommandException: " + ar.exception);
1568 CommandException.Error error =
1569 ((CommandException) (ar.exception)).getCommandError();
1570 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1571 request.result =
1572 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1573 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001574 } else {
1575 loge("setAllowedCarriers: Unknown exception");
1576 }
1577 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001578 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001579 break;
1580
1581 case CMD_GET_ALLOWED_CARRIERS:
1582 request = (MainThreadRequest) msg.obj;
1583 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001584 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001585 break;
1586
1587 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1588 ar = (AsyncResult) msg.obj;
1589 request = (MainThreadRequest) ar.userObj;
1590 if (ar.exception == null && ar.result != null) {
1591 request.result = ar.result;
1592 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001593 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001594 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001595 if (ar.result == null) {
1596 loge("getAllowedCarriers: Empty response");
1597 } else if (ar.exception instanceof CommandException) {
1598 loge("getAllowedCarriers: CommandException: " +
1599 ar.exception);
1600 } else {
1601 loge("getAllowedCarriers: Unknown exception");
1602 }
1603 }
arunvoddud7401012022-12-15 16:08:12 +00001604 if (request.argument != null) {
1605 // This is for the implementation of carrierRestrictionStatus.
1606 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1607 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001608 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001609 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1610 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1611 CarrierRestrictionRules carrierRestrictionRules =
1612 (CarrierRestrictionRules) ar.result;
1613 int carrierId = -1;
1614 try {
1615 CarrierIdentifier carrierIdentifier =
1616 carrierRestrictionRules.getAllowedCarriers().get(0);
1617 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1618 carrierIdentifier);
1619 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1620 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1621 }
1622 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001623 int restrictedStatus =
1624 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1625 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1626 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001627 lockStatus = TelephonyManager
1628 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001629 }
1630 } else {
1631 Rlog.e(LOG_TAG,
1632 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1633 }
1634 callback.accept(lockStatus);
1635 } else {
1636 // This is for the implementation of getAllowedCarriers.
1637 notifyRequester(request);
1638 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001639 break;
1640
Nathan Haroldb3014052017-01-25 15:57:32 -08001641 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1642 ar = (AsyncResult) msg.obj;
1643 request = (MainThreadRequest) ar.userObj;
1644 if (ar.exception == null && ar.result != null) {
1645 request.result = ar.result;
1646 } else {
1647 request.result = new IllegalArgumentException(
1648 "Failed to retrieve Forbidden Plmns");
1649 if (ar.result == null) {
1650 loge("getForbiddenPlmns: Empty response");
1651 } else {
1652 loge("getForbiddenPlmns: Unknown exception");
1653 }
1654 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001655 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001656 break;
1657
1658 case CMD_GET_FORBIDDEN_PLMNS:
1659 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001660 uiccPort = getUiccPortFromRequest(request);
1661 if (uiccPort == null) {
1662 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001663 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001664 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001665 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001666 break;
1667 }
1668 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001669 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001670 if (uiccApp == null) {
1671 loge("getForbiddenPlmns() no app with specified type -- "
1672 + appType);
1673 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001674 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001675 break;
1676 } else {
1677 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1678 + " specified type -- " + appType);
1679 }
1680 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1681 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001682 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001683 break;
1684
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001685 case CMD_SWITCH_SLOTS:
1686 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001687 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001688 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001689 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001690 break;
1691
1692 case EVENT_SWITCH_SLOTS_DONE:
1693 ar = (AsyncResult) msg.obj;
1694 request = (MainThreadRequest) ar.userObj;
1695 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001696 notifyRequester(request);
1697 break;
1698 case CMD_GET_NETWORK_SELECTION_MODE:
1699 request = (MainThreadRequest) msg.obj;
1700 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1701 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1702 break;
1703
1704 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1705 ar = (AsyncResult) msg.obj;
1706 request = (MainThreadRequest) ar.userObj;
1707 if (ar.exception != null) {
1708 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1709 } else {
1710 int mode = ((int[]) ar.result)[0];
1711 if (mode == 0) {
1712 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1713 } else {
1714 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1715 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001717 notifyRequester(request);
1718 break;
1719 case CMD_GET_CDMA_ROAMING_MODE:
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08001720 if (mFeatureFlags.cleanupCdma()) break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001721 request = (MainThreadRequest) msg.obj;
1722 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1723 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1724 break;
1725 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08001726 if (mFeatureFlags.cleanupCdma()) break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001727 ar = (AsyncResult) msg.obj;
1728 request = (MainThreadRequest) ar.userObj;
1729 if (ar.exception != null) {
1730 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1731 } else {
1732 request.result = ((int[]) ar.result)[0];
1733 }
1734 notifyRequester(request);
1735 break;
1736 case CMD_SET_CDMA_ROAMING_MODE:
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08001737 if (mFeatureFlags.cleanupCdma()) break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001738 request = (MainThreadRequest) msg.obj;
1739 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1740 int mode = (int) request.argument;
1741 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1742 break;
1743 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08001744 if (mFeatureFlags.cleanupCdma()) break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001745 ar = (AsyncResult) msg.obj;
1746 request = (MainThreadRequest) ar.userObj;
1747 request.result = ar.exception == null;
1748 notifyRequester(request);
1749 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001750 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08001751 if (mFeatureFlags.cleanupCdma()) break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001752 request = (MainThreadRequest) msg.obj;
1753 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1754 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1755 break;
1756 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08001757 if (mFeatureFlags.cleanupCdma()) break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001758 ar = (AsyncResult) msg.obj;
1759 request = (MainThreadRequest) ar.userObj;
1760 if (ar.exception != null) {
1761 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1762 } else {
1763 request.result = ((int[]) ar.result)[0];
1764 }
1765 notifyRequester(request);
1766 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001767 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08001768 if (mFeatureFlags.cleanupCdma()) break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001769 request = (MainThreadRequest) msg.obj;
1770 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1771 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001772 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1773 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001774 break;
1775 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08001776 if (mFeatureFlags.cleanupCdma()) break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001777 ar = (AsyncResult) msg.obj;
1778 request = (MainThreadRequest) ar.userObj;
1779 request.result = ar.exception == null;
1780 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001781 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001782 case CMD_GET_ALL_CELL_INFO:
1783 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001784 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001785 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001786 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001787 case EVENT_GET_ALL_CELL_INFO_DONE:
1788 ar = (AsyncResult) msg.obj;
1789 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001790 // If a timeout occurs, the response will be null
1791 request.result = (ar.exception == null && ar.result != null)
1792 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001793 synchronized (request) {
1794 request.notifyAll();
1795 }
1796 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001797 case CMD_REQUEST_CELL_INFO_UPDATE:
1798 request = (MainThreadRequest) msg.obj;
1799 request.phone.requestCellInfoUpdate(request.workSource,
1800 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1801 break;
1802 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1803 ar = (AsyncResult) msg.obj;
1804 request = (MainThreadRequest) ar.userObj;
1805 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1806 try {
1807 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001808 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001809 cb.onError(
1810 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1811 ar.exception.getClass().getName(),
1812 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001813 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001814 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001815 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001816 } else {
1817 // use the result as returned
1818 cb.onCellInfo((List<CellInfo>) ar.result);
1819 }
1820 } catch (RemoteException re) {
1821 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1822 }
1823 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001824 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001825 request = (MainThreadRequest) msg.obj;
1826 WorkSource ws = (WorkSource) request.argument;
1827 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001828 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001829 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001830 }
1831 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001832 ar = (AsyncResult) msg.obj;
1833 request = (MainThreadRequest) ar.userObj;
1834 if (ar.exception == null) {
1835 request.result = ar.result;
1836 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001837 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001838 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001839 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001840 }
1841
1842 synchronized (request) {
1843 request.notifyAll();
1844 }
1845 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001846 }
chen xu6dac5ab2018-10-26 17:39:23 -07001847 case CMD_MODEM_REBOOT:
1848 request = (MainThreadRequest) msg.obj;
Tomasz Wasilczykf1af36c2024-12-05 11:36:37 -08001849 onCompleted = obtainMessage(EVENT_CMD_MODEM_REBOOT_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001850 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001851 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001852 case EVENT_CMD_MODEM_REBOOT_DONE:
1853 handleNullReturnEvent(msg, "rebootModem");
1854 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001855 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001856 request = (MainThreadRequest) msg.obj;
1857 boolean enable = (boolean) request.argument;
1858 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001859 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001860 PhoneConfigurationManager.getInstance()
1861 .enablePhone(request.phone, enable, onCompleted);
1862 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001863 }
Michele Berionne5e411512020-11-13 02:36:59 +00001864 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001865 ar = (AsyncResult) msg.obj;
1866 request = (MainThreadRequest) ar.userObj;
1867 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001868 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001869 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001870 if ((boolean) request.result) {
1871 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1872 updateModemStateMetrics();
1873 } else {
1874 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1875 + ar.exception);
1876 }
1877 notifyRequester(request);
1878 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001879 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001880 case CMD_GET_MODEM_STATUS:
1881 request = (MainThreadRequest) msg.obj;
1882 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1883 PhoneConfigurationManager.getInstance()
1884 .getPhoneStatusFromModem(request.phone, onCompleted);
1885 break;
1886 case EVENT_GET_MODEM_STATUS_DONE:
1887 ar = (AsyncResult) msg.obj;
1888 request = (MainThreadRequest) ar.userObj;
1889 int id = request.phone.getPhoneId();
1890 if (ar.exception == null && ar.result != null) {
1891 request.result = ar.result;
1892 //update the cache as modem status has changed
1893 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1894 (boolean) request.result);
1895 } else {
1896 // Return true if modem status cannot be retrieved. For most cases,
1897 // modem status is on. And for older version modems, GET_MODEM_STATUS
1898 // and disable modem are not supported. Modem is always on.
1899 // TODO: this should be fixed in R to support a third
1900 // status UNKNOWN b/131631629
1901 request.result = true;
1902 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1903 + ar.exception);
1904 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001905 notifyRequester(request);
1906 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001907 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1908 request = (MainThreadRequest) msg.obj;
1909 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1910 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1911 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1912 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1913 break;
1914 }
1915 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1916 ar = (AsyncResult) msg.obj;
1917 request = (MainThreadRequest) ar.userObj;
1918 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1919 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1920 args.second.accept(ar.exception == null);
1921 notifyRequester(request);
1922 break;
1923 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001924 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1925 request = (MainThreadRequest) msg.obj;
1926 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1927 Phone phone = getPhoneFromRequest(request);
1928 if (phone != null) {
1929 phone.getSystemSelectionChannels(onCompleted);
1930 } else {
1931 loge("getSystemSelectionChannels: No phone object");
1932 request.result = new ArrayList<RadioAccessSpecifier>();
1933 notifyRequester(request);
1934 }
1935 break;
1936 }
1937 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1938 ar = (AsyncResult) msg.obj;
1939 request = (MainThreadRequest) ar.userObj;
1940 if (ar.exception == null && ar.result != null) {
1941 request.result = ar.result;
1942 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001943 request.result = new IllegalStateException(
1944 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001945 if (ar.result == null) {
1946 loge("getSystemSelectionChannels: Empty response");
1947 } else {
1948 loge("getSystemSelectionChannels: Unknown exception");
1949 }
1950 }
1951 notifyRequester(request);
1952 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001953 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1954 ar = (AsyncResult) msg.obj;
1955 request = (MainThreadRequest) ar.userObj;
1956 if (ar.exception == null && ar.result != null) {
1957 request.result = ar.result;
1958 } else {
1959 request.result = -1;
1960 loge("Failed to set Forbidden Plmns");
1961 if (ar.result == null) {
1962 loge("setForbidenPlmns: Empty response");
1963 } else if (ar.exception != null) {
1964 loge("setForbiddenPlmns: Exception: " + ar.exception);
1965 request.result = -1;
1966 } else {
1967 loge("setForbiddenPlmns: Unknown exception");
1968 }
1969 }
1970 notifyRequester(request);
1971 break;
1972 case CMD_SET_FORBIDDEN_PLMNS:
1973 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001974 uiccPort = getUiccPortFromRequest(request);
1975 if (uiccPort == null) {
1976 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001977 request.result = -1;
1978 notifyRequester(request);
1979 break;
1980 }
1981 Pair<Integer, List<String>> setFplmnsArgs =
1982 (Pair<Integer, List<String>>) request.argument;
1983 appType = setFplmnsArgs.first;
1984 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001985 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001986 if (uiccApp == null) {
1987 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1988 request.result = -1;
1989 loge("Failed to get UICC App");
1990 notifyRequester(request);
1991 } else {
1992 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1993 ((SIMRecords) uiccApp.getIccRecords())
1994 .setForbiddenPlmns(onCompleted, fplmns);
1995 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001996 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001997 case CMD_ERASE_MODEM_CONFIG:
1998 request = (MainThreadRequest) msg.obj;
1999 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2000 defaultPhone.eraseModemConfig(onCompleted);
2001 break;
2002 case EVENT_ERASE_MODEM_CONFIG_DONE:
2003 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002004 break;
zoey chene02881a2019-12-30 16:11:23 +08002005
Kai Shif70f46f2021-03-03 13:59:46 -08002006 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2007 request = (MainThreadRequest) msg.obj;
2008 request.result = defaultPhone.eraseDataInSharedPreferences();
2009 notifyRequester(request);
2010 break;
2011
zoey chene02881a2019-12-30 16:11:23 +08002012 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2013 request = (MainThreadRequest) msg.obj;
2014 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2015 Pair<String, String> changed = (Pair<String, String>) request.argument;
2016 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2017 changed.first, changed.second, onCompleted);
2018 break;
2019 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2020 ar = (AsyncResult) msg.obj;
2021 request = (MainThreadRequest) ar.userObj;
2022 if (ar.exception == null) {
2023 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002024 // If the operation is successful, update the PIN storage
2025 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2026 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002027 UiccController.getInstance().getPinStorage()
2028 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002029 } else {
2030 request.result = msg.arg1;
2031 }
2032 notifyRequester(request);
2033 break;
2034
Michele Berionne5e411512020-11-13 02:36:59 +00002035 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002036 request = (MainThreadRequest) msg.obj;
2037 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2038 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2039 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2040 enabled.first, enabled.second, onCompleted);
2041 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002042 }
zoey chene02881a2019-12-30 16:11:23 +08002043 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2044 ar = (AsyncResult) msg.obj;
2045 request = (MainThreadRequest) ar.userObj;
2046 if (ar.exception == null) {
2047 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002048 // If the operation is successful, update the PIN storage
2049 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2050 int phoneId = getPhoneFromRequest(request).getPhoneId();
2051 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002052 UiccController.getInstance().getPinStorage()
2053 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002054 } else {
2055 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2056 }
zoey chene02881a2019-12-30 16:11:23 +08002057 } else {
2058 request.result = msg.arg1;
2059 }
Michele Berionne5e411512020-11-13 02:36:59 +00002060
2061
zoey chene02881a2019-12-30 16:11:23 +08002062 notifyRequester(request);
2063 break;
2064
Peter Wangdafb9ac2020-01-15 14:13:38 -08002065 case MSG_NOTIFY_USER_ACTIVITY:
2066 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002067 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002068 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2069 getDefaultPhone().getContext().sendBroadcastAsUser(
2070 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2071 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002072
2073 case CMD_SET_DATA_THROTTLING: {
2074 request = (MainThreadRequest) msg.obj;
2075 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2076 DataThrottlingRequest dataThrottlingRequest =
2077 (DataThrottlingRequest) request.argument;
2078 Phone phone = getPhoneFromRequest(request);
2079 if (phone != null) {
2080 phone.setDataThrottling(onCompleted,
2081 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2082 dataThrottlingRequest.getCompletionDurationMillis());
2083 } else {
2084 loge("setDataThrottling: No phone object");
2085 request.result =
2086 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2087 notifyRequester(request);
2088 }
2089
2090 break;
2091 }
2092 case EVENT_SET_DATA_THROTTLING_DONE:
2093 ar = (AsyncResult) msg.obj;
2094 request = (MainThreadRequest) ar.userObj;
2095
2096 if (ar.exception == null) {
2097 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2098 } else if (ar.exception instanceof CommandException) {
2099 loge("setDataThrottling: CommandException: " + ar.exception);
2100 CommandException.Error error =
2101 ((CommandException) (ar.exception)).getCommandError();
2102
2103 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2104 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002105 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002106 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2107 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002108 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2109 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002110 } else {
2111 request.result =
2112 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2113 }
2114 } else {
2115 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2116 }
2117 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2118 notifyRequester(request);
2119 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002120
2121 case CMD_SET_SIM_POWER: {
2122 request = (MainThreadRequest) msg.obj;
2123 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2124 request = (MainThreadRequest) msg.obj;
2125 int stateToSet =
2126 ((Pair<Integer, IIntegerConsumer>)
2127 request.argument).first;
2128 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2129 break;
2130 }
2131 case EVENT_SET_SIM_POWER_DONE: {
2132 ar = (AsyncResult) msg.obj;
2133 request = (MainThreadRequest) ar.userObj;
2134 IIntegerConsumer callback =
2135 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2136 if (ar.exception != null) {
2137 loge("setSimPower exception: " + ar.exception);
2138 int errorCode = TelephonyManager.CallForwardingInfoCallback
2139 .RESULT_ERROR_UNKNOWN;
2140 if (ar.exception instanceof CommandException) {
2141 CommandException.Error error =
2142 ((CommandException) (ar.exception)).getCommandError();
2143 if (error == CommandException.Error.SIM_ERR) {
2144 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2145 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2146 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2147 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2148 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2149 } else {
2150 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2151 }
2152 }
2153 try {
2154 callback.accept(errorCode);
2155 } catch (RemoteException e) {
2156 // Ignore if the remote process is no longer available to call back.
2157 Log.w(LOG_TAG, "setSimPower: callback not available.");
2158 }
2159 } else {
2160 try {
2161 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2162 } catch (RemoteException e) {
2163 // Ignore if the remote process is no longer available to call back.
2164 Log.w(LOG_TAG, "setSimPower: callback not available.");
2165 }
2166 }
2167 break;
2168 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002169 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2170 request = (MainThreadRequest) msg.obj;
2171
2172 final Phone phone = getPhoneFromRequest(request);
2173 if (phone == null || phone.getServiceStateTracker() == null) {
2174 request.result = new IllegalStateException("Phone or SST is null");
2175 notifyRequester(request);
2176 break;
2177 }
2178
2179 Pair<Integer, SignalStrengthUpdateRequest> pair =
2180 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2181 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2182 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002183 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002184 request.subId, pair.first /*callingUid*/,
2185 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002186 break;
2187 }
2188 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2189 ar = (AsyncResult) msg.obj;
2190 request = (MainThreadRequest) ar.userObj;
2191 // request.result will be the exception of ar if present, true otherwise.
2192 // Be cautious not to leave result null which will wait() forever
2193 request.result = ar.exception != null ? ar.exception : true;
2194 notifyRequester(request);
2195 break;
2196 }
2197 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2198 request = (MainThreadRequest) msg.obj;
2199
2200 Phone phone = getPhoneFromRequest(request);
2201 if (phone == null || phone.getServiceStateTracker() == null) {
2202 request.result = new IllegalStateException("Phone or SST is null");
2203 notifyRequester(request);
2204 break;
2205 }
2206
2207 Pair<Integer, SignalStrengthUpdateRequest> pair =
2208 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2209 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2210 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002211 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002212 request.subId, pair.first /*callingUid*/,
2213 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002214 break;
2215 }
2216 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2217 ar = (AsyncResult) msg.obj;
2218 request = (MainThreadRequest) ar.userObj;
2219 request.result = ar.exception != null ? ar.exception : true;
2220 notifyRequester(request);
2221 break;
2222 }
Jordan Liu109698e2020-11-24 14:50:34 -08002223
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002224 case CMD_GET_SLICING_CONFIG: {
2225 request = (MainThreadRequest) msg.obj;
2226 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2227 request.phone.getSlicingConfig(onCompleted);
2228 break;
2229 }
2230 case EVENT_GET_SLICING_CONFIG_DONE: {
2231 ar = (AsyncResult) msg.obj;
2232 request = (MainThreadRequest) ar.userObj;
2233 ResultReceiver result = (ResultReceiver) request.argument;
2234
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002235 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002236 Bundle bundle = new Bundle();
2237 int resultCode = 0;
2238 if (ar.exception != null) {
2239 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2240 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002241 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002242 } else if (ar.result == null) {
2243 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002244 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002245 } else {
2246 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002247 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2248 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002249 }
2250
2251 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002252 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002253 }
2254 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2255 result.send(resultCode, bundle);
2256 notifyRequester(request);
2257 break;
2258 }
2259
Sarah Chin71b3a852022-09-28 15:54:19 -07002260 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002261 request = (MainThreadRequest) msg.obj;
2262 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002263 PurchasePremiumCapabilityArgument arg =
2264 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002265 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2266 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002267 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002268 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002269
Sarah Chin71b3a852022-09-28 15:54:19 -07002270 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002271 ar = (AsyncResult) msg.obj;
2272 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002273 PurchasePremiumCapabilityArgument arg =
2274 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002275 try {
2276 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002277 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002278 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002279 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002280 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002281 + TelephonyManager.convertPurchaseResultToString(result));
2282 } catch (RemoteException e) {
2283 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002284 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002285 + " failed: " + e;
2286 if (DBG) log(logStr);
2287 AnomalyReporter.reportAnomaly(
2288 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2289 }
2290 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002291 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002292
Michele Berionne5e411512020-11-13 02:36:59 +00002293 case CMD_PREPARE_UNATTENDED_REBOOT:
2294 request = (MainThreadRequest) msg.obj;
2295 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002296 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002297 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002298 notifyRequester(request);
2299 break;
2300
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 default:
2302 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2303 break;
2304 }
2305 }
Jake Hambye994d462014-02-03 13:10:13 -08002306
Pengquan Menga1bb6272018-09-06 09:59:22 -07002307 private void notifyRequester(MainThreadRequest request) {
2308 synchronized (request) {
2309 request.notifyAll();
2310 }
2311 }
2312
Jake Hambye994d462014-02-03 13:10:13 -08002313 private void handleNullReturnEvent(Message msg, String command) {
2314 AsyncResult ar = (AsyncResult) msg.obj;
2315 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2316 if (ar.exception == null) {
2317 request.result = true;
2318 } else {
2319 request.result = false;
2320 if (ar.exception instanceof CommandException) {
2321 loge(command + ": CommandException: " + ar.exception);
2322 } else {
2323 loge(command + ": Unknown exception");
2324 }
2325 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002326 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -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) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002336 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2337 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -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 */
2345 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2346 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002347 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002348 }
2349
2350 /**
2351 * Posts the specified command to be executed on the main thread,
2352 * waits for the request to complete, and returns the result.
2353 * @see #sendRequestAsync
2354 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002355 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002356 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2357 }
2358
2359 /**
2360 * Posts the specified command to be executed on the main thread,
2361 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2362 * if not timeout or null otherwise.
2363 * @see #sendRequestAsync
2364 */
2365 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2366 long timeoutInMs) {
2367 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002368 }
2369
2370 /**
2371 * Posts the specified command to be executed on the main thread,
2372 * waits for the request to complete, and returns the result.
2373 * @see #sendRequestAsync
2374 */
Nathan Harold92bed182018-10-12 18:16:49 -07002375 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002376 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002377 }
2378
2379 /**
2380 * Posts the specified command to be executed on the main thread,
2381 * waits for the request to complete, and returns the result.
2382 * @see #sendRequestAsync
2383 */
2384 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002385 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2386 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002387 }
2388
2389 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002390 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2391 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2392 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002393 * @see #sendRequestAsync
2394 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002395 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2396 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2398 throw new RuntimeException("This method will deadlock if called from the main thread.");
2399 }
2400
Nathan Harold92bed182018-10-12 18:16:49 -07002401 MainThreadRequest request = null;
2402 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2403 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2404 } else if (phone != null) {
2405 request = new MainThreadRequest(argument, phone, workSource);
2406 } else {
2407 request = new MainThreadRequest(argument, subId, workSource);
2408 }
2409
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 Message msg = mMainThreadHandler.obtainMessage(command, request);
2411 msg.sendToTarget();
2412
Rambo Wang0f050d82021-02-12 11:43:36 -08002413
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002415 if (timeoutInMs >= 0) {
2416 // Wait for at least timeoutInMs before returning null request result
2417 long now = SystemClock.elapsedRealtime();
2418 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002419 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002420 try {
2421 request.wait(deadline - now);
2422 } catch (InterruptedException e) {
2423 // Do nothing, go back and check if request is completed or timeout
2424 } finally {
2425 now = SystemClock.elapsedRealtime();
2426 }
2427 }
2428 } else {
2429 // Wait for the request to complete
2430 while (request.result == null) {
2431 try {
2432 request.wait();
2433 } catch (InterruptedException e) {
2434 // Do nothing, go back and wait until the request is complete
2435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 }
2437 }
2438 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002439 if (request.result == null) {
2440 Log.wtf(LOG_TAG,
2441 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 return request.result;
2444 }
2445
2446 /**
2447 * Asynchronous ("fire and forget") version of sendRequest():
2448 * Posts the specified command to be executed on the main thread, and
2449 * returns immediately.
2450 * @see #sendRequest
2451 */
2452 private void sendRequestAsync(int command) {
2453 mMainThreadHandler.sendEmptyMessage(command);
2454 }
2455
2456 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002457 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002458 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002459 */
2460 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002461 sendRequestAsync(command, argument, null, null);
2462 }
2463
2464 /**
2465 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2466 * @see {@link #sendRequest(int,Object)}
2467 */
2468 private void sendRequestAsync(
2469 int command, Object argument, Phone phone, WorkSource workSource) {
2470 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002471 Message msg = mMainThreadHandler.obtainMessage(command, request);
2472 msg.sendToTarget();
2473 }
2474
2475 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 * Initialize the singleton PhoneInterfaceManager instance.
2477 * This is only done once, at startup, from PhoneApp.onCreate().
2478 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002479 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 synchronized (PhoneInterfaceManager.class) {
2481 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002482 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 } else {
2484 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2485 }
2486 return sInstance;
2487 }
2488 }
2489
2490 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002491 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002493 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002494 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002496 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002497 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002498 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2500 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002501 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002502 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002503 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002504 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002505 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002506 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002507 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2508 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002509 mVendorApiLevel = SystemProperties.getInt(
2510 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2511
Tyler Gunn64144d92022-03-17 14:16:41 -07002512 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 publish();
arunvoddud7401012022-12-15 16:08:12 +00002514 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002515
2516 // Create the SatelliteEntitlementController singleton, for using the get the
2517 // entitlementStatus for satellite service.
2518 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 }
2520
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002521 @VisibleForTesting
2522 public SharedPreferences getSharedPreferences() {
2523 return mTelephonySharedPreferences;
2524 }
2525
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002526 /**
2527 * Get the default phone for this device.
2528 */
2529 @VisibleForTesting
2530 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002531 Phone thePhone = getPhone(getDefaultSubscription());
2532 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2533 }
2534
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 private void publish() {
2536 if (DBG) log("publish: " + this);
2537
Peter Wangc035ce42020-01-08 21:00:22 -08002538 TelephonyFrameworkInitializer
2539 .getTelephonyServiceManager()
2540 .getTelephonyServiceRegisterer()
2541 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 }
2543
Stuart Scott584921c2015-01-15 17:10:34 -08002544 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002545 if (request.phone != null) {
2546 return request.phone;
2547 } else {
2548 return getPhoneFromSubId(request.subId);
2549 }
2550 }
2551
2552 private Phone getPhoneFromSubId(int subId) {
2553 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2554 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002555 }
2556
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002557 /**
2558 * Get phone object associated with a subscription.
2559 * Return default phone if phone object associated with subscription is null
2560 * @param subId - subscriptionId
2561 * @return phone object associated with a subscription or default phone if null.
2562 */
Ling Mac28f0212023-03-24 16:07:15 -07002563 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002564 Phone phone = getPhoneFromSubId(subId);
2565 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002566 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002567 phone = getDefaultPhone();
2568 }
2569 return phone;
2570 }
2571
Rambo Wange53e07d2022-05-10 13:01:13 -07002572 @Nullable
2573 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002574 Phone phone = getPhoneFromRequest(request);
2575 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002576 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002577 }
2578
Ling Mac28f0212023-03-24 16:07:15 -07002579 /**
2580 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2581 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2582 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2583 * @return The Phone associated the sub Id
2584 */
2585 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002586 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588
Kai Shif70f46f2021-03-03 13:59:46 -08002589 private void sendEraseModemConfig(@NonNull Phone phone) {
Tomasz Wasilczykf1af36c2024-12-05 11:36:37 -08002590 if (mFeatureFlags.cleanupCdma()) return;
Kai Shif70f46f2021-03-03 13:59:46 -08002591 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2592 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2593 }
2594
2595 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2596 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2597 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002598 }
2599
Peter Wang44b186e2020-01-13 23:33:09 -08002600 private boolean isImsAvailableOnDevice() {
2601 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2602 if (pm == null) {
2603 // For some reason package manger is not available.. This will fail internally anyway,
2604 // so do not throw error and allow.
2605 return true;
2606 }
2607 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2608 }
2609
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002611 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2612 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2613
Wink Savilleadd7cc52014-09-08 14:23:09 -07002614 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002615 }
2616
Wink Savilleb564aae2014-10-23 10:18:09 -07002617 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 if (DBG) log("dial: " + number);
2619 // No permission check needed here: This is just a wrapper around the
2620 // ACTION_DIAL intent, which is available to any app since it puts up
2621 // the UI before it does anything.
2622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 String url = createTelUrl(number);
2626 if (url == null) {
2627 return;
2628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630 // PENDING: should we just silently fail if phone is offhook or ringing?
2631 PhoneConstants.State state = mCM.getState(subId);
2632 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2633 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2634 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002635 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 }
2637 } finally {
2638 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 }
2640 }
2641
2642 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002643 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002644 }
2645
Wink Savilleb564aae2014-10-23 10:18:09 -07002646 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 if (DBG) log("call: " + number);
2648
2649 // This is just a wrapper around the ACTION_CALL intent, but we still
Jack Yu58d04bd2024-09-10 17:32:39 -07002650 // need to do a permission check since we're calling startActivityAsUser()
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 // from the context of the phone app.
2652 enforceCallPermission();
2653
Jordan Liu1617b712019-07-10 15:06:26 -07002654 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 != AppOpsManager.MODE_ALLOWED) {
2656 return;
2657 }
2658
joonhunshin4ac60942023-11-15 15:23:39 +00002659 enforceTelephonyFeatureWithException(callingPackage,
2660 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 String url = createTelUrl(number);
2665 if (url == null) {
2666 return;
2667 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669 boolean isValid = false;
2670 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2671 if (slist != null) {
2672 for (SubscriptionInfo subInfoRecord : slist) {
2673 if (subInfoRecord.getSubscriptionId() == subId) {
2674 isValid = true;
2675 break;
2676 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002677 }
Wink Saville08874612014-08-31 19:19:58 -07002678 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679 if (!isValid) {
2680 return;
2681 }
Wink Saville08874612014-08-31 19:19:58 -07002682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2684 intent.putExtra(SUBSCRIPTION_KEY, subId);
2685 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -07002686 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 } finally {
2688 Binder.restoreCallingIdentity(identity);
2689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 }
2691
Wink Savilleb564aae2014-10-23 10:18:09 -07002692 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002693 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002694 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2695 }
2696
Wink Savilleb564aae2014-10-23 10:18:09 -07002697 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002698 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002699 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2700 }
2701
Wink Savilleb564aae2014-10-23 10:18:09 -07002702 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704
joonhunshin4ac60942023-11-15 15:23:39 +00002705 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2706 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2707 "supplyPinReportResultForSubscriber");
2708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709 final long identity = Binder.clearCallingIdentity();
2710 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002711 Phone phone = getPhone(subId);
2712 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 checkSimPin.start();
2714 return checkSimPin.unlockSim(null, pin);
2715 } finally {
2716 Binder.restoreCallingIdentity(identity);
2717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 }
2719
Wink Savilleb564aae2014-10-23 10:18:09 -07002720 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722
joonhunshin4ac60942023-11-15 15:23:39 +00002723 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2724 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 final long identity = Binder.clearCallingIdentity();
2727 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002728 Phone phone = getPhone(subId);
2729 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 checkSimPuk.start();
2731 return checkSimPuk.unlockSim(puk, pin);
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
2734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 }
2736
2737 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002738 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 * a synchronous one.
2740 */
2741 private static class UnlockSim extends Thread {
2742
2743 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002744 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745
2746 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002747 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2748 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002749
2750 // For replies from SimCard interface
2751 private Handler mHandler;
2752
2753 // For async handler to identify request type
2754 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002755 private static final int SUPPLY_PIN_DELAYED = 101;
2756 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2757 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2758 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759
Michele Berionne5e411512020-11-13 02:36:59 +00002760 UnlockSim(int phoneId, IccCard simCard) {
2761 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 mSimCard = simCard;
2763 }
2764
2765 @Override
2766 public void run() {
2767 Looper.prepare();
2768 synchronized (UnlockSim.this) {
2769 mHandler = new Handler() {
2770 @Override
2771 public void handleMessage(Message msg) {
2772 AsyncResult ar = (AsyncResult) msg.obj;
2773 switch (msg.what) {
2774 case SUPPLY_PIN_COMPLETE:
2775 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2776 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002777 mRetryCount = msg.arg1;
2778 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002779 CommandException.Error error = null;
2780 if (ar.exception instanceof CommandException) {
2781 error = ((CommandException) (ar.exception))
2782 .getCommandError();
2783 }
2784 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002785 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002786 } else if (error == CommandException.Error.ABORTED) {
2787 /* When UiccCardApp dispose, handle message and return
2788 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002789 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002790 } else {
2791 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2792 }
2793 } else {
2794 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002797 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 UnlockSim.this.notifyAll();
2799 }
2800 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002801 case SUPPLY_PIN_DELAYED:
2802 if(!mDone) {
2803 String logStr = "Delay in receiving SIM PIN response ";
2804 if (DBG) log(logStr);
2805 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2806 }
2807 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002808 }
2809 }
2810 };
2811 UnlockSim.this.notifyAll();
2812 }
2813 Looper.loop();
2814 }
2815
2816 /*
2817 * Use PIN or PUK to unlock SIM card
2818 *
2819 * If PUK is null, unlock SIM card with PIN
2820 *
2821 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302822 *
2823 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2824 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002825 */
Wink Saville9de0f752013-10-22 19:04:03 -07002826 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827
2828 while (mHandler == null) {
2829 try {
2830 wait();
2831 } catch (InterruptedException e) {
2832 Thread.currentThread().interrupt();
2833 }
2834 }
2835 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2836
2837 if (puk == null) {
2838 mSimCard.supplyPin(pin, callback);
2839 } else {
2840 mSimCard.supplyPuk(puk, pin, callback);
2841 }
2842
2843 while (!mDone) {
2844 try {
2845 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002846 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2847 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 wait();
2849 } catch (InterruptedException e) {
2850 // Restore the interrupted status
2851 Thread.currentThread().interrupt();
2852 }
2853 }
2854 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002855 int[] resultArray = new int[2];
2856 resultArray[0] = mResult;
2857 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002858
2859 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002860 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002861 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302862 // This instance is no longer reused, so quit its thread's looper.
2863 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002864
Wink Saville9de0f752013-10-22 19:04:03 -07002865 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002866 }
2867 }
2868
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002869 /**
2870 * This method has been removed due to privacy and stability concerns.
2871 */
2872 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002874 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2875 return;
Wink Saville36469e72014-06-11 15:17:00 -07002876 }
2877
Nathan Harold1f889d82020-06-04 17:05:26 -07002878 @Override
2879 public void updateServiceLocationWithPackageName(String callingPackage) {
2880 mApp.getSystemService(AppOpsManager.class)
2881 .checkPackage(Binder.getCallingUid(), callingPackage);
2882
Nathan Haroldf096d982020-11-18 17:18:06 -08002883 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002884 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2885 // Callers targeting S have no business invoking this method.
2886 return;
2887 }
2888
2889 LocationAccessPolicy.LocationPermissionResult locationResult =
2890 LocationAccessPolicy.checkLocationPermission(mApp,
2891 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2892 .setCallingPackage(callingPackage)
2893 .setCallingFeatureId(null)
2894 .setCallingPid(Binder.getCallingPid())
2895 .setCallingUid(Binder.getCallingUid())
2896 .setMethod("updateServiceLocation")
2897 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2898 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2899 .build());
2900 // Apps that lack location permission have no business calling this method;
2901 // however, because no permission was declared in the public API, denials must
2902 // all be "soft".
2903 switch (locationResult) {
2904 case DENIED_HARD: /* fall through */
2905 case DENIED_SOFT:
2906 return;
2907 }
2908
2909 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 final long identity = Binder.clearCallingIdentity();
2911 try {
Ling Mac28f0212023-03-24 16:07:15 -07002912 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002913 } finally {
2914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002916 }
2917
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002918 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002919 @Override
2920 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002921 return isRadioOnWithFeature(callingPackage, null);
2922 }
2923
2924
2925 @Override
2926 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2927 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2928 callingFeatureId);
2929 }
2930
2931 @Deprecated
2932 @Override
2933 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2934 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002935 }
2936
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002937 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002938 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2939 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002941 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002942 return false;
2943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002944
joonhunshin4ac60942023-11-15 15:23:39 +00002945 enforceTelephonyFeatureWithException(callingPackage,
2946 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 return isRadioOnForSubscriber(subId);
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002954 }
2955
2956 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957 final long identity = Binder.clearCallingIdentity();
2958 try {
2959 final Phone phone = getPhone(subId);
2960 if (phone != null) {
2961 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2962 } else {
2963 return false;
2964 }
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002968 }
2969
2970 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002971 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002972 }
Wink Saville36469e72014-06-11 15:17:00 -07002973
Wink Savilleb564aae2014-10-23 10:18:09 -07002974 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976
joonhunshin4ac60942023-11-15 15:23:39 +00002977 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2978 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 final Phone phone = getPhone(subId);
2983 if (phone != null) {
2984 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2985 }
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002988 }
Wink Saville36469e72014-06-11 15:17:00 -07002989 }
2990
2991 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002992 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002993 }
2994
Wink Savilleb564aae2014-10-23 10:18:09 -07002995 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002996 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997
2998 final long identity = Binder.clearCallingIdentity();
2999 try {
3000 final Phone phone = getPhone(subId);
3001 if (phone == null) {
3002 return false;
3003 }
3004 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3005 toggleRadioOnOffForSubscriber(subId);
3006 }
3007 return true;
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003011 }
Wink Saville36469e72014-06-11 15:17:00 -07003012
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003013 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003014 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00003015
Tomasz Wasilczykef763582024-09-17 13:50:32 -07003016 if (!mApp.getResources().getBoolean(
3017 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3018 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3019 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
3020 }
joonhunshin4ac60942023-11-15 15:23:39 +00003021
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003022 /*
3023 * If any of the Radios are available, it will need to be
3024 * shutdown. So return true if any Radio is available.
3025 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 final long identity = Binder.clearCallingIdentity();
3027 try {
3028 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3029 Phone phone = PhoneFactory.getPhone(i);
3030 if (phone != null && phone.isRadioAvailable()) return true;
3031 }
3032 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3033 return false;
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003036 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003037 }
3038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003040 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 enforceModifyPermission();
3042
joonhunshin4ac60942023-11-15 15:23:39 +00003043 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3044 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3049 logv("Shutting down Phone " + i);
3050 shutdownRadioUsingPhoneId(i);
3051 }
3052 } finally {
3053 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003054 }
3055 }
3056
3057 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003058 Phone phone = PhoneFactory.getPhone(phoneId);
3059 if (phone != null && phone.isRadioAvailable()) {
3060 phone.shutdownRadio();
3061 }
3062 }
3063
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003065 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003066
Ling Ma83dc5ea2023-01-12 15:06:04 -08003067 if (!turnOn) {
3068 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3069 }
3070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3074 if (defaultPhone != null) {
3075 defaultPhone.setRadioPower(turnOn);
3076 return true;
3077 } else {
3078 loge("There's no default phone.");
3079 return false;
3080 }
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003083 }
Wink Saville36469e72014-06-11 15:17:00 -07003084 }
3085
Wink Savilleb564aae2014-10-23 10:18:09 -07003086 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003087 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003088
Ling Ma83dc5ea2023-01-12 15:06:04 -08003089 if (!turnOn) {
3090 log("setRadioPowerForSubscriber off: subId=" + subId
3091 + ",callingPackage=" + getCurrentPackageName());
3092 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003093 final long identity = Binder.clearCallingIdentity();
3094 try {
3095 final Phone phone = getPhone(subId);
3096 if (phone != null) {
3097 phone.setRadioPower(turnOn);
3098 return true;
3099 } else {
3100 return false;
3101 }
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003105 }
3106
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003107 /**
3108 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3109 * no reason to power it off. When any of the voters want to power it off, it will be turned
3110 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3111 * powering it off, and these radio off votes will be cleared.
3112 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3113 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3114 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3115 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3116 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3117 * check its vote.
3118 *
3119 * @param subId The subscription ID.
3120 * @param reason The reason for powering off radio.
3121 * @return true on success and false on failure.
3122 */
3123 public boolean requestRadioPowerOffForReason(int subId,
3124 @TelephonyManager.RadioPowerReason int reason) {
3125 enforceModifyPermission();
3126
joonhunshin4ac60942023-11-15 15:23:39 +00003127 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3128 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3129
Ling Ma83dc5ea2023-01-12 15:06:04 -08003130 log("requestRadioPowerOffForReason: subId=" + subId
3131 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003132 final long identity = Binder.clearCallingIdentity();
3133 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003134 boolean result = false;
3135 for (Phone phone : PhoneFactory.getPhones()) {
3136 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003137 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003138 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003139 if (!result) {
3140 loge("requestRadioPowerOffForReason: no phone exists");
3141 }
3142 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
3146 }
3147
3148 /**
3149 * Remove the vote on powering off the radio for a reason, as requested by
3150 * {@link requestRadioPowerOffForReason}.
3151 *
3152 * @param subId The subscription ID.
3153 * @param reason The reason for powering off radio.
3154 * @return true on success and false on failure.
3155 */
3156 public boolean clearRadioPowerOffForReason(int subId,
3157 @TelephonyManager.RadioPowerReason int reason) {
3158 enforceModifyPermission();
3159
joonhunshin4ac60942023-11-15 15:23:39 +00003160 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3161 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3162
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003163 final long identity = Binder.clearCallingIdentity();
3164 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003165 boolean result = false;
3166 for (Phone phone : PhoneFactory.getPhones()) {
3167 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003168 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003169 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003170 if (!result) {
3171 loge("clearRadioPowerOffForReason: no phone exists");
3172 }
3173 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
3177 }
3178
3179 /**
3180 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3181 *
3182 * @param subId The subscription ID.
3183 * @param callingPackage The package making the call.
3184 * @param callingFeatureId The feature in the package.
3185 * @return List of reasons for powering off radio.
3186 */
3187 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3188 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3189
joonhunshin4ac60942023-11-15 15:23:39 +00003190 enforceTelephonyFeatureWithException(callingPackage,
3191 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3192
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003193 final long identity = Binder.clearCallingIdentity();
3194 List result = new ArrayList();
3195 try {
3196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3197 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3198 return result;
3199 }
3200
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003201 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003202 if (phone != null) {
3203 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003204 } else {
3205 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003206 }
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
3209 }
3210 return result;
3211 }
3212
Wink Saville36469e72014-06-11 15:17:00 -07003213 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003214 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003215 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217
joonhunshin4ac60942023-11-15 15:23:39 +00003218 enforceTelephonyFeatureWithException(callingPackage,
3219 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 final long identity = Binder.clearCallingIdentity();
3222 try {
Jack Yu285100e2022-12-02 22:48:35 -08003223 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003225 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003226 phone.getDataSettingsManager().setDataEnabled(
3227 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228 return true;
3229 } else {
3230 return false;
3231 }
3232 } finally {
3233 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003235 }
3236
Wink Saville36469e72014-06-11 15:17:00 -07003237 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003239 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003240 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241
joonhunshin4ac60942023-11-15 15:23:39 +00003242 enforceTelephonyFeatureWithException(callingPackage,
3243 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245 final long identity = Binder.clearCallingIdentity();
3246 try {
Jack Yu285100e2022-12-02 22:48:35 -08003247 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003249 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003250 phone.getDataSettingsManager().setDataEnabled(
3251 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252 return true;
3253 } else {
3254 return false;
3255 }
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 }
3260
Sanket Padawe356d7632015-06-22 14:03:32 -07003261 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003262 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003263 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3264 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 final Phone phone = getPhone(subId);
3269 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003270 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271 } else {
3272 return false;
3273 }
3274 } finally {
3275 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003277 }
3278
3279 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003280 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003281 }
3282
pkanwarae03a6b2016-11-06 20:37:09 -08003283 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284 enforceCallPermission();
3285
joonhunshin4ac60942023-11-15 15:23:39 +00003286 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3287 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003289 final long identity = Binder.clearCallingIdentity();
3290 try {
3291 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3292 return;
3293 }
3294 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3295 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
pkanwar32d516d2016-10-14 19:37:38 -07003299 };
3300
Wink Savilleb564aae2014-10-23 10:18:09 -07003301 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003302 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303
joonhunshin4ac60942023-11-15 15:23:39 +00003304 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3305 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3310 return false;
3311 }
3312 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003316 }
3317
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003318 /**
3319 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3320 * tag on getCallState Binder call.
3321 */
3322 @Deprecated
3323 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003324 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003325 if (CompatChanges.isChangeEnabled(
3326 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3327 Binder.getCallingUid())) {
3328 // Do not allow this API to be called on API version 31+, it should only be
3329 // called on old apps using this Binder call directly.
3330 throw new SecurityException("This method can only be used for applications "
3331 + "targeting API version 30 or less.");
3332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333 final long identity = Binder.clearCallingIdentity();
3334 try {
Ling Mac28f0212023-03-24 16:07:15 -07003335 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3336 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003337 } finally {
3338 Binder.restoreCallingIdentity(identity);
3339 }
3340 }
3341
3342 @Override
3343 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3344 if (CompatChanges.isChangeEnabled(
3345 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3346 Binder.getCallingUid())) {
3347 // Check READ_PHONE_STATE for API version 31+
3348 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3349 featureId, "getCallStateForSubscription")) {
3350 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3351 + "targeting API level 31+.");
3352 }
3353 }
joonhunshin4ac60942023-11-15 15:23:39 +00003354
3355 enforceTelephonyFeatureWithException(callingPackage,
3356 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3357
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003361 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3362 PhoneConstantConversions.convertCallState(phone.getState());
3363 } finally {
3364 Binder.restoreCallingIdentity(identity);
3365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003366 }
3367
Sanket Padawe356d7632015-06-22 14:03:32 -07003368 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003369 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003370 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003371 }
3372
3373 @Override
3374 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003375 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3376 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 final long identity = Binder.clearCallingIdentity();
3379 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003380 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003382 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003383 } else {
3384 return PhoneConstantConversions.convertDataState(
3385 PhoneConstants.DataState.DISCONNECTED);
3386 }
3387 } finally {
3388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 }
3391
Sanket Padawe356d7632015-06-22 14:03:32 -07003392 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003393 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003394 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003395 }
3396
3397 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003398 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003399 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3400 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402 final long identity = Binder.clearCallingIdentity();
3403 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003404 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003406 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407 } else {
3408 return TelephonyManager.DATA_ACTIVITY_NONE;
3409 }
3410 } finally {
3411 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 }
3414
3415 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003416 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003417 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003418 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003419
3420 LocationAccessPolicy.LocationPermissionResult locationResult =
3421 LocationAccessPolicy.checkLocationPermission(mApp,
3422 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3423 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003424 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003425 .setCallingPid(Binder.getCallingPid())
3426 .setCallingUid(Binder.getCallingUid())
3427 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003428 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003429 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3430 .build());
3431 switch (locationResult) {
3432 case DENIED_HARD:
3433 throw new SecurityException("Not allowed to access cell location");
3434 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003435 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3436 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003437 }
3438
joonhunshin4ac60942023-11-15 15:23:39 +00003439 enforceTelephonyFeatureWithException(callingPackage,
3440 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3441
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003442 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443 final long identity = Binder.clearCallingIdentity();
3444 try {
3445 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003446 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003447 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
Svetoslav64fad262015-04-14 14:35:21 -07003451 }
3452
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003453 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003454 public String getNetworkCountryIsoForPhone(int phoneId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003455 if (!mApp.getResources().getBoolean(
3456 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3457 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3458 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3459 }
joonhunshin4ac60942023-11-15 15:23:39 +00003460
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003461 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3462 // registered cell info, so return a NULL country instead.
3463 final long identity = Binder.clearCallingIdentity();
3464 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003465 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3466 // Get default phone in this case.
3467 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3468 }
Jack Yu285100e2022-12-02 22:48:35 -08003469 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003470 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003471 if (phone == null) return "";
3472 ServiceStateTracker sst = phone.getServiceStateTracker();
3473 if (sst == null) return "";
3474 LocaleTracker lt = sst.getLocaleTracker();
3475 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003476 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003477 } finally {
3478 Binder.restoreCallingIdentity(identity);
3479 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003480 }
3481
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003482 /**
3483 * This method was removed due to potential issues caused by performing partial
3484 * updates of service state, and lack of a credible use case.
3485 *
3486 * This has the ability to break the telephony implementation by disabling notification of
3487 * changes in device connectivity. DO NOT USE THIS!
3488 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003489 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003490 public void enableLocationUpdates() {
3491 mApp.enforceCallingOrSelfPermission(
3492 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003493 }
3494
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003495 /**
3496 * This method was removed due to potential issues caused by performing partial
3497 * updates of service state, and lack of a credible use case.
3498 *
3499 * This has the ability to break the telephony implementation by disabling notification of
3500 * changes in device connectivity. DO NOT USE THIS!
3501 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003502 @Override
3503 public void disableLocationUpdates() {
3504 mApp.enforceCallingOrSelfPermission(
3505 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003506 }
3507
3508 @Override
3509 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003510 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3511 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003512 try {
3513 mApp.getSystemService(AppOpsManager.class)
3514 .checkPackage(Binder.getCallingUid(), callingPackage);
3515 } catch (SecurityException e) {
3516 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3517 throw e;
3518 }
3519
Nathan Haroldf096d982020-11-18 17:18:06 -08003520 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003521 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3522 throw new SecurityException(
3523 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3524 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003525
Jordan Liu1617b712019-07-10 15:06:26 -07003526 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003527 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3528 return null;
3529 }
Svetoslav64fad262015-04-14 14:35:21 -07003530
joonhunshin4ac60942023-11-15 15:23:39 +00003531 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3532 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3533
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003534 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003535
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003536 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003537 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003538
Nathan Haroldf180aac2018-06-01 18:43:55 -07003539 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3540 for (CellInfo ci : info) {
3541 if (ci instanceof CellInfoGsm) {
3542 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3543 } else if (ci instanceof CellInfoWcdma) {
3544 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003546 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003547 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003548 }
3549
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003550 private List<CellInfo> getCachedCellInfo() {
3551 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3552 for (Phone phone : PhoneFactory.getPhones()) {
3553 List<CellInfo> info = phone.getAllCellInfo();
3554 if (info != null) cellInfos.addAll(info);
3555 }
3556 return cellInfos;
3557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003558
3559 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003560 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003561 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003562 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003563
3564 LocationAccessPolicy.LocationPermissionResult locationResult =
3565 LocationAccessPolicy.checkLocationPermission(mApp,
3566 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3567 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003568 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003569 .setCallingPid(Binder.getCallingPid())
3570 .setCallingUid(Binder.getCallingUid())
3571 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003572 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003573 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3574 .build());
3575 switch (locationResult) {
3576 case DENIED_HARD:
3577 throw new SecurityException("Not allowed to access cell info");
3578 case DENIED_SOFT:
3579 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003580 }
3581
Nathan Haroldf096d982020-11-18 17:18:06 -08003582 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003583 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3584 return getCachedCellInfo();
3585 }
3586
joonhunshin4ac60942023-11-15 15:23:39 +00003587 enforceTelephonyFeatureWithException(callingPackage,
3588 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3589
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003590 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003591 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3595 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003596 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003597 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598 if (info != null) cellInfos.addAll(info);
3599 }
3600 return cellInfos;
3601 } finally {
3602 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003603 }
3604 }
3605
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003606 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003607 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3608 String callingFeatureId) {
3609 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3610 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003611 }
3612
3613 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003614 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3615 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003616 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003617 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003618 }
3619
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003620 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3621 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003622 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003623 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003624
3625 LocationAccessPolicy.LocationPermissionResult locationResult =
3626 LocationAccessPolicy.checkLocationPermission(mApp,
3627 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3628 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003629 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003630 .setCallingPid(Binder.getCallingPid())
3631 .setCallingUid(Binder.getCallingUid())
3632 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003633 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3634 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003635 .build());
3636 switch (locationResult) {
3637 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003638 if (TelephonyPermissions
3639 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003640 // Safetynet logging for b/154934934
3641 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3642 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003643 throw new SecurityException("Not allowed to access cell info");
3644 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003645 if (TelephonyPermissions
3646 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003647 // Safetynet logging for b/154934934
3648 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3649 }
Nathan Harold5320c422019-05-09 10:26:08 -07003650 try {
3651 cb.onCellInfo(new ArrayList<CellInfo>());
3652 } catch (RemoteException re) {
3653 // Drop without consequences
3654 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003655 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003656 }
3657
joonhunshin4ac60942023-11-15 15:23:39 +00003658 enforceTelephonyFeatureWithException(callingPackage,
3659 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003660
3661 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003662 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3663
3664 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3665 }
3666
3667 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003668 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003669 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003670 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003671
3672 final long identity = Binder.clearCallingIdentity();
3673 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003674 Phone phone = getPhone(subId);
3675 if (phone == null) {
3676 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3677 } else {
3678 phone.setCellInfoListRate(rateInMillis, workSource);
3679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003683 }
3684
Shishir Agrawala9f32182016-04-12 12:00:16 -07003685 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003686 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003687 Phone phone = PhoneFactory.getPhone(slotIndex);
3688 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003689 return null;
3690 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003691 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003692 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003693 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003694 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003695 return null;
3696 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003697
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 return phone.getImei();
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003704 }
3705
3706 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003707 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3708 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3709 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3710 callingFeatureId, "getPrimaryImei")) {
3711 throw new SecurityException("Caller does not have permission");
3712 }
joonhunshin4ac60942023-11-15 15:23:39 +00003713
arunvoddud5c6ce02022-12-11 06:03:12 +00003714 final long identity = Binder.clearCallingIdentity();
3715 try {
3716 for (Phone phone : PhoneFactory.getPhones()) {
3717 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3718 return phone.getImei();
3719 }
3720 }
3721 throw new UnsupportedOperationException("Operation not supported");
3722 } finally {
3723 Binder.restoreCallingIdentity(identity);
3724 }
3725 }
3726
3727 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003728 public String getTypeAllocationCodeForSlot(int slotIndex) {
3729 Phone phone = PhoneFactory.getPhone(slotIndex);
3730 String tac = null;
3731 if (phone != null) {
3732 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003733 try {
3734 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3735 } catch (IndexOutOfBoundsException e) {
3736 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3737 return null;
3738 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003739 }
3740 return tac;
3741 }
3742
3743 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003744 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08003745 if (mFeatureFlags.cleanupCdma()) return null;
3746
Shuo Qian13d89152021-05-10 23:58:11 -07003747 try {
3748 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3749 } catch (SecurityException se) {
3750 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3751 throw new SecurityException("Package " + callingPackage + " does not belong to "
3752 + Binder.getCallingUid());
3753 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003754 Phone phone = PhoneFactory.getPhone(slotIndex);
3755 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003756 return null;
3757 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003758
Jeff Davidson913390f2018-02-23 17:11:49 -08003759 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003760 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003761 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003762 return null;
3763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003764
joonhunshin4ac60942023-11-15 15:23:39 +00003765 enforceTelephonyFeatureWithException(callingPackage,
3766 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 return phone.getMeid();
3771 } finally {
3772 Binder.restoreCallingIdentity(identity);
3773 }
Jack Yu2af8d712017-03-15 17:14:14 -07003774 }
3775
3776 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003777 public String getManufacturerCodeForSlot(int slotIndex) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08003778 if (mFeatureFlags.cleanupCdma()) return null;
3779
joonhunshin4ac60942023-11-15 15:23:39 +00003780 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3781 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3782
David Kelly5e06a7f2018-03-12 14:10:59 +00003783 Phone phone = PhoneFactory.getPhone(slotIndex);
3784 String manufacturerCode = null;
3785 if (phone != null) {
3786 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003787 try {
3788 manufacturerCode =
3789 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3790 } catch (IndexOutOfBoundsException e) {
3791 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3792 return null;
3793 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003794 }
3795 return manufacturerCode;
3796 }
3797
3798 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003799 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3800 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003801 Phone phone = PhoneFactory.getPhone(slotIndex);
3802 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003803 return null;
3804 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003805 int subId = phone.getSubId();
3806 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003807 mApp, subId, callingPackage, callingFeatureId,
3808 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003809 return null;
3810 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811
joonhunshin4ac60942023-11-15 15:23:39 +00003812 enforceTelephonyFeatureWithException(callingPackage,
3813 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003815 final long identity = Binder.clearCallingIdentity();
3816 try {
3817 return phone.getDeviceSvn();
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003821 }
3822
fionaxu43304da2017-11-27 22:51:16 -08003823 @Override
3824 public int getSubscriptionCarrierId(int subId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003825 if (!mApp.getResources().getBoolean(
3826 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3827 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3828 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3829 }
joonhunshin4ac60942023-11-15 15:23:39 +00003830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 final Phone phone = getPhone(subId);
3834 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
3837 }
fionaxu43304da2017-11-27 22:51:16 -08003838 }
3839
3840 @Override
3841 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003842 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3843 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3844
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003845 final long identity = Binder.clearCallingIdentity();
3846 try {
3847 final Phone phone = getPhone(subId);
3848 return phone == null ? null : phone.getCarrierName();
3849 } finally {
3850 Binder.restoreCallingIdentity(identity);
3851 }
fionaxu43304da2017-11-27 22:51:16 -08003852 }
3853
calvinpanffe225e2018-11-01 19:43:06 +08003854 @Override
chen xu0026ca62019-03-06 15:28:50 -08003855 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003856 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3857 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3858
chen xu25637222018-11-04 17:17:00 -08003859 final long identity = Binder.clearCallingIdentity();
3860 try {
3861 final Phone phone = getPhone(subId);
3862 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003863 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003864 } finally {
3865 Binder.restoreCallingIdentity(identity);
3866 }
3867 }
3868
3869 @Override
chen xu0026ca62019-03-06 15:28:50 -08003870 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003871 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3872 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3873 "getSubscriptionSpecificCarrierName");
3874
chen xu25637222018-11-04 17:17:00 -08003875 final long identity = Binder.clearCallingIdentity();
3876 try {
3877 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003878 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003879 } finally {
3880 Binder.restoreCallingIdentity(identity);
3881 }
3882 }
3883
chen xu651eec72018-11-11 19:03:44 -08003884 @Override
chen xu864e11c2018-12-06 22:10:03 -08003885 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3886 if (!isSubscriptionMccMnc) {
3887 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3888 }
chen xu651eec72018-11-11 19:03:44 -08003889 final Phone phone = PhoneFactory.getPhone(slotIndex);
3890 if (phone == null) {
3891 return TelephonyManager.UNKNOWN_CARRIER_ID;
3892 }
joonhunshin4ac60942023-11-15 15:23:39 +00003893
3894 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3895 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3896
chen xu651eec72018-11-11 19:03:44 -08003897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3900 } finally {
3901 Binder.restoreCallingIdentity(identity);
3902 }
3903 }
3904
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003905 //
3906 // Internal helper methods.
3907 //
3908
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003909 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003910 * Make sure the caller is the calling package itself
3911 *
3912 * @throws SecurityException if the caller is not the calling package
3913 */
3914 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3915 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003916 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3917 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003918 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003919 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003920 } catch (PackageManager.NameNotFoundException e) {
3921 // packageUid is -1
3922 }
3923 if (packageUid != callingUid) {
3924 throw new SecurityException(message + ": Package " + callingPackage
3925 + " does not belong to " + callingUid);
3926 }
3927 }
3928
3929 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003930 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3931 *
3932 * @throws SecurityException if the caller does not have the required permission
3933 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003934 @VisibleForTesting
3935 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003936 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3937 }
3938
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003939 /**
arunvoddud7401012022-12-15 16:08:12 +00003940 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003941 *
3942 * @throws SecurityException if the caller does not have the required permission
3943 */
3944 @VisibleForTesting
3945 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003946 enforceReadPermission(null);
3947 }
3948
3949 /**
3950 * Make sure the caller has the READ_PHONE_STATE permissions.
3951 *
3952 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3953 */
3954 @VisibleForTesting
3955 public void enforceReadPermission(String msg) {
3956 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003957 }
3958
Shuo Qian3b6ee772019-11-13 17:43:31 -08003959 private void enforceActiveEmergencySessionPermission() {
3960 mApp.enforceCallingOrSelfPermission(
3961 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3962 }
3963
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003964 /**
3965 * Make sure the caller has the CALL_PHONE permission.
3966 *
3967 * @throws SecurityException if the caller does not have the required permission
3968 */
3969 private void enforceCallPermission() {
3970 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3971 }
3972
paulhu5a773602019-08-23 19:17:33 +08003973 private void enforceSettingsPermission() {
3974 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003975 }
3976
Michele Berionne5e411512020-11-13 02:36:59 +00003977 private void enforceRebootPermission() {
3978 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3979 }
3980
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003981 /**
3982 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3983 * @param message - log message to print.
3984 * @throws SecurityException if the caller does not have the required permission
3985 */
3986 private void enforceSatelliteCommunicationPermission(String message) {
3987 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3988 }
3989
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003990 /**
3991 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3992 * @param message - log message to print.
3993 * @throws SecurityException if the caller does not have the required permission
3994 */
3995 private void enforcePackageUsageStatsPermission(String message) {
3996 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3997 }
3998
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003999 private String createTelUrl(String number) {
4000 if (TextUtils.isEmpty(number)) {
4001 return null;
4002 }
4003
Jake Hambye994d462014-02-03 13:10:13 -08004004 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004005 }
4006
Ihab Awadf9e92732013-12-05 18:02:52 -08004007 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08004008 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004009 }
4010
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004011 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004012 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004013 }
4014
Ihab Awadf9e92732013-12-05 18:02:52 -08004015 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004016 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004017 }
4018
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004019 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004020 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004021 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004022 }
4023
Sanket Padawe356d7632015-06-22 14:03:32 -07004024 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004025 public int getActivePhoneTypeForSlot(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07004026 if (!mApp.getResources().getBoolean(
4027 com.android.internal.R.bool.config_force_phone_globals_creation)) {
4028 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4029 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4030 }
joonhunshin4ac60942023-11-15 15:23:39 +00004031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 final Phone phone = PhoneFactory.getPhone(slotIndex);
4035 if (phone == null) {
4036 return PhoneConstants.PHONE_TYPE_NONE;
4037 } else {
4038 return phone.getPhoneType();
4039 }
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004042 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004043 }
4044
4045 /**
4046 * Returns the CDMA ERI icon index to display
4047 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004048 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004049 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08004050 if (mFeatureFlags.cleanupCdma()) return -1;
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004051 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4052 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004053 }
4054
Sanket Padawe356d7632015-06-22 14:03:32 -07004055 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004056 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4057 String callingFeatureId) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08004058 if (mFeatureFlags.cleanupCdma()) return -1;
4059
Jeff Davidson7e17e312018-02-13 18:17:36 -08004060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004061 mApp, subId, callingPackage, callingFeatureId,
4062 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004063 return -1;
4064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004065
joonhunshin4ac60942023-11-15 15:23:39 +00004066 enforceTelephonyFeatureWithException(callingPackage,
4067 PackageManager.FEATURE_TELEPHONY_CDMA,
4068 "getCdmaEriIconIndexForSubscriber");
4069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 final Phone phone = getPhone(subId);
4073 if (phone != null) {
4074 return phone.getCdmaEriIconIndex();
4075 } else {
4076 return -1;
4077 }
4078 } finally {
4079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004081 }
4082
4083 /**
4084 * Returns the CDMA ERI icon mode,
4085 * 0 - ON
4086 * 1 - FLASHING
4087 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004088 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004089 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08004090 if (mFeatureFlags.cleanupCdma()) return -1;
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004091 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4092 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004093 }
4094
Sanket Padawe356d7632015-06-22 14:03:32 -07004095 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004096 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4097 String callingFeatureId) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08004098 if (mFeatureFlags.cleanupCdma()) return -1;
4099
Jeff Davidson7e17e312018-02-13 18:17:36 -08004100 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004101 mApp, subId, callingPackage, callingFeatureId,
4102 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004103 return -1;
4104 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105
4106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 final Phone phone = getPhone(subId);
4109 if (phone != null) {
4110 return phone.getCdmaEriIconMode();
4111 } else {
4112 return -1;
4113 }
4114 } finally {
4115 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004117 }
4118
4119 /**
4120 * Returns the CDMA ERI text,
4121 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004122 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004123 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08004124 if (mFeatureFlags.cleanupCdma()) return null;
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004125 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4126 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004127 }
4128
Sanket Padawe356d7632015-06-22 14:03:32 -07004129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004130 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4131 String callingFeatureId) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08004132 if (mFeatureFlags.cleanupCdma()) return null;
4133
Jeff Davidson7e17e312018-02-13 18:17:36 -08004134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004135 mApp, subId, callingPackage, callingFeatureId,
4136 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004137 return null;
4138 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004139
4140 final long identity = Binder.clearCallingIdentity();
4141 try {
4142 final Phone phone = getPhone(subId);
4143 if (phone != null) {
4144 return phone.getCdmaEriText();
4145 } else {
4146 return null;
4147 }
4148 } finally {
4149 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004151 }
4152
4153 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004154 * Returns the CDMA MDN.
4155 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004156 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004157 public String getCdmaMdn(int subId) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08004158 if (mFeatureFlags.cleanupCdma()) return null;
4159
Jeff Davidson7e17e312018-02-13 18:17:36 -08004160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4161 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162
joonhunshin4ac60942023-11-15 15:23:39 +00004163 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4164 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004169 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004170 return phone.getLine1Number();
4171 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004172 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004173 return null;
4174 }
4175 } finally {
4176 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004177 }
4178 }
4179
4180 /**
4181 * Returns the CDMA MIN.
4182 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004183 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004184 public String getCdmaMin(int subId) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08004185 if (mFeatureFlags.cleanupCdma()) return null;
4186
Jeff Davidson7e17e312018-02-13 18:17:36 -08004187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4188 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004189
joonhunshin4ac60942023-11-15 15:23:39 +00004190 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4191 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 final Phone phone = getPhone(subId);
4196 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4197 return phone.getCdmaMin();
4198 } else {
4199 return null;
4200 }
4201 } finally {
4202 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004203 }
4204 }
4205
Hall Liud892bec2018-11-30 14:51:45 -08004206 @Override
4207 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4208 INumberVerificationCallback callback, String callingPackage) {
4209 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4210 != PERMISSION_GRANTED) {
4211 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4212 }
4213 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4214
4215 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4216 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004217 throw new SecurityException("Calling package must be configured in the device config: "
4218 + "calling package: " + callingPackage
4219 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004220 }
4221
joonhunshin4ac60942023-11-15 15:23:39 +00004222 enforceTelephonyFeatureWithException(callingPackage,
4223 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4224
Hall Liud892bec2018-11-30 14:51:45 -08004225 if (range == null) {
4226 throw new NullPointerException("Range must be non-null");
4227 }
4228
4229 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004230 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004231
4232 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4233 }
4234
Junda Liuca05d5d2014-08-14 22:36:34 -07004235 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004236 * Returns true if CDMA provisioning needs to run.
4237 */
4238 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004239 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4240 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 final long identity = Binder.clearCallingIdentity();
4243 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004244 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004248 }
4249
4250 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004251 * Sets the voice mail number of a given subId.
4252 */
4253 @Override
4254 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004255 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4256 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257
joonhunshin4ac60942023-11-15 15:23:39 +00004258 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4259 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
Nathan Harolddc3bcec2024-05-16 14:06:40 -07004263 Boolean success = (Boolean) sendRequest(
4264 CMD_SET_VOICEMAIL_NUMBER,
4265 new Pair<String, String>(alphaTag, number),
4266 new Integer(subId),
4267 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
4268 if (success == null) return false; // most likely due to a timeout
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004269 return success;
4270 } finally {
4271 Binder.restoreCallingIdentity(identity);
4272 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004273 }
4274
Ta-wei Yen87c49842016-05-13 21:19:52 -07004275 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004276 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4277 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004278 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4279 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004280 if (!TextUtils.equals(callingPackage, systemDialer)) {
4281 throw new SecurityException("caller must be system dialer");
4282 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283
joonhunshin4ac60942023-11-15 15:23:39 +00004284 enforceTelephonyFeatureWithException(callingPackage,
4285 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287 final long identity = Binder.clearCallingIdentity();
4288 try {
4289 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4290 if (phoneAccountHandle == null) {
4291 return null;
4292 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004293 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004294 } finally {
4295 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004296 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004297 }
4298
4299 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004300 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4301 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004302 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004304 mApp, subId, callingPackage, callingFeatureId,
4305 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004306 return null;
4307 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308
joonhunshin4ac60942023-11-15 15:23:39 +00004309 enforceTelephonyFeatureWithException(callingPackage,
4310 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4311
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004312 final long identity = Binder.clearCallingIdentity();
4313 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004314 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004318 }
4319
4320 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004321 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4322 VisualVoicemailSmsFilterSettings settings) {
4323 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004324 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004325 enforceTelephonyFeatureWithException(callingPackage,
4326 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004330 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331 } finally {
4332 Binder.restoreCallingIdentity(identity);
4333 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004334 }
4335
4336 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004337 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4338 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004339 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004340 enforceTelephonyFeatureWithException(callingPackage,
4341 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 final long identity = Binder.clearCallingIdentity();
4344 try {
4345 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004346 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004347 } finally {
4348 Binder.restoreCallingIdentity(identity);
4349 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004350 }
4351
4352 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004353 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4354 String callingPackage, int subId) {
4355 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356
4357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004360 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361 } finally {
4362 Binder.restoreCallingIdentity(identity);
4363 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004364 }
4365
4366 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004367 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004369
4370 final long identity = Binder.clearCallingIdentity();
4371 try {
4372 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004373 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004374 } finally {
4375 Binder.restoreCallingIdentity(identity);
4376 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004377 }
4378
4379 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004380 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4381 String callingAttributionTag, int subId, String number, int port, String text,
4382 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004383 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004384 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004385 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004386
4387 enforceTelephonyFeatureWithException(callingPackage,
4388 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4389
Amit Mahajandccb3f12019-05-13 13:48:32 -07004390 SmsController smsController = PhoneFactory.getSmsController();
Nikhil Kumardeebd752024-08-14 14:49:06 +01004391 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage,
4392 Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number,
4393 port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004394 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004395
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004396 /**
fionaxu0152e512016-11-14 13:36:14 -08004397 * Sets the voice activation state of a given subId.
4398 */
4399 @Override
4400 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4402 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403
joonhunshin4ac60942023-11-15 15:23:39 +00004404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4405 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 final long identity = Binder.clearCallingIdentity();
4408 try {
4409 final Phone phone = getPhone(subId);
4410 if (phone != null) {
4411 phone.setVoiceActivationState(activationState);
4412 } else {
4413 loge("setVoiceActivationState fails with invalid subId: " + subId);
4414 }
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004417 }
4418 }
4419
4420 /**
4421 * Sets the data activation state of a given subId.
4422 */
4423 @Override
4424 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4426 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427
joonhunshin4ac60942023-11-15 15:23:39 +00004428 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4429 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4430
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431 final long identity = Binder.clearCallingIdentity();
4432 try {
4433 final Phone phone = getPhone(subId);
4434 if (phone != null) {
4435 phone.setDataActivationState(activationState);
4436 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004437 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004438 }
4439 } finally {
4440 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004441 }
4442 }
4443
4444 /**
4445 * Returns the voice activation state of a given subId.
4446 */
4447 @Override
4448 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450
joonhunshin4ac60942023-11-15 15:23:39 +00004451 enforceTelephonyFeatureWithException(callingPackage,
4452 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4453
fionaxu0152e512016-11-14 13:36:14 -08004454 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 final long identity = Binder.clearCallingIdentity();
4456 try {
4457 if (phone != null) {
4458 return phone.getVoiceActivationState();
4459 } else {
4460 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4461 }
4462 } finally {
4463 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004464 }
4465 }
4466
4467 /**
4468 * Returns the data activation state of a given subId.
4469 */
4470 @Override
4471 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004472 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004473
joonhunshin4ac60942023-11-15 15:23:39 +00004474 enforceTelephonyFeatureWithException(callingPackage,
4475 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4476
fionaxu0152e512016-11-14 13:36:14 -08004477 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 final long identity = Binder.clearCallingIdentity();
4479 try {
4480 if (phone != null) {
4481 return phone.getDataActivationState();
4482 } else {
4483 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4484 }
4485 } finally {
4486 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004487 }
4488 }
4489
4490 /**
Wink Saville36469e72014-06-11 15:17:00 -07004491 * Returns the unread count of voicemails for a subId
4492 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004493 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004494 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4495 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004497 mApp, subId, callingPackage, callingFeatureId,
4498 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004499 return 0;
4500 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501 final long identity = Binder.clearCallingIdentity();
4502 try {
4503 final Phone phone = getPhone(subId);
4504 if (phone != null) {
4505 return phone.getVoiceMessageCount();
4506 } else {
4507 return 0;
4508 }
4509 } finally {
4510 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004512 }
4513
4514 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004515 * returns true, if the device is in a state where both voice and data
4516 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004517 */
4518 @Override
4519 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004520 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4521 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004523 final long identity = Binder.clearCallingIdentity();
4524 try {
Ling Mac28f0212023-03-24 16:07:15 -07004525 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004529 }
4530
4531 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004532 * Send the dialer code if called from the current default dialer or the caller has
4533 * carrier privilege.
4534 * @param inputCode The dialer code to send
4535 */
4536 @Override
4537 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004538 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004539 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004540 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4541 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004542 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004543 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004544 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004545 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004546
joonhunshin4ac60942023-11-15 15:23:39 +00004547 enforceTelephonyFeatureWithException(callingPackage,
4548 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550 final long identity = Binder.clearCallingIdentity();
4551 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004552 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 } finally {
4554 Binder.restoreCallingIdentity(identity);
4555 }
fionaxu235cc5e2017-03-06 22:25:57 -08004556 }
4557
Pengquan Menga1bb6272018-09-06 09:59:22 -07004558 @Override
4559 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004560 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004561 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4562 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004563
4564 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4565 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4566
shilufc958392020-01-20 11:36:01 -08004567 final long identity = Binder.clearCallingIdentity();
4568 try {
4569 if (!isActiveSubscription(subId)) {
4570 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4571 }
4572 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4573 } finally {
4574 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004575 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004576 }
4577
Brad Ebinger35c841c2018-10-01 10:40:55 -07004578 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004579 public boolean isInEmergencySmsMode() {
4580 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004581
4582 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4583 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4584
Brad Ebingerb2b65522019-03-15 13:48:47 -07004585 final long identity = Binder.clearCallingIdentity();
4586 try {
4587 for (Phone phone : PhoneFactory.getPhones()) {
4588 if (phone.isInEmergencySmsMode()) {
4589 return true;
4590 }
4591 }
4592 } finally {
4593 Binder.restoreCallingIdentity(identity);
4594 }
4595 return false;
4596 }
4597
shilu366312e2019-12-17 09:28:10 -08004598 /**
4599 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4600 * @param subId The subscription to use to check the configuration.
4601 * @param c The callback that will be used to send the result.
4602 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004603 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004604 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4605 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004606 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004607 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004608
4609 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4610 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4611 "IMS not available on device.");
4612 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004613 final long token = Binder.clearCallingIdentity();
4614 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004615 int slotId = getSlotIndexOrException(subId);
4616 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004617
4618 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4619 if (controller != null) {
4620 ImsManager imsManager = controller.getImsManager(subId);
4621 if (imsManager != null) {
4622 imsManager.addRegistrationCallbackForSubscription(c, subId);
4623 } else {
4624 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4625 }
4626 } else {
4627 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4628 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004629 } catch (ImsException e) {
4630 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004631 } finally {
4632 Binder.restoreCallingIdentity(token);
4633 }
4634 }
4635
shilu366312e2019-12-17 09:28:10 -08004636 /**
4637 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4638 * @param subId The subscription to use to check the configuration.
4639 * @param c The callback that will be used to send the result.
4640 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004641 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004642 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004643 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004644 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004645 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4646 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4647 }
Meng Wangafbc5852019-09-19 17:37:13 -07004648 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004649
Meng Wangafbc5852019-09-19 17:37:13 -07004650 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004651 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4652 if (controller != null) {
4653 ImsManager imsManager = controller.getImsManager(subId);
4654 if (imsManager != null) {
4655 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4656 } else {
4657 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4658 + "is inactive, ignoring unregister.");
4659 // If the ImsManager is not valid, just return, since the callback
4660 // will already have been removed internally.
4661 }
4662 }
Meng Wangafbc5852019-09-19 17:37:13 -07004663 } finally {
4664 Binder.restoreCallingIdentity(token);
4665 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004666 }
4667
Brad Ebingera34a6c22019-10-22 17:36:18 -07004668 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004669 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4670 * @param subId The subscription to use to check the configuration.
4671 * @param c The callback that will be used to send the result.
4672 */
4673 @Override
4674 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4675 throws RemoteException {
4676 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4677 mApp, subId, "registerImsEmergencyRegistrationCallback");
4678
4679 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4680 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4681 "IMS not available on device.");
4682 }
4683 final long token = Binder.clearCallingIdentity();
4684 try {
4685 int slotId = getSlotIndexOrException(subId);
4686 verifyImsMmTelConfiguredOrThrow(slotId);
4687
4688 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4689 if (controller != null) {
4690 ImsManager imsManager = controller.getImsManager(subId);
4691 if (imsManager != null) {
4692 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4693 } else {
4694 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4695 }
4696 } else {
4697 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4698 }
4699 } catch (ImsException e) {
4700 throw new ServiceSpecificException(e.getCode());
4701 } finally {
4702 Binder.restoreCallingIdentity(token);
4703 }
4704 }
4705
4706 /**
4707 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4708 * @param subId The subscription to use to check the configuration.
4709 * @param c The callback that will be used to send the result.
4710 */
4711 @Override
4712 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4713 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4714 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4715 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4716 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4717 }
4718 final long token = Binder.clearCallingIdentity();
4719
4720 try {
4721 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4722 if (controller != null) {
4723 ImsManager imsManager = controller.getImsManager(subId);
4724 if (imsManager != null) {
4725 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4726 } else {
4727 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4728 + "is inactive, ignoring unregister.");
4729 // If the ImsManager is not valid, just return, since the callback
4730 // will already have been removed internally.
4731 }
4732 }
4733 } finally {
4734 Binder.restoreCallingIdentity(token);
4735 }
4736 }
4737
4738 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004739 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4740 */
4741 @Override
4742 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4743 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4744 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4745 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4746 "IMS not available on device.");
4747 }
4748 final long token = Binder.clearCallingIdentity();
4749 try {
4750 Phone phone = getPhone(subId);
4751 if (phone == null) {
4752 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4753 + subId + "'");
4754 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4755 }
4756 phone.getImsRegistrationState(regState -> {
4757 try {
4758 consumer.accept((regState == null)
4759 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4760 } catch (RemoteException e) {
4761 // Ignore if the remote process is no longer available to call back.
4762 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4763 }
4764 });
4765 } finally {
4766 Binder.restoreCallingIdentity(token);
4767 }
4768 }
4769
4770 /**
4771 * Get the transport type for the IMS service registration state.
4772 */
4773 @Override
4774 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004775 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004776 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004777 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4778 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4779 "IMS not available on device.");
4780 }
4781 final long token = Binder.clearCallingIdentity();
4782 try {
4783 Phone phone = getPhone(subId);
4784 if (phone == null) {
4785 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4786 + subId + "'");
4787 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4788 }
4789 phone.getImsRegistrationTech(regTech -> {
4790 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4791 int regTechConverted = (regTech == null)
4792 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4793 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4794 regTechConverted);
4795 try {
4796 consumer.accept(regTechConverted);
4797 } catch (RemoteException e) {
4798 // Ignore if the remote process is no longer available to call back.
4799 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4800 }
4801 });
4802 } finally {
4803 Binder.restoreCallingIdentity(token);
4804 }
4805 }
4806
shilu366312e2019-12-17 09:28:10 -08004807 /**
4808 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4809 * @param subId The subscription to use to check the configuration.
4810 * @param c The callback that will be used to send the result.
4811 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004812 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004813 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4814 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004815 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004816 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004817 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4818 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4819 "IMS not available on device.");
4820 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004821 final long token = Binder.clearCallingIdentity();
4822 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004823 int slotId = getSlotIndexOrException(subId);
4824 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004825
4826 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4827 if (controller != null) {
4828 ImsManager imsManager = controller.getImsManager(subId);
4829 if (imsManager != null) {
4830 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4831 } else {
4832 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4833 }
4834 } else {
4835 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4836 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004837 } catch (ImsException e) {
4838 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004839 } finally {
4840 Binder.restoreCallingIdentity(token);
4841 }
4842 }
4843
shilu366312e2019-12-17 09:28:10 -08004844 /**
4845 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4846 * @param subId The subscription to use to check the configuration.
4847 * @param c The callback that will be used to send the result.
4848 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004849 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004850 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004851 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004852 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004853 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4854 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4855 }
Meng Wangafbc5852019-09-19 17:37:13 -07004856
4857 final long token = Binder.clearCallingIdentity();
4858 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004859 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4860 if (controller != null) {
4861 ImsManager imsManager = controller.getImsManager(subId);
4862 if (imsManager != null) {
4863 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4864 } else {
4865 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4866 + " is inactive, ignoring unregister.");
4867 // If the ImsManager is not valid, just return, since the callback
4868 // will already have been removed internally.
4869 }
4870 }
Meng Wangafbc5852019-09-19 17:37:13 -07004871 } finally {
4872 Binder.restoreCallingIdentity(token);
4873 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004874 }
4875
4876 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004877 public boolean isCapable(int subId, int capability, int regTech) {
4878 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004879
4880 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4881 FEATURE_TELEPHONY_IMS, "isCapable");
4882
Brad Ebinger35c841c2018-10-01 10:40:55 -07004883 final long token = Binder.clearCallingIdentity();
4884 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004885 int slotId = getSlotIndexOrException(subId);
4886 verifyImsMmTelConfiguredOrThrow(slotId);
4887 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4888 } catch (com.android.ims.ImsException e) {
4889 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4890 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004891 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004892 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4893 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004894 } finally {
4895 Binder.restoreCallingIdentity(token);
4896 }
4897 }
4898
4899 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004900 public boolean isAvailable(int subId, int capability, int regTech) {
4901 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004902
4903 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4904 FEATURE_TELEPHONY_IMS, "isAvailable");
4905
Brad Ebinger35c841c2018-10-01 10:40:55 -07004906 final long token = Binder.clearCallingIdentity();
4907 try {
4908 Phone phone = getPhone(subId);
4909 if (phone == null) return false;
4910 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004911 } catch (com.android.ims.ImsException e) {
4912 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4913 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004914 } finally {
4915 Binder.restoreCallingIdentity(token);
4916 }
4917 }
4918
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004919 /**
4920 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4921 * subscription.
4922 * @param subId The subscription to use to check the configuration.
4923 * @param callback The callback that will be used to send the result.
4924 * @param capability The MmTelFeature capability that will be used to send the result.
4925 * @param transportType The transport type of the MmTelFeature capability.
4926 */
4927 @Override
4928 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4929 int transportType) {
4930 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004931 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4932 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4933 "IMS not available on device.");
4934 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004935 final long token = Binder.clearCallingIdentity();
4936 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004937 int slotId = getSlotIndex(subId);
4938 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4939 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4940 + subId + "'");
4941 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4942 }
4943 verifyImsMmTelConfiguredOrThrow(slotId);
4944 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4945 transportType, aBoolean -> {
4946 try {
4947 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4948 } catch (RemoteException e) {
4949 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4950 + "running. Ignore");
4951 }
4952 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004953 } catch (ImsException e) {
4954 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004955 } finally {
4956 Binder.restoreCallingIdentity(token);
4957 }
4958 }
4959
shilu366312e2019-12-17 09:28:10 -08004960 /**
4961 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4962 * @param subId The subscription to use to check the configuration.
4963 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004964 @Override
4965 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004966 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004967 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004968
joonhunshin4ac60942023-11-15 15:23:39 +00004969 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4970 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4971
Brad Ebinger35c841c2018-10-01 10:40:55 -07004972 final long token = Binder.clearCallingIdentity();
4973 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004974 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004975 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004976 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004977 } catch (ImsException e) {
4978 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004979 } finally {
4980 Binder.restoreCallingIdentity(token);
4981 }
4982 }
4983
4984 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004985 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004987 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004988
4989 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4990 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4991
Brad Ebinger35c841c2018-10-01 10:40:55 -07004992 final long identity = Binder.clearCallingIdentity();
4993 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004994 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004995 // This setting doesn't require an active ImsService connection, so do not verify. The
4996 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004997 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004998 } catch (ImsException e) {
4999 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005000 } finally {
5001 Binder.restoreCallingIdentity(identity);
5002 }
5003 }
5004
shilu366312e2019-12-17 09:28:10 -08005005 /**
5006 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5007 * @param subId The subscription to use to check the configuration.
5008 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005009 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005010 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005011 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005012 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005013
5014 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5015 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
5016
Brad Ebinger35c841c2018-10-01 10:40:55 -07005017 final long identity = Binder.clearCallingIdentity();
5018 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005019 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005020 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005021 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005022 } catch (ImsException e) {
5023 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
5026 }
5027 }
5028
5029 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005030 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005032 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005033
5034 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5035 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
5036
Brad Ebinger35c841c2018-10-01 10:40:55 -07005037 final long identity = Binder.clearCallingIdentity();
5038 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005039 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005040 // This setting doesn't require an active ImsService connection, so do not verify. The
5041 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005042 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005043 } catch (ImsException e) {
5044 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005045 } finally {
5046 Binder.restoreCallingIdentity(identity);
5047 }
5048 }
5049
shilu366312e2019-12-17 09:28:10 -08005050 /**
5051 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5052 * @param subId The subscription to use to check the configuration.
5053 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005054 @Override
5055 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005056 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005057 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005058
5059 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5060 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5061
Brad Ebinger35c841c2018-10-01 10:40:55 -07005062 final long identity = Binder.clearCallingIdentity();
5063 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005064 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005065 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005066 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005067 } catch (ImsException e) {
5068 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
5072 }
5073
5074 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005075 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005077 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005078
5079 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5080 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5081
Brad Ebinger35c841c2018-10-01 10:40:55 -07005082 final long identity = Binder.clearCallingIdentity();
5083 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005084 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005085 // This setting doesn't require an active ImsService connection, so do not verify. The
5086 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005087 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005088 } catch (ImsException e) {
5089 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005090 } finally {
5091 Binder.restoreCallingIdentity(identity);
5092 }
5093 }
5094
shilu366312e2019-12-17 09:28:10 -08005095 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005096 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5097 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5098 * @param subId The subscription to use to check the configuration.
5099 */
5100 @Override
5101 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005102 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005103 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005104
5105 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5106 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5107
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005108 final long identity = Binder.clearCallingIdentity();
5109 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005110 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005111 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005112 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
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 /**
5121 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5122 * Requires MODIFY_PHONE_STATE permission.
5123 * @param subId The subscription to use to check the configuration.
5124 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5125 * false otherwise
5126 */
5127 @Override
5128 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5130 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005131
5132 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5133 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5134
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005135 final long identity = Binder.clearCallingIdentity();
5136 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005137 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005138 // This setting doesn't require an active ImsService connection, so do not verify. The
5139 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005140 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005141 } catch (ImsException e) {
5142 throw new ServiceSpecificException(e.getCode());
5143 } finally {
5144 Binder.restoreCallingIdentity(identity);
5145 }
5146 }
5147
5148 /**
shilu366312e2019-12-17 09:28:10 -08005149 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5150 * @param subId The subscription to use to check the configuration.
5151 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005152 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005153
Brad Ebinger35c841c2018-10-01 10:40:55 -07005154 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005155 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005156 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005157
5158 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5159 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5160
Brad Ebinger35c841c2018-10-01 10:40:55 -07005161 final long identity = Binder.clearCallingIdentity();
5162 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005163 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005164 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005165 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005166 } catch (ImsException e) {
5167 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005168 } finally {
5169 Binder.restoreCallingIdentity(identity);
5170 }
5171 }
5172
5173 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005174 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005176 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005177
5178 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5179 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5180
Brad Ebinger35c841c2018-10-01 10:40:55 -07005181 final long identity = Binder.clearCallingIdentity();
5182 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005183 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005184 // This setting doesn't require an active ImsService connection, so do not verify. The
5185 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005186 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005187 } catch (ImsException e) {
5188 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
5192 }
5193
5194 @Override
5195 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5197 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005198
5199 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5200 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5201
Brad Ebinger35c841c2018-10-01 10:40:55 -07005202 final long identity = Binder.clearCallingIdentity();
5203 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005204 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005205 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005206 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005207 } catch (ImsException e) {
5208 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
5212 }
5213
shilu366312e2019-12-17 09:28:10 -08005214 /**
5215 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5216 * @param subId The subscription to use to check the configuration.
5217 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005218 @Override
5219 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005220 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005221 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005222
5223 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5224 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5225
Brad Ebinger35c841c2018-10-01 10:40:55 -07005226 final long identity = Binder.clearCallingIdentity();
5227 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005228 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005229 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005230 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005231 } catch (ImsException e) {
5232 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
5236 }
5237
5238 @Override
5239 public void setVoWiFiModeSetting(int subId, int mode) {
5240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5241 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005242
5243 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5244 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5245
Brad Ebinger35c841c2018-10-01 10:40:55 -07005246 final long identity = Binder.clearCallingIdentity();
5247 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005248 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005249 // This setting doesn't require an active ImsService connection, so do not verify. The
5250 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005251 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005252 } catch (ImsException e) {
5253 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005254 } finally {
5255 Binder.restoreCallingIdentity(identity);
5256 }
5257 }
5258
5259 @Override
5260 public int getVoWiFiRoamingModeSetting(int subId) {
5261 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005262
5263 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5264 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5265
Brad Ebinger35c841c2018-10-01 10:40:55 -07005266 final long identity = Binder.clearCallingIdentity();
5267 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005268 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005269 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005270 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005271 } catch (ImsException e) {
5272 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005273 } finally {
5274 Binder.restoreCallingIdentity(identity);
5275 }
5276 }
5277
5278 @Override
5279 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5281 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005282
5283 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5284 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5285
Brad Ebinger35c841c2018-10-01 10:40:55 -07005286 final long identity = Binder.clearCallingIdentity();
5287 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005288 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005289 // This setting doesn't require an active ImsService connection, so do not verify. The
5290 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005291 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005292 } catch (ImsException e) {
5293 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
5297 }
5298
5299 @Override
5300 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5302 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005303
5304 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5305 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5306
Brad Ebinger35c841c2018-10-01 10:40:55 -07005307 final long identity = Binder.clearCallingIdentity();
5308 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005309 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005310 // This setting doesn't require an active ImsService connection, so do not verify. The
5311 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005312 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005313 } catch (ImsException e) {
5314 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005315 } finally {
5316 Binder.restoreCallingIdentity(identity);
5317 }
5318 }
5319
shilu366312e2019-12-17 09:28:10 -08005320 /**
5321 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5322 * @param subId The subscription to use to check the configuration.
5323 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005324 @Override
5325 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005326 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005327 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005328
5329 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5330 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5331
Brad Ebinger35c841c2018-10-01 10:40:55 -07005332 final long identity = Binder.clearCallingIdentity();
5333 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005334 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005335 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005336 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005337 } catch (ImsException e) {
5338 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
5342 }
5343
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005344 @Override
5345 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5346 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005347
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005348 final long identity = Binder.clearCallingIdentity();
5349 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005350 if (!isImsAvailableOnDevice()) {
5351 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5352 "IMS not available on device.");
5353 }
5354 int slotId = getSlotIndexOrException(subId);
5355 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005356
5357 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5358 if (controller != null) {
5359 ImsManager imsManager = controller.getImsManager(subId);
5360 if (imsManager != null) {
5361 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5362 } else {
5363 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5364 }
5365 } else {
5366 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5367 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005368 } catch (ImsException e) {
5369 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005370 } finally {
5371 Binder.restoreCallingIdentity(identity);
5372 }
5373 }
5374
5375 @Override
5376 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5377 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005378
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005379 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005380 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5381 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5382 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005383 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005384 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5385 if (controller != null) {
5386 ImsManager imsManager = controller.getImsManager(subId);
5387 if (imsManager != null) {
5388 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5389 } else {
5390 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5391 + " is inactive, ignoring unregister.");
5392 // If the ImsManager is not valid, just return, since the callback will already
5393 // have been removed internally.
5394 }
5395 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
5399 }
5400
joonhunshincffb7fc2021-11-28 07:32:01 +00005401 @Override
5402 public void registerFeatureProvisioningChangedCallback(int subId,
5403 IFeatureProvisioningCallback callback) {
5404 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5405 mApp, subId, "registerFeatureProvisioningChangedCallback");
5406
5407 final long identity = Binder.clearCallingIdentity();
5408 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5409 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5410 }
5411
joonhunshin91bc1952022-04-29 08:47:15 +00005412 try {
5413 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5414 if (controller == null) {
5415 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5416 "Device does not support IMS");
5417 }
5418 controller.addFeatureProvisioningChangedCallback(subId, callback);
5419 } finally {
5420 Binder.restoreCallingIdentity(identity);
5421 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005422 }
5423
5424 @Override
5425 public void unregisterFeatureProvisioningChangedCallback(int subId,
5426 IFeatureProvisioningCallback callback) {
5427 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5428 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5429
5430 final long identity = Binder.clearCallingIdentity();
5431 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5432 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5433 }
5434
joonhunshin91bc1952022-04-29 08:47:15 +00005435 try {
5436 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5437 if (controller == null) {
5438 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5439 return;
5440 }
5441 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
5444 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005445 }
allenwtsu99c623b2020-01-03 18:24:23 +08005446
5447 private void checkModifyPhoneStatePermission(int subId, String message) {
5448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5449 message);
5450 }
5451
allenwtsu99c623b2020-01-03 18:24:23 +08005452 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005453 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005454 boolean isProvisioned) {
5455 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5456
joonhunshin4ac60942023-11-15 15:23:39 +00005457 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5458 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5459
allenwtsu99c623b2020-01-03 18:24:23 +08005460 final long identity = Binder.clearCallingIdentity();
5461 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005462 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5463 if (controller == null) {
5464 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5465 return;
5466 }
5467 controller.setRcsProvisioningStatusForCapability(
5468 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005469 } finally {
5470 Binder.restoreCallingIdentity(identity);
5471 }
allenwtsu99c623b2020-01-03 18:24:23 +08005472 }
5473
5474
5475 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005476 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5477 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5478 mApp, subId, "getRcsProvisioningStatusForCapability");
5479
joonhunshin4ac60942023-11-15 15:23:39 +00005480 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5481 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5482
allenwtsu99c623b2020-01-03 18:24:23 +08005483 final long identity = Binder.clearCallingIdentity();
5484 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005485 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5486 if (controller == null) {
5487 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5488
5489 // device does not support IMS, this method will return true always.
5490 return true;
5491 }
5492 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
5496 }
5497
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005498 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005499 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5500 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005501 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005502
joonhunshin4ac60942023-11-15 15:23:39 +00005503 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5504 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5505
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005506 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005507 final long identity = Binder.clearCallingIdentity();
5508 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005509 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5510 if (controller == null) {
5511 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5512 return;
5513 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005514 controller.setImsProvisioningStatusForCapability(displayPackageName,
joonhunshin91bc1952022-04-29 08:47:15 +00005515 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
5519 }
5520
5521 @Override
5522 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005523 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5524 mApp, subId, "getProvisioningStatusForCapability");
5525
joonhunshin4ac60942023-11-15 15:23:39 +00005526 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5527 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5528
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005529 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005530 final long identity = Binder.clearCallingIdentity();
5531 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005532 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5533 if (controller == null) {
5534 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005535
joonhunshin91bc1952022-04-29 08:47:15 +00005536 // device does not support IMS, this method will return true always.
5537 return true;
5538 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005539 return controller.getImsProvisioningStatusForCapability(displayPackageName,
5540 subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
5544 }
5545
5546 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005547 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5548 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5549 mApp, subId, "isProvisioningRequiredForCapability");
5550
joonhunshin4ac60942023-11-15 15:23:39 +00005551 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5552 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5553
joonhunshincffb7fc2021-11-28 07:32:01 +00005554 final long identity = Binder.clearCallingIdentity();
5555 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005556 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5557 if (controller == null) {
5558 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5559
5560 // device does not support IMS, this method will return false
5561 return false;
5562 }
5563 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005564 } finally {
5565 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005566 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005567 }
5568
5569 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005570 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5571 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5572 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005573
joonhunshin4ac60942023-11-15 15:23:39 +00005574 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5575 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5576
joonhunshincffb7fc2021-11-28 07:32:01 +00005577 final long identity = Binder.clearCallingIdentity();
5578 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005579 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5580 if (controller == null) {
5581 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5582
5583 // device does not support IMS, this method will return false
5584 return false;
5585 }
5586 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005590 }
5591
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005592 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005593 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005594 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5595 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5596 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005597 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5598 mApp, subId, "getImsProvisioningInt");
5599
joonhunshin4ac60942023-11-15 15:23:39 +00005600 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5601 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5602
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005603 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005604 final long identity = Binder.clearCallingIdentity();
5605 try {
5606 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005607 int slotId = getSlotIndex(subId);
5608 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5609 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5610 + subId + "' for key:" + key);
5611 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5612 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005613
joonhunshin91bc1952022-04-29 08:47:15 +00005614 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5615 if (controller == null) {
5616 loge("getImsProvisioningInt: Device does not support IMS");
5617
5618 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5619 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5620 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005621 int retVal = controller.getProvisioningValue(displayPackageName, subId,
5622 key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005623 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5624 return retVal;
5625 }
5626
calvinpanb5a34062021-02-08 19:59:36 +08005627 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005628 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005629 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5630 + subId + "' for key:" + key);
5631 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005632 } finally {
5633 Binder.restoreCallingIdentity(identity);
5634 }
5635 }
5636
5637 @Override
5638 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005639 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5640 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5641 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005642 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5643 mApp, subId, "getImsProvisioningString");
5644
joonhunshin4ac60942023-11-15 15:23:39 +00005645 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5646 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5647
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005648 final long identity = Binder.clearCallingIdentity();
5649 try {
5650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005651 int slotId = getSlotIndex(subId);
5652 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5653 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5654 + subId + "' for key:" + key);
5655 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5656 }
calvinpanb5a34062021-02-08 19:59:36 +08005657 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005658 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005659 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5660 + subId + "' for key:" + key);
5661 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005662 } finally {
5663 Binder.restoreCallingIdentity(identity);
5664 }
5665 }
5666
5667 @Override
5668 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5670 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5671 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5673 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005674
joonhunshin4ac60942023-11-15 15:23:39 +00005675 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5676 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5677
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005678 String displayPackageName = getCurrentPackageNameOrPhone();
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005679 final long identity = Binder.clearCallingIdentity();
5680 try {
5681 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005682 int slotId = getSlotIndex(subId);
5683 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5684 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5685 + subId + "' for key:" + key);
5686 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5687 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005688
joonhunshin91bc1952022-04-29 08:47:15 +00005689 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5690 if (controller == null) {
5691 loge("setImsProvisioningInt: Device does not support IMS");
5692
5693 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5694 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5695 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -07005696 int retVal = controller.setProvisioningValue(displayPackageName, subId, key,
5697 value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005698 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5699 return retVal;
5700 }
5701
calvinpanb5a34062021-02-08 19:59:36 +08005702 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5703 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005704 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005705 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005706 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005707 } finally {
5708 Binder.restoreCallingIdentity(identity);
5709 }
5710 }
5711
5712 @Override
5713 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005714 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5715 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5716 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5718 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005719
5720 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5721 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5722
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005723 final long identity = Binder.clearCallingIdentity();
5724 try {
5725 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005726 int slotId = getSlotIndex(subId);
5727 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5728 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5729 + subId + "' for key:" + key);
5730 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5731 }
calvinpanb5a34062021-02-08 19:59:36 +08005732 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5733 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005734 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005735 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005736 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
5740 }
5741
Brad Ebinger919631e2021-06-02 17:46:35 -07005742 /**
5743 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5744 * for the given slot ID or no ImsResolver instance has been created.
5745 * @param slotId The slot ID that the IMS service is created for.
5746 * @throws ImsException If there is no ImsService configured for this slot.
5747 */
5748 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5749 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5750 ImsFeature.FEATURE_MMTEL)) {
5751 throw new ImsException("This subscription does not support MMTEL over IMS",
5752 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5753 }
5754 }
5755
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005756 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005757 int slotId = SubscriptionManager.getSlotIndex(subId);
5758 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005759 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5760 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005761 }
5762 return slotId;
5763 }
5764
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005765 private int getSlotIndex(int subId) {
5766 int slotId = SubscriptionManager.getSlotIndex(subId);
5767 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5768 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5769 }
5770 return slotId;
5771 }
5772
Wink Saville36469e72014-06-11 15:17:00 -07005773 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005774 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005775 */
5776 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005777 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5778 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005779 try {
5780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5781 } catch (SecurityException se) {
5782 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5783 throw new SecurityException("Package " + callingPackage + " does not belong to "
5784 + Binder.getCallingUid());
5785 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005786 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005787 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005788 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005789 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005790 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005791 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005792 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005793 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5794 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005795
joonhunshin4ac60942023-11-15 15:23:39 +00005796 enforceTelephonyFeatureWithException(callingPackage,
5797 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799 final long identity = Binder.clearCallingIdentity();
5800 try {
5801 final Phone phone = getPhone(subId);
5802 if (phone != null) {
5803 return phone.getServiceState().getDataNetworkType();
5804 } else {
5805 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5806 }
5807 } finally {
5808 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005810 }
5811
5812 /**
5813 * Returns the data network type
5814 */
5815 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005816 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005817 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005818 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005819 }
5820
5821 /**
5822 * Returns the data network type for a subId
5823 */
5824 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005825 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5826 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005827 String functionName = "getDataNetworkTypeForSubscriber";
5828 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5829 mApp, functionName)) {
5830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5831 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5832 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5833 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005834 }
5835
joonhunshin4ac60942023-11-15 15:23:39 +00005836 enforceTelephonyFeatureWithException(callingPackage,
5837 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 final long identity = Binder.clearCallingIdentity();
5840 try {
5841 final Phone phone = getPhone(subId);
5842 if (phone != null) {
5843 return phone.getServiceState().getDataNetworkType();
5844 } else {
5845 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5846 }
5847 } finally {
5848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005850 }
5851
5852 /**
Wink Saville36469e72014-06-11 15:17:00 -07005853 * Returns the Voice network type for a subId
5854 */
5855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005856 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5857 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005858 String functionName = "getVoiceNetworkTypeForSubscriber";
5859 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5860 mApp, functionName)) {
5861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5862 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5863 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5864 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005865 }
5866
joonhunshin4ac60942023-11-15 15:23:39 +00005867 enforceTelephonyFeatureWithException(callingPackage,
5868 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870 final long identity = Binder.clearCallingIdentity();
5871 try {
5872 final Phone phone = getPhone(subId);
5873 if (phone != null) {
5874 return phone.getServiceState().getVoiceNetworkType();
5875 } else {
5876 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5877 }
5878 } finally {
5879 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005881 }
5882
5883 /**
5884 * @return true if a ICC card is present
5885 */
5886 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005887 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005888 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005889 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005890 }
5891
5892 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005893 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005894 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005895 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005896 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07005897 if (!mApp.getResources().getBoolean(
5898 com.android.internal.R.bool.config_force_phone_globals_creation)) {
5899 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5900 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5901 }
joonhunshin4ac60942023-11-15 15:23:39 +00005902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 final long identity = Binder.clearCallingIdentity();
5904 try {
5905 final Phone phone = PhoneFactory.getPhone(slotIndex);
5906 if (phone != null) {
5907 return phone.getIccCard().hasIccCard();
5908 } else {
5909 return false;
5910 }
5911 } finally {
5912 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005914 }
5915
5916 /**
5917 * Return if the current radio is LTE on CDMA. This
5918 * is a tri-state return value as for a period of time
5919 * the mode may be unknown.
5920 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005921 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005922 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005923 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005924 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005925 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005926 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5927 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5928 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005929 }
5930
Sanket Padawe356d7632015-06-22 14:03:32 -07005931 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005932 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5933 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005934 try {
5935 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5936 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005937 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5938 }
5939
joonhunshin4ac60942023-11-15 15:23:39 +00005940 enforceTelephonyFeatureWithException(callingPackage,
5941 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 final long identity = Binder.clearCallingIdentity();
5944 try {
5945 final Phone phone = getPhone(subId);
5946 if (phone == null) {
5947 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5948 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005949 return TelephonyProperties.lte_on_cdma_device()
5950 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 }
5952 } finally {
5953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005954 }
Wink Saville36469e72014-06-11 15:17:00 -07005955 }
5956
Wink Saville36469e72014-06-11 15:17:00 -07005957 /**
5958 * {@hide}
5959 * Returns Default subId, 0 in the case of single standby.
5960 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005961 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005962 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005963 }
5964
Shishir Agrawala9f32182016-04-12 12:00:16 -07005965 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005966 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005967 }
5968
Wink Savilleb564aae2014-10-23 10:18:09 -07005969 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005970 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005971 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005972
Pengquan Menge92a50d2018-09-21 15:54:48 -07005973 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005974 return getSubscriptionManagerService().isActiveSubId(subId,
5975 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005976 }
5977
Ihab Awadf2177b72013-11-25 13:33:23 -08005978 /**
5979 * @see android.telephony.TelephonyManager.WifiCallingChoices
5980 */
5981 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 final long identity = Binder.clearCallingIdentity();
5983 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005984 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5986 getWhenToMakeWifiCallsDefaultPreference());
5987 } finally {
5988 Binder.restoreCallingIdentity(identity);
5989 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005990 }
5991
5992 /**
5993 * @see android.telephony.TelephonyManager.WifiCallingChoices
5994 */
5995 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 final long identity = Binder.clearCallingIdentity();
5997 try {
5998 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005999 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
6001 } finally {
6002 Binder.restoreCallingIdentity(identity);
6003 }
Ihab Awadf9e92732013-12-05 18:02:52 -08006004 }
6005
Sailesh Nepald1e68152013-12-12 19:08:02 -08006006 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07006007 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08006008 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08006009 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08006010
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006011 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
6012 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
6013 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08006014 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006015 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006016 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08006017 }
6018 return PhoneFactory.getPhone(phoneId);
6019 }
6020
Shishir Agrawal566b7612013-10-28 14:41:00 -07006021 @Override
Derek Tan740e1672017-06-27 14:56:27 -07006022 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08006023 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006024
Rambo Wanga1782702021-11-10 20:15:19 -08006025 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6026 /*message=*/ "iccOpenLogicalChannel");
6027
6028 if (DBG) log("iccOpenLogicalChannel: request=" + request);
6029 // Verify that the callingPackage in the request belongs to the calling UID
6030 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
6031
joonhunshin4ac60942023-11-15 15:23:39 +00006032 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6033 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
6034
Rambo Wanga1782702021-11-10 20:15:19 -08006035 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006036 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006037
Rambo Wanga1782702021-11-10 20:15:19 -08006038 private Phone getPhoneFromValidIccLogicalChannelRequest(
6039 @NonNull IccLogicalChannelRequest request, String message) {
6040 Phone phone;
6041 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6043 mApp, request.subId, message);
6044 phone = getPhoneFromSubId(request.subId);
6045 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6046 enforceModifyPermission();
6047 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6048 } else {
6049 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006050 }
Rambo Wanga1782702021-11-10 20:15:19 -08006051 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006052 }
6053
6054 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006055 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 final long identity = Binder.clearCallingIdentity();
6057 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006058 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006060 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6061 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006062 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6063 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 loge("The calling package is not allowed to access ISD-R.");
6065 throw new SecurityException(
6066 "The calling package is not allowed to access ISD-R.");
6067 }
Derek Tan740e1672017-06-27 14:56:27 -07006068 }
Derek Tan740e1672017-06-27 14:56:27 -07006069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006071 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6072 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 return response;
6074 } finally {
6075 Binder.restoreCallingIdentity(identity);
6076 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006077 }
6078
6079 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006080 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006081 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6082 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6083
Rambo Wanga1782702021-11-10 20:15:19 -08006084 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6085 /*message=*/"iccCloseLogicalChannel");
6086
6087 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6088
6089 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006090 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006091
Rambo Wanga1782702021-11-10 20:15:19 -08006092 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6093 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006094 // before this feature is enabled, this API should only return false if
6095 // the operation fails instead of throwing runtime exception for
6096 // backward-compatibility.
6097 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6098 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 final long identity = Binder.clearCallingIdentity();
6100 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006101 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006102 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006103 }
Chen Xue9d737e2022-01-01 23:41:31 -08006104 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006105 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006106 Boolean success = false;
6107 if (result instanceof RuntimeException) {
6108 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006109 if (shouldThrowExceptionOnFailure) {
6110 throw (RuntimeException) result;
6111 } else {
6112 return false;
6113 }
Chen Xue9d737e2022-01-01 23:41:31 -08006114 } else if (result instanceof Boolean) {
6115 success = (Boolean) result;
6116 } else {
6117 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6118 }
Rambo Wanga1782702021-11-10 20:15:19 -08006119 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120 return success;
6121 } finally {
6122 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006123 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006124 }
6125
6126 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006127 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006128 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6130 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006131
6132 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6133 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6134
Jordan Liu4c733742019-02-28 12:03:40 -08006135 if (DBG) {
6136 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6137 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6138 + p3 + " data=" + data);
6139 }
6140 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6141 command, p1, p2, p3, data);
6142 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006143
Jordan Liu4c733742019-02-28 12:03:40 -08006144 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006145 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006146 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006147 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006148
6149 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6150 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6151 "iccTransmitApduLogicalChannelBySlot");
6152
Jordan Liu4c733742019-02-28 12:03:40 -08006153 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006154 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006155 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6156 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006157 }
6158 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006159 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6160 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006161 }
6162
6163 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6164 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 final long identity = Binder.clearCallingIdentity();
6166 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006167 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 return "";
6169 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006172 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6173 null /* workSource */);
6174 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 // Append the returned status code to the end of the response payload.
6177 String s = Integer.toHexString(
6178 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6179 if (response.payload != null) {
6180 s = IccUtils.bytesToHexString(response.payload) + s;
6181 }
6182 return s;
6183 } finally {
6184 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006185 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006186 }
Jake Hambye994d462014-02-03 13:10:13 -08006187
Evan Charltonc66da362014-05-16 14:06:40 -07006188 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006189 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6190 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6192 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006194
6195 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6196 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6197
Jordan Liu4c733742019-02-28 12:03:40 -08006198 if (DBG) {
6199 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6200 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6201 }
6202 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6203 cla, command, p1, p2, p3, data);
6204 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006205
Jordan Liu4c733742019-02-28 12:03:40 -08006206 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006207 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006208 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006209 enforceModifyPermission();
6210 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006211
6212 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6213 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6214
Jordan Liu4c733742019-02-28 12:03:40 -08006215 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006216 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006217 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6218 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006219 }
6220
6221 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006222 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6223 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006224 }
6225
6226 // open APDU basic channel assuming the caller has sufficient permissions
6227 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6228 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 final long identity = Binder.clearCallingIdentity();
6230 try {
6231 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6232 && TextUtils.equals(ISDR_AID, data)) {
6233 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006234 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6235 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 if (bestComponent == null
6237 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6238 loge("The calling package is not allowed to select ISD-R.");
6239 throw new SecurityException(
6240 "The calling package is not allowed to select ISD-R.");
6241 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006242 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006245 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6246 null /* workSource */);
6247 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 // Append the returned status code to the end of the response payload.
6250 String s = Integer.toHexString(
6251 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6252 if (response.payload != null) {
6253 s = IccUtils.bytesToHexString(response.payload) + s;
6254 }
6255 return s;
6256 } finally {
6257 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006258 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006259 }
6260
6261 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006262 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006263 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6265 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006266
joonhunshin4ac60942023-11-15 15:23:39 +00006267 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6268 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 final long identity = Binder.clearCallingIdentity();
6271 try {
6272 if (DBG) {
6273 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6274 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6275 }
6276
6277 IccIoResult response =
6278 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6279 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6280 subId);
6281
6282 if (DBG) {
6283 log("Exchange SIM_IO [R]" + response);
6284 }
6285
6286 byte[] result = null;
6287 int length = 2;
6288 if (response.payload != null) {
6289 length = 2 + response.payload.length;
6290 result = new byte[length];
6291 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6292 } else {
6293 result = new byte[length];
6294 }
6295
6296 result[length - 1] = (byte) response.sw2;
6297 result[length - 2] = (byte) response.sw1;
6298 return result;
6299 } finally {
6300 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006301 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006302 }
6303
Nathan Haroldb3014052017-01-25 15:57:32 -08006304 /**
6305 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6306 * on a particular subscription
6307 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006308 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6309 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006311 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006312 return null;
6313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314
joonhunshin4ac60942023-11-15 15:23:39 +00006315 enforceTelephonyFeatureWithException(callingPackage,
6316 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 final long identity = Binder.clearCallingIdentity();
6319 try {
6320 if (appType != TelephonyManager.APPTYPE_USIM
6321 && appType != TelephonyManager.APPTYPE_SIM) {
6322 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6323 return null;
6324 }
6325 Object response = sendRequest(
6326 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6327 if (response instanceof String[]) {
6328 return (String[]) response;
6329 }
yincheng zhao2737e882019-09-06 17:06:54 -07006330 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006332 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333 } finally {
6334 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006335 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006336 }
6337
yincheng zhao2737e882019-09-06 17:06:54 -07006338 /**
6339 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6340 * subscription.
6341 *
6342 * @param subId the id of the subscription.
6343 * @param appType the uicc app type, must be USIM or SIM.
6344 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6345 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006346 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006347 * @return number of fplmns that is successfully written to the SIM.
6348 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006349 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6350 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6352 mApp, subId, "setForbiddenPlmns");
6353
joonhunshin4ac60942023-11-15 15:23:39 +00006354 enforceTelephonyFeatureWithException(callingPackage,
6355 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6356
yincheng zhao2737e882019-09-06 17:06:54 -07006357 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6358 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6359 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6360 }
6361 if (fplmns == null) {
6362 throw new IllegalArgumentException("Fplmn List provided is null");
6363 }
6364 for (String fplmn : fplmns) {
6365 if (!CellIdentity.isValidPlmn(fplmn)) {
6366 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6367 }
6368 }
6369 final long identity = Binder.clearCallingIdentity();
6370 try {
6371 Object response = sendRequest(
6372 CMD_SET_FORBIDDEN_PLMNS,
6373 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6374 subId);
6375 return (int) response;
6376 } finally {
6377 Binder.restoreCallingIdentity(identity);
6378 }
6379 }
6380
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006381 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006382 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6384 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006385
joonhunshin4ac60942023-11-15 15:23:39 +00006386 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6387 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 final long identity = Binder.clearCallingIdentity();
6390 try {
6391 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6392 if (response.payload == null) {
6393 return "";
6394 }
Evan Charltonc66da362014-05-16 14:06:40 -07006395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396 // Append the returned status code to the end of the response payload.
6397 String s = Integer.toHexString(
6398 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6399 s = IccUtils.bytesToHexString(response.payload) + s;
6400 return s;
6401 } finally {
6402 Binder.restoreCallingIdentity(identity);
6403 }
Evan Charltonc66da362014-05-16 14:06:40 -07006404 }
6405
Jake Hambye994d462014-02-03 13:10:13 -08006406 /**
6407 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6408 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6409 *
6410 * @param itemID the ID of the item to read
6411 * @return the NV item as a String, or null on error.
6412 */
6413 @Override
6414 public String nvReadItem(int itemID) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08006415 if (mFeatureFlags.cleanupCdma()) return null;
6416
vagdeviaf9a5b92018-08-15 16:01:53 -07006417 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6419 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420
6421 final long identity = Binder.clearCallingIdentity();
6422 try {
6423 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006424 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6426 return value;
6427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
Jake Hambye994d462014-02-03 13:10:13 -08006430 }
6431
6432 /**
6433 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6434 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6435 *
6436 * @param itemID the ID of the item to read
6437 * @param itemValue the value to write, as a String
6438 * @return true on success; false on any failure
6439 */
6440 @Override
6441 public boolean nvWriteItem(int itemID, String itemValue) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08006442 if (mFeatureFlags.cleanupCdma()) return false;
6443
vagdeviaf9a5b92018-08-15 16:01:53 -07006444 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6446 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447
6448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6451 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006452 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6454 return success;
6455 } finally {
6456 Binder.restoreCallingIdentity(identity);
6457 }
Jake Hambye994d462014-02-03 13:10:13 -08006458 }
6459
6460 /**
6461 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6462 * Used for device configuration by some CDMA operators.
6463 *
6464 * @param preferredRoamingList byte array containing the new PRL
6465 * @return true on success; false on any failure
6466 */
6467 @Override
6468 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08006469 if (mFeatureFlags.cleanupCdma()) return false;
6470
Jeff Davidson7e17e312018-02-13 18:17:36 -08006471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6472 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006473
6474 final long identity = Binder.clearCallingIdentity();
6475 try {
6476 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6477 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6478 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6479 return success;
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
6482 }
Jake Hambye994d462014-02-03 13:10:13 -08006483 }
6484
6485 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006486 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006487 * Used for device configuration by some CDMA operators.
6488 *
chen xu6dac5ab2018-10-26 17:39:23 -07006489 * @param slotIndex - device slot.
6490 *
Jake Hambye994d462014-02-03 13:10:13 -08006491 * @return true on success; false on any failure
6492 */
6493 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006494 public boolean resetModemConfig(int slotIndex) {
Tomasz Wasilczykf1af36c2024-12-05 11:36:37 -08006495 if (mFeatureFlags.cleanupCdma()) return false;
chen xu6dac5ab2018-10-26 17:39:23 -07006496 Phone phone = PhoneFactory.getPhone(slotIndex);
6497 if (phone != null) {
6498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6499 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006500
joonhunshin4ac60942023-11-15 15:23:39 +00006501 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6502 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6503
chen xu6dac5ab2018-10-26 17:39:23 -07006504 final long identity = Binder.clearCallingIdentity();
6505 try {
6506 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6507 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6508 return success;
6509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512 }
chen xu6dac5ab2018-10-26 17:39:23 -07006513 return false;
6514 }
6515
6516 /**
6517 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6518 *
6519 * @param slotIndex - device slot.
6520 *
6521 * @return true on success; false on any failure
6522 */
6523 @Override
6524 public boolean rebootModem(int slotIndex) {
6525 Phone phone = PhoneFactory.getPhone(slotIndex);
6526 if (phone != null) {
6527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6528 mApp, phone.getSubId(), "rebootModem");
6529
joonhunshin4ac60942023-11-15 15:23:39 +00006530 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6531 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6532
chen xu6dac5ab2018-10-26 17:39:23 -07006533 final long identity = Binder.clearCallingIdentity();
6534 try {
6535 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6536 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6537 return success;
6538 } finally {
6539 Binder.restoreCallingIdentity(identity);
6540 }
6541 }
6542 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006543 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006544
Brad Ebinger51f743a2017-01-23 13:50:20 -08006545 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006546 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6547 * {@link #disableIms(int)}.
6548 * @param slotIndex device slot.
6549 */
6550 public void resetIms(int slotIndex) {
6551 enforceModifyPermission();
6552
joonhunshin4ac60942023-11-15 15:23:39 +00006553 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6554 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6555
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006556 final long identity = Binder.clearCallingIdentity();
6557 try {
6558 if (mImsResolver == null) {
6559 // may happen if the does not support IMS.
6560 return;
6561 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006562 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006563 } finally {
6564 Binder.restoreCallingIdentity(identity);
6565 }
6566 }
6567
6568 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006569 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6570 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006571 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006572 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574
6575 final long identity = Binder.clearCallingIdentity();
6576 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006577 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006578 // may happen if the device does not support IMS.
6579 return;
6580 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006581 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 } finally {
6583 Binder.restoreCallingIdentity(identity);
6584 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006585 }
6586
6587 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006588 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6589 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006590 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006591 public void disableIms(int slotId) {
6592 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593
6594 final long identity = Binder.clearCallingIdentity();
6595 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006596 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006597 // may happen if the device does not support IMS.
6598 return;
6599 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006600 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601 } finally {
6602 Binder.restoreCallingIdentity(identity);
6603 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006604 }
6605
6606 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006607 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6608 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006609 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006610 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006611 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006612 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006613
6614 final long identity = Binder.clearCallingIdentity();
6615 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006616 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006617 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6618 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006619 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006620 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 } finally {
6622 Binder.restoreCallingIdentity(identity);
6623 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006624 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006625 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006626 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6627 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006628 @Override
6629 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006630 enforceModifyPermission();
6631
6632 final long identity = Binder.clearCallingIdentity();
6633 try {
6634 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006635 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006636 } finally {
6637 Binder.restoreCallingIdentity(identity);
6638 }
6639 }
6640
6641 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006642 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006643 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006644 */
6645 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6646 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647
6648 final long identity = Binder.clearCallingIdentity();
6649 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006650 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006651 // may happen if the device does not support IMS.
6652 return null;
6653 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006654 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655 } finally {
6656 Binder.restoreCallingIdentity(identity);
6657 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006658 }
6659
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006660 /**
6661 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006662 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006663 */
6664 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006666
6667 final long identity = Binder.clearCallingIdentity();
6668 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006669 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006670 // may happen if the device does not support IMS.
6671 return null;
6672 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006673 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006674 } finally {
6675 Binder.restoreCallingIdentity(identity);
6676 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006677 }
6678
Brad Ebinger884c07b2018-02-15 16:17:40 -08006679 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006680 * Sets the ImsService Package Name that Telephony will bind to.
6681 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006682 * @param slotIndex the slot ID that the ImsService should bind for.
Brad Ebinger555ddec2024-11-04 13:46:31 -08006683 * @param userId the user ID that the ImsService should bind for or {@link UserHandle#USER_NULL}
6684 * if there is no preference.
Brad Ebinger24c29992019-12-05 13:03:21 -08006685 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006686 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006687 * @param featureTypes An integer array of feature types associated with a packageName.
6688 * @param packageName The name of the package that the current configuration will be replaced
6689 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006690 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006691 */
Brad Ebinger555ddec2024-11-04 13:46:31 -08006692 public boolean setBoundImsServiceOverride(int slotIndex, int userId, boolean isCarrierService,
Brad Ebinger24c29992019-12-05 13:03:21 -08006693 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006694 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006696 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698 final long identity = Binder.clearCallingIdentity();
6699 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006700 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006701 // may happen if the device does not support IMS.
6702 return false;
6703 }
Brad Ebinger555ddec2024-11-04 13:46:31 -08006704 return mImsResolver.overrideImsServiceConfiguration(packageName, slotIndex, userId,
6705 isCarrierService, featureTypes);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 } finally {
6707 Binder.restoreCallingIdentity(identity);
6708 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006709 }
6710
6711 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006712 * Clears any carrier ImsService overrides for the slot index specified that were previously
6713 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6714 *
6715 * This should only be used for testing.
6716 *
6717 * @param slotIndex the slot ID that the ImsService should bind for.
6718 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6719 */
6720 @Override
6721 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006722 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6723 "clearCarrierImsServiceOverride");
6724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006725 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006726
6727 final long identity = Binder.clearCallingIdentity();
6728 try {
6729 if (mImsResolver == null) {
6730 // may happen if the device does not support IMS.
6731 return false;
6732 }
6733 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6734 } finally {
6735 Binder.restoreCallingIdentity(identity);
6736 }
6737 }
6738
6739 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006740 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006741 *
6742 * @param slotId The slot that the ImsService is associated with.
6743 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6744 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006745 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006746 * @return the package name of the ImsService configuration.
6747 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006748 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6749 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006750 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006751 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6752 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006754 final long identity = Binder.clearCallingIdentity();
6755 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006756 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006757 // may happen if the device does not support IMS.
6758 return "";
6759 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006760 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006761 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6762 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 } finally {
6764 Binder.restoreCallingIdentity(identity);
6765 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006766 }
6767
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006768 /**
6769 * Get the MmTelFeature state associated with the requested subscription id.
6770 * @param subId The subscription that the MmTelFeature is associated with.
6771 * @param callback A callback with an integer containing the
6772 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6773 */
6774 @Override
6775 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6776 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006777 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6778 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6779 "IMS not available on device.");
6780 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006781 final long token = Binder.clearCallingIdentity();
6782 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006783 int slotId = getSlotIndex(subId);
6784 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6785 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6786 + subId + "'");
6787 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6788 }
6789 verifyImsMmTelConfiguredOrThrow(slotId);
6790 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6791 try {
6792 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6793 } catch (RemoteException e) {
6794 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6795 + "Ignore");
6796 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006797 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006798 } catch (ImsException e) {
6799 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006800 } finally {
6801 Binder.restoreCallingIdentity(token);
6802 }
6803 }
6804
Daniel Brightbb5840b2021-01-12 15:48:18 -08006805 /**
6806 * Sets the ims registration state on all valid {@link Phone}s.
6807 */
6808 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006809 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810
6811 final long identity = Binder.clearCallingIdentity();
6812 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006813 // NOTE: Before S, this method only set the default phone.
6814 for (final Phone phone : PhoneFactory.getPhones()) {
6815 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6816 phone.setImsRegistrationState(registered);
6817 }
6818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819 } finally {
6820 Binder.restoreCallingIdentity(identity);
6821 }
Wink Saville36469e72014-06-11 15:17:00 -07006822 }
6823
6824 /**
Stuart Scott54788802015-03-30 13:18:01 -07006825 * Set the network selection mode to automatic.
6826 *
6827 */
6828 @Override
6829 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6831 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832
joonhunshin4ac60942023-11-15 15:23:39 +00006833 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6834 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6835
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 final long identity = Binder.clearCallingIdentity();
6837 try {
shilufc958392020-01-20 11:36:01 -08006838 if (!isActiveSubscription(subId)) {
6839 return;
6840 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006842 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
Nathan Harolddc3bcec2024-05-16 14:06:40 -07006843 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844 } finally {
6845 Binder.restoreCallingIdentity(identity);
6846 }
Stuart Scott54788802015-03-30 13:18:01 -07006847 }
6848
Jack Yud10cdd42020-09-28 20:28:01 -07006849 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006850 * Ask the radio to connect to the input network and change selection mode to manual.
6851 *
6852 * @param subId the id of the subscription.
6853 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6854 * the operator to attach to.
6855 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6856 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6857 * normal network selection next time.
6858 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006859 */
6860 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006861 public boolean setNetworkSelectionModeManual(
6862 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6864 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006865
joonhunshin4ac60942023-11-15 15:23:39 +00006866 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6867 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6868
Jack Yu285100e2022-12-02 22:48:35 -08006869 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006870 if (!isActiveSubscription(subId)) {
6871 return false;
6872 }
6873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006875 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006877 if (DBG) {
6878 log("setNetworkSelectionModeManual: subId: " + subId
6879 + " operator: " + operatorInfo);
6880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6882 } finally {
6883 Binder.restoreCallingIdentity(identity);
6884 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006885 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006886 /**
shilu84f6e8b2019-12-19 13:58:01 -08006887 * Get the manual network selection
6888 *
6889 * @param subId the id of the subscription.
6890 *
6891 * @return the previously saved user selected PLMN
6892 */
6893 @Override
6894 public String getManualNetworkSelectionPlmn(int subId) {
6895 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006896 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6897 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006898
joonhunshin4ac60942023-11-15 15:23:39 +00006899 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6900 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6901
shilu84f6e8b2019-12-19 13:58:01 -08006902 final long identity = Binder.clearCallingIdentity();
6903 try {
6904 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006905 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006906 }
6907
6908 final Phone phone = getPhone(subId);
6909 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006910 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006911 }
6912 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6913 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006914 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006915 } finally {
6916 Binder.restoreCallingIdentity(identity);
6917 }
6918 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006919
6920 /**
6921 * Scans for available networks.
6922 */
6923 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006924 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6925 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6927 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006928 LocationAccessPolicy.LocationPermissionResult locationResult =
6929 LocationAccessPolicy.checkLocationPermission(mApp,
6930 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6931 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006932 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006933 .setCallingPid(Binder.getCallingPid())
6934 .setCallingUid(Binder.getCallingUid())
6935 .setMethod("getCellNetworkScanResults")
6936 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006937 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6938 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006939 .build());
6940 switch (locationResult) {
6941 case DENIED_HARD:
6942 throw new SecurityException("Not allowed to access scan results -- location");
6943 case DENIED_SOFT:
6944 return null;
6945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006946
Pengquan Menga1bb6272018-09-06 09:59:22 -07006947 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948 try {
6949 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006950 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006951 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 } finally {
6953 Binder.restoreCallingIdentity(identity);
6954 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006955 }
6956
6957 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006958 * Get the call forwarding info, given the call forwarding reason.
6959 */
6960 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006961 public void getCallForwarding(int subId, int callForwardingReason,
6962 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006963 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006964
6965 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6966 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6967
Shuo Qian4a594052020-01-23 11:59:30 -08006968 long identity = Binder.clearCallingIdentity();
6969 try {
6970 if (DBG) {
6971 log("getCallForwarding: subId " + subId
6972 + " callForwardingReason" + callForwardingReason);
6973 }
Hall Liu27d24262020-09-18 19:04:59 -07006974
6975 Phone phone = getPhone(subId);
6976 if (phone == null) {
6977 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006978 callback.onError(
6979 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006980 } catch (RemoteException e) {
6981 // ignore
6982 }
6983 return;
6984 }
6985
6986 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6987 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6988 @Override
6989 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6990 try {
6991 callback.onCallForwardingInfoAvailable(info);
6992 } catch (RemoteException e) {
6993 // ignore
6994 }
6995 }
6996
6997 @Override
6998 public void onError(int error) {
6999 try {
7000 callback.onError(error);
7001 } catch (RemoteException e) {
7002 // ignore
7003 }
7004 }
7005 });
7006 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
7010 }
7011
7012 /**
7013 * Sets the voice call forwarding info including status (enable/disable), call forwarding
7014 * reason, the number to forward, and the timeout before the forwarding is attempted.
7015 */
7016 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007017 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
7018 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007019 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007020
7021 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7022 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
7023
Shuo Qian4a594052020-01-23 11:59:30 -08007024 long identity = Binder.clearCallingIdentity();
7025 try {
7026 if (DBG) {
7027 log("setCallForwarding: subId " + subId
7028 + " callForwardingInfo" + callForwardingInfo);
7029 }
Hall Liu27d24262020-09-18 19:04:59 -07007030
7031 Phone phone = getPhone(subId);
7032 if (phone == null) {
7033 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007034 callback.accept(
7035 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007036 } catch (RemoteException e) {
7037 // ignore
7038 }
7039 return;
7040 }
7041
7042 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7043 FunctionalUtils.ignoreRemoteException(callback::accept));
7044
7045 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007046 } finally {
7047 Binder.restoreCallingIdentity(identity);
7048 }
7049 }
7050
7051 /**
Hall Liu27d24262020-09-18 19:04:59 -07007052 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007053 */
7054 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007055 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007056 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007057
7058 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7059 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7060
Shuo Qian4a594052020-01-23 11:59:30 -08007061 long identity = Binder.clearCallingIdentity();
7062 try {
Hall Liu27d24262020-09-18 19:04:59 -07007063 Phone phone = getPhone(subId);
7064 if (phone == null) {
7065 try {
7066 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7067 } catch (RemoteException e) {
7068 // ignore
7069 }
7070 return;
7071 }
SongFerngWang0e767992021-03-31 22:08:45 +08007072 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7073 PersistableBundle c = configManager.getConfigForSubId(subId);
7074 boolean requireUssd = c.getBoolean(
7075 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007076
Shuo Qian4a594052020-01-23 11:59:30 -08007077 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007078 if (requireUssd) {
7079 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7080 getSubscriptionCarrierId(subId));
7081 String newUssdCommand = "";
7082 try {
7083 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007084 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007085 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7086 } catch (NullPointerException e) {
7087 loge("Failed to generate USSD number" + e);
7088 }
7089 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7090 mMainThreadHandler, callback, carrierXmlParser,
7091 CarrierXmlParser.SsEntry.SSAction.QUERY);
7092 final String ussdCommand = newUssdCommand;
7093 Executors.newSingleThreadExecutor().execute(() -> {
7094 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7095 });
7096 } else {
7097 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7098 callback::accept);
7099 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7100 }
Shuo Qian4a594052020-01-23 11:59:30 -08007101 } finally {
7102 Binder.restoreCallingIdentity(identity);
7103 }
7104 }
7105
7106 /**
Hall Liu27d24262020-09-18 19:04:59 -07007107 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007108 */
7109 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007110 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007111 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007112
7113 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7114 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7115
Shuo Qian4a594052020-01-23 11:59:30 -08007116 long identity = Binder.clearCallingIdentity();
7117 try {
Hall Liu27d24262020-09-18 19:04:59 -07007118 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7119
7120 Phone phone = getPhone(subId);
7121 if (phone == null) {
7122 try {
7123 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7124 } catch (RemoteException e) {
7125 // ignore
7126 }
7127 return;
7128 }
7129
SongFerngWang0e767992021-03-31 22:08:45 +08007130 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7131 PersistableBundle c = configManager.getConfigForSubId(subId);
7132 boolean requireUssd = c.getBoolean(
7133 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007134
SongFerngWang0e767992021-03-31 22:08:45 +08007135 if (DBG) log("getCallWaitingStatus: subId " + subId);
7136 if (requireUssd) {
7137 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7138 getSubscriptionCarrierId(subId));
7139 CarrierXmlParser.SsEntry.SSAction ssAction =
7140 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7141 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7142 String newUssdCommand = "";
7143 try {
7144 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007145 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007146 .makeCommand(ssAction, null);
7147 } catch (NullPointerException e) {
7148 loge("Failed to generate USSD number" + e);
7149 }
7150 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7151 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7152 final String ussdCommand = newUssdCommand;
7153 Executors.newSingleThreadExecutor().execute(() -> {
7154 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7155 });
7156 } else {
7157 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7158 FunctionalUtils.ignoreRemoteException(callback::accept));
7159
7160 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7161 }
Shuo Qian4a594052020-01-23 11:59:30 -08007162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
7165 }
7166
7167 /**
yinxub1bed742017-04-17 11:45:04 -07007168 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007169 *
yinxub1bed742017-04-17 11:45:04 -07007170 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007171 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7172 * location related information which will be sent if the caller already possess
7173 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007174 * @param request contains the radio access networks with bands/channels to scan
7175 * @param messenger callback messenger for scan results or errors
7176 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007177 * @return the id of the requested scan which can be used to stop the scan.
7178 */
7179 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007180 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7181 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007182 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7184 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007185 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007186 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7187 if (!renounceFineLocationAccess) {
7188 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007189 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7190 .setCallingPackage(callingPackage)
7191 .setCallingFeatureId(callingFeatureId)
7192 .setCallingPid(Binder.getCallingPid())
7193 .setCallingUid(Binder.getCallingUid())
7194 .setMethod("requestNetworkScan")
7195 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7196 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7197 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7198 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007199 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007200 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007201 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7202 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007203 if (e != null) {
7204 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7205 throw e;
7206 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007207 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007208 return TelephonyScanManager.INVALID_SCAN_ID;
7209 }
7210 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 }
joonhunshin4ac60942023-11-15 15:23:39 +00007212
7213 enforceTelephonyFeatureWithException(callingPackage,
7214 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7215
Hall Liu912dfd32019-04-25 14:02:26 -07007216 int callingUid = Binder.getCallingUid();
7217 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007218 final long identity = Binder.clearCallingIdentity();
7219 try {
7220 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007221 renounceFineLocationAccess, request, messenger, binder,
7222 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007223 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007224 } finally {
7225 Binder.restoreCallingIdentity(identity);
7226 }
yinxu504e1392017-04-12 16:03:22 -07007227 }
7228
Hall Liub2ac8ef2019-02-28 15:56:23 -08007229 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007230 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007231 boolean hasCarrierPriv;
7232 final long identity = Binder.clearCallingIdentity();
7233 try {
7234 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7235 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
Hall Liu558027f2019-05-15 19:14:05 -07007239 boolean hasNetworkScanPermission =
7240 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007241 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007242
7243 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7244 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7245 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007246 }
7247
7248 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7249 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007250 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7251 return new SecurityException("Specific channels must not be"
7252 + " scanned without location access.");
7253 }
7254 }
7255 }
7256
Hall Liub2ac8ef2019-02-28 15:56:23 -08007257 return null;
7258 }
7259
yinxu504e1392017-04-12 16:03:22 -07007260 /**
7261 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007262 *
7263 * @param subId id of the subscription
7264 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007265 */
7266 @Override
7267 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7269 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007270
Hall Liu912dfd32019-04-25 14:02:26 -07007271 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 final long identity = Binder.clearCallingIdentity();
7273 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007274 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007275 } finally {
7276 Binder.restoreCallingIdentity(identity);
7277 }
yinxu504e1392017-04-12 16:03:22 -07007278 }
7279
7280 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007281 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007282 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007283 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007284 */
7285 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007286 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007287 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007288 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007289 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290
joonhunshin4ac60942023-11-15 15:23:39 +00007291 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7292 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007294 final long identity = Binder.clearCallingIdentity();
7295 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007296 if (DBG) log("getAllowedNetworkTypesBitmask");
7297 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7298 int networkTypesBitmask = (result != null ? result[0] : -1);
7299 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7300 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007301 } finally {
7302 Binder.restoreCallingIdentity(identity);
7303 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007304 }
7305
7306 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007307 * Get the allowed network types for certain reason.
7308 *
7309 * @param subId the id of the subscription.
7310 * @param reason the reason the allowed network type change is taking place
7311 * @return the allowed network types.
7312 */
7313 @Override
7314 public long getAllowedNetworkTypesForReason(int subId,
7315 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007316 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007317 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007318
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007319 if (!mApp.getResources().getBoolean(
7320 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7321 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7322 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7323 "getAllowedNetworkTypesForReason");
7324 }
joonhunshin4ac60942023-11-15 15:23:39 +00007325
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007326 final long identity = Binder.clearCallingIdentity();
7327 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007328 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007329 } finally {
7330 Binder.restoreCallingIdentity(identity);
7331 }
7332 }
7333
7334 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007335 * Enable/Disable E-UTRA-NR Dual Connectivity
7336 * @param subId subscription id of the sim card
7337 * @param nrDualConnectivityState expected NR dual connectivity state
7338 * This can be passed following states
7339 * <ol>
7340 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7341 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7342 * <li>Disable NR dual connectivity and force secondary cell to be released
7343 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7344 * </ol>
7345 * @return operation result.
7346 */
7347 @Override
7348 public int setNrDualConnectivityState(int subId,
7349 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7351 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007352 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007353 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7354 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7355 }
7356
Sooraj Sasindran37444802020-08-11 10:40:43 -07007357 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7358 final long identity = Binder.clearCallingIdentity();
7359 try {
7360 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7361 nrDualConnectivityState, subId,
7362 workSource);
7363 if (DBG) log("enableNRDualConnectivity result: " + result);
7364 return result;
7365 } finally {
7366 Binder.restoreCallingIdentity(identity);
7367 }
7368 }
7369
7370 /**
7371 * Is E-UTRA-NR Dual Connectivity enabled
7372 * @return true if dual connectivity is enabled else false
7373 */
7374 @Override
7375 public boolean isNrDualConnectivityEnabled(int subId) {
7376 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007377 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007378 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007379 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007380 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7381 return false;
7382 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007383 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7384 final long identity = Binder.clearCallingIdentity();
7385 try {
7386 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7387 null, subId, workSource);
7388 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7389 return isEnabled;
7390 } finally {
7391 Binder.restoreCallingIdentity(identity);
7392 }
7393 }
7394
7395 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007396 * Set the allowed network types of the device and
7397 * provide the reason triggering the allowed network change.
7398 *
7399 * @param subId the id of the subscription.
7400 * @param reason the reason the allowed network type change is taking place
7401 * @param allowedNetworkTypes the allowed network types.
7402 * @return true on success; false on any failure.
7403 */
7404 @Override
7405 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007406 @TelephonyManager.AllowedNetworkTypesReason int reason,
7407 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7409 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007410 // If the caller only has carrier privileges, then they should not be able to override
7411 // any network types which were set for security reasons.
7412 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7413 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007414 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007415 throw new SecurityException(
7416 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007417 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007418 }
joonhunshin4ac60942023-11-15 15:23:39 +00007419
7420 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7421 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7422
SongFerngWang3ef3e072020-12-21 16:41:52 +08007423 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007424 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007425 return false;
7426 }
7427 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7428 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007429 return false;
7430 }
7431
Jack Yu5b494332023-01-23 18:18:04 +00007432 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7433 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007434
Jack Yue37dd262022-12-16 11:53:37 -08007435 Phone phone = getPhone(subId);
7436 if (phone == null) {
7437 return false;
7438 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007439
Jack Yue37dd262022-12-16 11:53:37 -08007440 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007441 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007442 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007443 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007444
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007445 final long identity = Binder.clearCallingIdentity();
7446 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007447 Boolean success = (Boolean) sendRequest(
7448 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7449 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7450
7451 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7452 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007453 } finally {
7454 Binder.restoreCallingIdentity(identity);
7455 }
7456 }
7457
7458 /**
Miaoa84611c2019-03-15 09:21:10 +08007459 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007460 *
Miaoa84611c2019-03-15 09:21:10 +08007461 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007462 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007463 * @hide
7464 */
7465 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007466 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007467 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007468
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07007469 if (!mApp.getResources().getBoolean(
7470 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7471 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7472 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7473 }
joonhunshin4ac60942023-11-15 15:23:39 +00007474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007476 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 try {
Miaoa84611c2019-03-15 09:21:10 +08007478 if (phone != null) {
7479 return phone.hasMatchedTetherApnSetting();
7480 } else {
7481 return false;
7482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 } finally {
7484 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007485 }
Junda Liu475951f2014-11-07 16:45:03 -08007486 }
7487
7488 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007489 * Get the user enabled state of Mobile Data.
7490 *
7491 * TODO: remove and use isUserDataEnabled.
7492 * This can't be removed now because some vendor codes
7493 * calls through ITelephony directly while they should
7494 * use TelephonyManager.
7495 *
7496 * @return true on enabled
7497 */
7498 @Override
7499 public boolean getDataEnabled(int subId) {
7500 return isUserDataEnabled(subId);
7501 }
7502
7503 /**
7504 * Get whether mobile data is enabled per user setting.
7505 *
7506 * There are other factors deciding whether mobile data is actually enabled, but they are
7507 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007508 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007509 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7510 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007511 *
7512 * @return {@code true} if data is enabled else {@code false}
7513 */
7514 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007515 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007516 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007517 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007518 try {
7519 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7520 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007521 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007522 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7523 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007524 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007526 mApp, subId, functionName);
7527
Robert Greenwalt646120a2014-05-23 11:54:03 -07007528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529
7530 final long identity = Binder.clearCallingIdentity();
7531 try {
Jack Yu285100e2022-12-02 22:48:35 -08007532 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7534 Phone phone = PhoneFactory.getPhone(phoneId);
7535 if (phone != null) {
7536 boolean retVal = phone.isUserDataEnabled();
7537 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7538 return retVal;
7539 } else {
7540 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7541 return false;
7542 }
7543 } finally {
7544 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007545 }
7546 }
7547
7548 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007549 * Checks if the device is capable of mobile data by considering whether whether the
7550 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7551 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007552 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007553 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007554 */
7555 @Override
7556 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007557 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007558 try {
7559 try {
7560 mApp.enforceCallingOrSelfPermission(
7561 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007562 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007563 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007564 try {
7565 mApp.enforceCallingOrSelfPermission(
7566 android.Manifest.permission.READ_PHONE_STATE,
7567 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007568 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007569 mApp.enforceCallingOrSelfPermission(
7570 permission.READ_BASIC_PHONE_STATE, functionName);
7571 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007572 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007573 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007574 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007576
joonhunshin4ac60942023-11-15 15:23:39 +00007577 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7578 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580 final long identity = Binder.clearCallingIdentity();
7581 try {
Jack Yu285100e2022-12-02 22:48:35 -08007582 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007584 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007585 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007586 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 return retVal;
7588 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007589 if (DBG) {
7590 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7591 + subId + " retVal=false");
7592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 return false;
7594 }
7595 } finally {
7596 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007597 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007598 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007599
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007600 /**
7601 * Check if data is enabled for a specific reason
7602 * @param subId Subscription index
7603 * @param reason the reason the data enable change is taking place
7604 * @return {@code true} if the overall data is enabled; {@code false} if not.
7605 */
7606 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007607 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007608 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007609 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007610 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007611 try {
7612 mApp.enforceCallingOrSelfPermission(
7613 android.Manifest.permission.ACCESS_NETWORK_STATE,
7614 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007615 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007616 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7617 functionName);
7618 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007619 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007620 try {
7621 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007622 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007623 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007625 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007626 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007627 }
7628
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007629 if (!mApp.getResources().getBoolean(
7630 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7631 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7632 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
7633 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007634
7635 final long identity = Binder.clearCallingIdentity();
7636 try {
Jack Yu285100e2022-12-02 22:48:35 -08007637 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007638 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007639 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007640 + " reason=" + reason);
7641 }
7642 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007643 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007644 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007645 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007646 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007647 return retVal;
7648 } else {
7649 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007650 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007651 + subId + " retVal=false");
7652 }
7653 return false;
7654 }
7655 } finally {
7656 Binder.restoreCallingIdentity(identity);
7657 }
7658 }
7659
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007660 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007661 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007662 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7663 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7664
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007665 // No permission needed; this only lets the caller inspect their own status.
7666 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007667 }
Junda Liu29340342014-07-10 15:23:27 -07007668
7669 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007670 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007671 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007672
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007673 if (!mApp.getResources().getBoolean(
7674 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7675 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7676 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7677 "getCarrierPrivilegeStatusForUid");
7678 }
joonhunshin4ac60942023-11-15 15:23:39 +00007679
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007680 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7681 }
7682
7683 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7684 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007685 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007686 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007687 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7688 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007689 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7690 if (cpt == null) {
7691 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007692 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7693 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007694 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007695 }
7696
7697 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007698 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007699 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007700
7701 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7702 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7703
chen xuf7e9fe82019-05-09 19:31:02 -07007704 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007705 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007706 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007707 Phone phone = getPhone(subId);
7708 if (phone == null) {
7709 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7710 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7711 }
7712 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7713 if (cpt == null) {
7714 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007715 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7716 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007717 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007718 }
7719
7720 @Override
7721 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007722 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007723
Tomasz Wasilczyk406b9b32024-07-10 15:45:21 -07007724 if (!mApp.getResources().getBoolean(
7725 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7726 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7727 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7728 "checkCarrierPrivilegesForPackageAnyPhone");
7729 }
joonhunshin4ac60942023-11-15 15:23:39 +00007730
Rambo Wange7209ce2022-02-23 13:41:02 -08007731 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7732 }
7733
7734 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007735 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007736 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007737 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007738 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007739 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7740 Phone phone = PhoneFactory.getPhone(phoneId);
7741 if (phone == null) {
7742 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007743 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007744 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7745 if (cpt == null) {
7746 continue;
7747 }
7748 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007749 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7750 break;
7751 }
7752 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007753 return result;
Junda Liu29340342014-07-10 15:23:27 -07007754 }
Derek Tan89e89d42014-07-08 17:00:10 -07007755
7756 @Override
Junda Liue64de782015-04-16 17:19:16 -07007757 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007758 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007759
7760 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7761 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7762 "getCarrierPackageNamesForIntentAndPhone");
7763
Rambo Wang8a247eb2022-02-08 21:11:18 +00007764 Phone phone = PhoneFactory.getPhone(phoneId);
7765 if (phone == null) {
7766 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007767 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007768 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7769 if (cpt == null) {
7770 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007771 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007772 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007773 }
7774
Amith Yamasani6e118872016-02-19 12:53:51 -08007775 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007776 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007777 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Yan Yan965c84f2024-09-24 18:14:17 -07007778
7779 enforceTelephonyFeatureWithException(
7780 getCurrentPackageName(),
7781 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7782 "getPackagesWithCarrierPrivileges");
7783
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007784 Phone phone = PhoneFactory.getPhone(phoneId);
7785 if (phone == null) {
7786 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007787 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007788 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7789 if (cpt == null) {
7790 return Collections.emptyList();
7791 }
7792 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007793 }
7794
chen xuf7e9fe82019-05-09 19:31:02 -07007795 @Override
7796 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007797 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007798
7799 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7800 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7801 "getPackagesWithCarrierPrivilegesForAllPhones");
7802
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007803 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007804 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007805 try {
7806 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7807 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7808 }
7809 } finally {
7810 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007811 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007812 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007813 }
7814
Rambo Wang6812ffb2022-03-15 16:54:17 -07007815 @Override
7816 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7817 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7818
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007819 if (!mApp.getResources().getBoolean(
7820 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7821 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7822 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7823 "getCarrierServicePackageNameForLogicalSlot");
7824 }
joonhunshin4ac60942023-11-15 15:23:39 +00007825
Rambo Wang6812ffb2022-03-15 16:54:17 -07007826 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7827 if (phone == null) {
7828 return null;
7829 }
7830 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7831 if (cpt == null) {
7832 return null;
7833 }
7834 return cpt.getCarrierServicePackageName();
7835 }
7836
Wink Savilleb564aae2014-10-23 10:18:09 -07007837 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007838 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007839 UiccPort port = phone == null ? null : phone.getUiccPort();
7840 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007841 return null;
7842 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007843 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007844 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007845 return null;
7846 }
7847 return iccId;
7848 }
7849
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007850 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007851 public void setCallComposerStatus(int subId, int status) {
7852 enforceModifyPermission();
7853
joonhunshin4ac60942023-11-15 15:23:39 +00007854 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7855 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7856
Shuo Qiane4e11672020-12-15 22:15:33 -08007857 final long identity = Binder.clearCallingIdentity();
7858 try {
7859 Phone phone = getPhone(subId);
7860 if (phone != null) {
7861 Phone defaultPhone = phone.getImsPhone();
7862 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7863 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7864 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007865 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7866 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007867 }
7868 }
Shuo Qian284ae752020-12-22 19:10:14 -08007869 } catch (ImsException e) {
7870 throw new ServiceSpecificException(e.getCode());
7871 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007872 Binder.restoreCallingIdentity(identity);
7873 }
7874 }
7875
7876 @Override
7877 public int getCallComposerStatus(int subId) {
7878 enforceReadPrivilegedPermission("getCallComposerStatus");
7879
joonhunshin4ac60942023-11-15 15:23:39 +00007880 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7881 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7882
Shuo Qiane4e11672020-12-15 22:15:33 -08007883 final long identity = Binder.clearCallingIdentity();
7884 try {
7885 Phone phone = getPhone(subId);
7886 if (phone != null) {
7887 Phone defaultPhone = phone.getImsPhone();
7888 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7889 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7890 return imsPhone.getCallComposerStatus();
7891 }
7892 }
7893 } finally {
7894 Binder.restoreCallingIdentity(identity);
7895 }
7896 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7897 }
7898
7899 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007900 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7901 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007902 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007903 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007904
joonhunshin4ac60942023-11-15 15:23:39 +00007905 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7906 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7907 "setLine1NumberForDisplayForSubscriber");
7908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007909 final long identity = Binder.clearCallingIdentity();
7910 try {
7911 final String iccId = getIccId(subId);
7912 final Phone phone = getPhone(subId);
7913 if (phone == null) {
7914 return false;
7915 }
arunvoddub1365e62024-07-31 09:42:31 +00007916 if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) {
7917 Rlog.e(LOG_TAG, "Number is too long");
7918 return false;
7919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920 final String subscriberId = phone.getSubscriberId();
7921
7922 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007923 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007924 + subscriberId + " to " + number);
7925 }
7926
7927 if (TextUtils.isEmpty(iccId)) {
7928 return false;
7929 }
7930
7931 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7932
7933 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7934 if (alphaTag == null) {
7935 editor.remove(alphaTagPrefKey);
7936 } else {
7937 editor.putString(alphaTagPrefKey, alphaTag);
7938 }
7939
7940 // Record both the line number and IMSI for this ICCID, since we need to
7941 // track all merged IMSIs based on line number
7942 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7943 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7944 if (number == null) {
7945 editor.remove(numberPrefKey);
7946 editor.remove(subscriberPrefKey);
7947 } else {
7948 editor.putString(numberPrefKey, number);
7949 editor.putString(subscriberPrefKey, subscriberId);
7950 }
7951
7952 editor.commit();
7953 return true;
7954 } finally {
7955 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007956 }
Derek Tan7226c842014-07-02 17:42:23 -07007957 }
7958
7959 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007960 public String getLine1NumberForDisplay(int subId, String callingPackage,
7961 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007962 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007963 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007964 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007965 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007966 return null;
7967 }
Derek Tan97ebb422014-09-05 16:55:38 -07007968
Tomasz Wasilczykef763582024-09-17 13:50:32 -07007969 if (!mApp.getResources().getBoolean(
7970 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7971 enforceTelephonyFeatureWithException(callingPackage,
7972 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7973 }
joonhunshin4ac60942023-11-15 15:23:39 +00007974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007975 final long identity = Binder.clearCallingIdentity();
7976 try {
7977 String iccId = getIccId(subId);
7978 if (iccId != null) {
7979 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7980 if (DBG_MERGE) {
7981 log("getLine1NumberForDisplay returning "
7982 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7983 }
7984 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007986 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7987 return null;
7988 } finally {
7989 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007990 }
Derek Tan7226c842014-07-02 17:42:23 -07007991 }
7992
7993 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007994 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7995 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007997 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007998 return null;
7999 }
Derek Tan97ebb422014-09-05 16:55:38 -07008000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 final long identity = Binder.clearCallingIdentity();
8002 try {
8003 String iccId = getIccId(subId);
8004 if (iccId != null) {
8005 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
8006 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
8007 }
8008 return null;
8009 } finally {
8010 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07008011 }
Derek Tan7226c842014-07-02 17:42:23 -07008012 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008013
8014 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008015 public String[] getMergedSubscriberIds(int subId, String callingPackage,
8016 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008017 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
8018 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08008019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08008020 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008021 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008022 return null;
8023 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008024
Jordan Liub49b04b2019-05-06 14:45:15 -07008025 // Clear calling identity, when calling TelephonyManager, because callerUid must be
8026 // the process, where TelephonyManager was instantiated.
8027 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008028 final long identity = Binder.clearCallingIdentity();
8029 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008030 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008031 final TelephonyManager tele = TelephonyManager.from(context);
8032 final SubscriptionManager sub = SubscriptionManager.from(context);
8033
8034 // Figure out what subscribers are currently active
8035 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008036
Jordan Liub49b04b2019-05-06 14:45:15 -07008037 // Only consider subs which match the current subId
8038 // This logic can be simplified. See b/131189269 for progress.
8039 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008040 activeSubscriberIds.add(tele.getSubscriberId(subId));
8041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008042
8043 // First pass, find a number override for an active subscriber
8044 String mergeNumber = null;
8045 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8046 for (String key : prefs.keySet()) {
8047 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8048 final String subscriberId = (String) prefs.get(key);
8049 if (activeSubscriberIds.contains(subscriberId)) {
8050 final String iccId = key.substring(
8051 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8052 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8053 mergeNumber = (String) prefs.get(numberKey);
8054 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008055 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056 + " for active subscriber " + subscriberId);
8057 }
8058 if (!TextUtils.isEmpty(mergeNumber)) {
8059 break;
8060 }
8061 }
8062 }
8063 }
8064
8065 // Shortcut when no active merged subscribers
8066 if (TextUtils.isEmpty(mergeNumber)) {
8067 return null;
8068 }
8069
8070 // Second pass, find all subscribers under that line override
8071 final ArraySet<String> result = new ArraySet<>();
8072 for (String key : prefs.keySet()) {
8073 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8074 final String number = (String) prefs.get(key);
8075 if (mergeNumber.equals(number)) {
8076 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8077 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8078 final String subscriberId = (String) prefs.get(subscriberKey);
8079 if (!TextUtils.isEmpty(subscriberId)) {
8080 result.add(subscriberId);
8081 }
8082 }
8083 }
8084 }
8085
8086 final String[] resultArray = result.toArray(new String[result.size()]);
8087 Arrays.sort(resultArray);
8088 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008089 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8091 }
8092 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008093 } finally {
8094 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008095 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008096 }
8097
8098 @Override
zoey chen38003472019-12-13 17:16:31 +08008099 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8100 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008101
joonhunshin4ac60942023-11-15 15:23:39 +00008102 enforceTelephonyFeatureWithException(callingPackage,
8103 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8104
Malcolm Chen6ca97372019-07-01 16:28:21 -07008105 final long identity = Binder.clearCallingIdentity();
8106 try {
8107 final TelephonyManager telephonyManager = mApp.getSystemService(
8108 TelephonyManager.class);
8109 String subscriberId = telephonyManager.getSubscriberId(subId);
8110 if (subscriberId == null) {
8111 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008112 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008113 + subId);
8114 }
8115 return null;
8116 }
8117
Jack Yu3beaf9d2023-04-14 09:17:27 -07008118 final SubscriptionInfo info = getSubscriptionManagerService()
8119 .getSubscriptionInfo(subId);
8120 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008121 // If it doesn't belong to any group, return just subscriberId of itself.
8122 if (groupUuid == null) {
8123 return new String[]{subscriberId};
8124 }
8125
8126 // Get all subscriberIds from the group.
8127 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008128 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8129 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8130 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008131 for (SubscriptionInfo subInfo : groupInfos) {
8132 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8133 if (subscriberId != null) {
8134 mergedSubscriberIds.add(subscriberId);
8135 }
8136 }
8137
8138 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8139 } finally {
8140 Binder.restoreCallingIdentity(identity);
8141
8142 }
8143 }
8144
8145 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008146 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008147 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008148 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008149
joonhunshin4ac60942023-11-15 15:23:39 +00008150 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8151 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 final long identity = Binder.clearCallingIdentity();
8154 try {
8155 final Phone phone = getPhone(subId);
8156 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8157 } finally {
8158 Binder.restoreCallingIdentity(identity);
8159 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008160 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008161
8162 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008163 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008164 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8165 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008166 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8167 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008168
8169 final long identity = Binder.clearCallingIdentity();
8170 try {
8171 final Phone phone = getPhone(subId);
8172 if (phone == null) {
8173 return false;
8174 }
8175 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8176 cdmaNonRoamingList);
8177 } finally {
8178 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008179 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008180 }
8181
8182 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008183 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008184 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008185 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008186 if (phone == null) {
8187 return raf;
8188 }
8189
Shuo Qiandee53402020-05-29 14:08:15 -07008190 try {
8191 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008192 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008193 mApp, phone.getSubId(), "getRadioAccessFamily");
8194 } catch (SecurityException e) {
8195 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8196 throw e;
8197 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008198
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008199 if (!mApp.getResources().getBoolean(
8200 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8201 enforceTelephonyFeatureWithException(callingPackage,
8202 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8203 }
joonhunshin4ac60942023-11-15 15:23:39 +00008204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008205 final long identity = Binder.clearCallingIdentity();
8206 try {
chen xub97461a2018-10-26 14:17:57 -07008207 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208 } finally {
8209 Binder.restoreCallingIdentity(identity);
8210 }
chen xub97461a2018-10-26 14:17:57 -07008211 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008212 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008213
8214 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008215 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008216 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Jack Yub6e8bad2024-09-01 19:56:34 -07008217 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8218 "Invalid package:" + callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00008219 enforceTelephonyFeatureWithException(callingPackage,
8220 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8221
Hall Liu82694d52020-12-11 18:22:04 -08008222 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008223 List<String> dialerRoleHolders;
Jack Yub6e8bad2024-09-01 19:56:34 -07008224 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8225 UserHandle.of(ActivityManager.getCurrentUser()));
Hall Liu82694d52020-12-11 18:22:04 -08008226 if (!dialerRoleHolders.contains(callingPackage)) {
8227 throw new SecurityException("App must be the dialer role holder to"
8228 + " upload a call composer pic");
8229 }
8230
8231 Executors.newSingleThreadExecutor().execute(() -> {
8232 ByteArrayOutputStream output = new ByteArrayOutputStream(
8233 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8234 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8235 boolean readUntilEnd = false;
8236 int totalBytesRead = 0;
8237 byte[] buffer = new byte[16 * 1024];
8238 while (true) {
8239 int numRead;
8240 try {
8241 numRead = input.read(buffer);
8242 } catch (IOException e) {
8243 try {
8244 fd.checkError();
8245 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8246 null);
8247 } catch (IOException e1) {
8248 // This means that the other side closed explicitly with an error. If this
8249 // happens, log and ignore.
8250 loge("Remote end of call composer picture pipe closed: " + e1);
8251 }
8252 break;
8253 }
8254 if (numRead == -1) {
8255 readUntilEnd = true;
8256 break;
8257 }
8258 totalBytesRead += numRead;
8259 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8260 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8261 try {
8262 input.close();
8263 } catch (IOException e) {
8264 // ignore
8265 }
8266 break;
8267 }
8268 output.write(buffer, 0, numRead);
8269 }
8270 // Generally, the remote end will close the file descriptors. The only case where we
8271 // close is above, where the picture size is too big.
8272
8273 try {
8274 fd.checkError();
8275 } catch (IOException e) {
8276 loge("Remote end for call composer closed with an error: " + e);
8277 return;
8278 }
8279
Hall Liuaa4211e2021-01-20 15:43:39 -08008280 if (!readUntilEnd) {
8281 loge("Did not finish reading entire image; aborting");
8282 return;
8283 }
Hall Liu82694d52020-12-11 18:22:04 -08008284
Hall Liuaa4211e2021-01-20 15:43:39 -08008285 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8286 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8287 new CallComposerPictureTransfer.Factory() {},
8288 imageData,
8289 (result) -> {
8290 if (result.first != null) {
8291 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8292 Bundle outputResult = new Bundle();
8293 outputResult.putParcelable(
8294 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8295 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8296 outputResult);
8297 } else {
8298 callback.send(result.second, null);
8299 }
8300 }
8301 );
Hall Liu82694d52020-12-11 18:22:04 -08008302 });
8303 }
8304
8305 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008306 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008307 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008308 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309
joonhunshin4ac60942023-11-15 15:23:39 +00008310 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8311 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313 final long identity = Binder.clearCallingIdentity();
8314 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008315 ImsManager.getInstance(defaultPhone.getContext(),
8316 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008320 }
8321
8322 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008323 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008324 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8326 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008327 return false;
8328 }
Svet Ganovb320e182015-04-16 12:30:10 -07008329
joonhunshin4ac60942023-11-15 15:23:39 +00008330 enforceTelephonyFeatureWithException(callingPackage,
8331 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333 final long identity = Binder.clearCallingIdentity();
8334 try {
8335 // Check the user preference and the system-level IMS setting. Even if the user has
8336 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8337 // In the long run, we may instead need to check if there exists a connection service
8338 // which can support video calling.
8339 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008340 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 return imsManager.isVtEnabledByPlatform()
8342 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8343 && imsManager.isVtEnabledByUser();
8344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008347 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008348
Andrew Leea1239f22015-03-02 17:44:07 -08008349 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008350 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8351 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008353 mApp, subId, callingPackage, callingFeatureId,
8354 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008355 return false;
8356 }
8357
joonhunshin4ac60942023-11-15 15:23:39 +00008358 enforceTelephonyFeatureWithException(callingPackage,
8359 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361 final long identity = Binder.clearCallingIdentity();
8362 try {
8363 CarrierConfigManager configManager =
8364 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008365 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8367 } finally {
8368 Binder.restoreCallingIdentity(identity);
8369 }
Andrew Leea1239f22015-03-02 17:44:07 -08008370 }
8371
8372 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008373 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008375 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376 return false;
8377 }
8378
joonhunshin4ac60942023-11-15 15:23:39 +00008379 enforceTelephonyFeatureWithException(callingPackage,
8380 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008382 final long identity = Binder.clearCallingIdentity();
8383 try {
8384 CarrierConfigManager configManager =
8385 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008386 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008387 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8388 } finally {
8389 Binder.restoreCallingIdentity(identity);
8390 }
Andrew Leea1239f22015-03-02 17:44:07 -08008391 }
8392
Andrew Lee9431b832015-03-09 18:46:45 -07008393 @Override
8394 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008395 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008396 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008397 }
8398
8399 @Override
8400 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008401 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8402 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008404 final long identity = Binder.clearCallingIdentity();
8405 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008406 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407 } finally {
8408 Binder.restoreCallingIdentity(identity);
8409 }
Andrew Lee9431b832015-03-09 18:46:45 -07008410 }
8411
Hall Liuf6668912018-10-31 17:05:23 -07008412 /**
8413 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8414 * support for the feature and device firmware support.
8415 *
8416 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8417 */
8418 @Override
8419 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008420 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8421 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008423 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008424 final Phone phone = getPhone(subscriptionId);
8425 if (phone == null) {
8426 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8427 return false;
8428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008429 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008430 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008431 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008432 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8433 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8434 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008435 return isCarrierSupported && isDeviceSupported;
8436 } finally {
8437 Binder.restoreCallingIdentity(identity);
8438 }
Hall Liu98187582018-01-22 19:15:32 -08008439 }
8440
Hall Liuf6668912018-10-31 17:05:23 -07008441 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008442 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8443 * RTT setting, will return true if the device and carrier both support RTT.
8444 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008445 */
8446 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008447 final long identity = Binder.clearCallingIdentity();
8448 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008449 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8450 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8451 return false;
8452 }
8453 }
8454
Hall Liu5bab75c2019-12-11 23:58:20 +00008455 boolean isRttSupported = isRttSupported(subscriptionId);
8456 boolean isUserRttSettingOn = Settings.Secure.getInt(
8457 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8458 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8459 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8460 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461 } finally {
8462 Binder.restoreCallingIdentity(identity);
8463 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008464 }
8465
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008466 @Deprecated
8467 @Override
8468 public String getDeviceId(String callingPackage) {
8469 return getDeviceIdWithFeature(callingPackage, null);
8470 }
8471
Sanket Padawe7310cc72015-01-14 09:53:20 -08008472 /**
8473 * Returns the unique device ID of phone, for example, the IMEI for
8474 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8475 *
8476 * <p>Requires Permission:
8477 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8478 */
8479 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008480 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008481 try {
8482 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8483 } catch (SecurityException se) {
8484 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8485 throw new SecurityException("Package " + callingPackage + " does not belong to "
8486 + Binder.getCallingUid());
8487 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008488 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008489 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008490 return null;
8491 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008492 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008493 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008494 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008495 return null;
8496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008497
8498 final long identity = Binder.clearCallingIdentity();
8499 try {
8500 return phone.getDeviceId();
8501 } finally {
8502 Binder.restoreCallingIdentity(identity);
8503 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008504 }
8505
Ping Sunc67b7c22016-03-02 19:16:45 +08008506 /**
8507 * {@hide}
8508 * Returns the IMS Registration Status on a particular subid
8509 *
8510 * @param subId
8511 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008512 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008513 Phone phone = getPhone(subId);
8514 if (phone != null) {
8515 return phone.isImsRegistered();
8516 } else {
8517 return false;
8518 }
8519 }
8520
Santos Cordon7a1885b2015-02-03 11:15:19 -08008521 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008522 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008523 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008525 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008526 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8527 }
8528 final long identity = Binder.clearCallingIdentity();
8529 try {
8530 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8531 } finally {
8532 Binder.restoreCallingIdentity(identity);
8533 }
8534 }
8535
8536 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008537 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008538 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008539 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008540 mApp,
8541 subscriptionId,
8542 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8543 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008544
8545 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8546 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8547
Tyler Gunnf70ed162019-04-03 15:28:53 -07008548 final long identity = Binder.clearCallingIdentity();
8549 try {
8550 Phone phone = getPhone(subscriptionId);
8551 if (phone == null) {
8552 return null;
8553 }
8554 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8555 } finally {
8556 Binder.restoreCallingIdentity(identity);
8557 }
8558 }
8559
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008560 /**
8561 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008562 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008563 public boolean isWifiCallingAvailable(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.isWifiCallingEnabled();
8569 } else {
8570 return false;
8571 }
8572 } finally {
8573 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008574 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008575 }
8576
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008577 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008578 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008579 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008580 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008581 final long identity = Binder.clearCallingIdentity();
8582 try {
8583 Phone phone = getPhone(subId);
8584 if (phone != null) {
8585 return phone.isVideoEnabled();
8586 } else {
8587 return false;
8588 }
8589 } finally {
8590 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008591 }
8592 }
8593
8594 /**
8595 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8596 * defined in {@link ImsRegistrationImplBase}.
8597 */
8598 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008599 final long identity = Binder.clearCallingIdentity();
8600 try {
8601 Phone phone = getPhone(subId);
8602 if (phone != null) {
8603 return phone.getImsRegistrationTech();
8604 } else {
8605 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8606 }
8607 } finally {
8608 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008609 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008610 }
8611
Stuart Scott8eef64f2015-04-08 15:13:54 -07008612 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008613 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008614 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008615
8616 enforceTelephonyFeatureWithException(callingPackage,
8617 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8618
Stuart Scott981d8582015-04-21 14:09:50 -07008619 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8620 return;
8621 }
Kai Shif70f46f2021-03-03 13:59:46 -08008622 Phone defaultPhone = getDefaultPhone();
8623 if (defaultPhone != null) {
8624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8625 mApp, getDefaultPhone().getSubId(), "factoryReset");
8626 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008627 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008628
Svet Ganovcc087f82015-05-12 20:35:54 -07008629 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008630 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8631 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008632 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008633 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008634 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008635 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008636 cleanUpAllowedNetworkTypes(phone, subId);
TAKAHASHI Uichiroc4b07452022-08-29 16:03:11 +09008637
Rambo Wang71f6aa62024-02-23 20:16:22 +00008638 setDataRoamingEnabled(subId, phone == null ? false
8639 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
TAKAHASHI Uichiroc4b07452022-08-29 16:03:11 +09008640 getPhone(subId).resetCarrierKeysForImsiEncryption(true);
Svet Ganovcc087f82015-05-12 20:35:54 -07008641 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008642 // There has been issues when Sms raw table somehow stores orphan
8643 // fragments. They lead to garbled message when new fragments come
8644 // in and combined with those stale ones. In case this happens again,
8645 // user can reset all network settings which will clean up this table.
8646 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008647 // Clean up IMS settings as well here.
8648 int slotId = getSlotIndex(subId);
Tomasz Wasilczyk2159ca22024-07-25 13:54:35 -07008649 if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008650 ImsManager.getInstance(mApp, slotId).factoryReset();
8651 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008652
Kai Shif70f46f2021-03-03 13:59:46 -08008653 if (defaultPhone == null) {
8654 return;
8655 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008656 // Erase modem config if erase modem on network setting is enabled.
8657 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8658 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8659 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008660 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008661 }
Kai Shif70f46f2021-03-03 13:59:46 -08008662
8663 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008664 } finally {
8665 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008666 }
8667 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008668
SongFerngWangfd89b102021-05-27 22:44:54 +08008669 @VisibleForTesting
8670 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8671 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8672 return;
8673 }
8674 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8675 RILConstants.PREFERRED_NETWORK_MODE);
8676 SubscriptionManager.setSubscriptionProperty(subId,
8677 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8678 "user=" + defaultNetworkType);
8679 phone.loadAllowedNetworksFromSubscriptionDatabase();
8680 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8681 defaultNetworkType, null);
8682 }
8683
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008684 private void cleanUpSmsRawTable(Context context) {
8685 ContentResolver resolver = context.getContentResolver();
8686 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8687 resolver.delete(uri, null, null);
8688 }
8689
Narayan Kamath1c496c22015-04-16 14:40:19 +01008690 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008691 public String getSimLocaleForSubscriber(int subId) {
8692 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008693
8694 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8695 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8696
chen xu5d3637b2019-01-21 23:31:38 -08008697 final Phone phone = getPhone(subId);
8698 if (phone == null) {
8699 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008700 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008702 final long identity = Binder.clearCallingIdentity();
8703 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008704 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8705 phone.getContext().getOpPackageName(),
8706 phone.getContext().getAttributionTag());
8707 if (info == null) {
8708 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8709 return null;
chen xu6291c472019-02-04 12:55:53 -08008710 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008711 // Try and fetch the locale from the carrier properties or from the SIM language
8712 // preferences (EF-PL and EF-LI)...
8713 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008714 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008715 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8716 if (localeFromDefaultSim != null) {
8717 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8718 if (DBG) log("Using locale from subId: " + subId + " locale: "
8719 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008720 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008721 } else {
8722 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008723 }
8724 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008726 // The SIM language preferences only store a language (e.g. fr = French), not an
8727 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8728 // the SIM and carrier preferences does not include a country we add the country
8729 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008730 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008731 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008732 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008733 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008734 }
8735
8736 if (DBG) log("No locale found - returning null");
8737 return null;
8738 } finally {
8739 Binder.restoreCallingIdentity(identity);
8740 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008741 }
8742
tom hsu0b59d292022-09-29 23:49:21 +08008743 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008744 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008745 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008746 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008747 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008748 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8749 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008750 Locale.forLanguageTag(localeTag).getCountry())) {
8751 return localeTag;
8752 }
8753 }
8754 return inputLocale.toLanguageTag();
8755 }
8756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008757 /**
8758 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8759 */
8760 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008761 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008762 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008763 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008764
Gary Jian3aa9a762022-01-24 16:41:19 +08008765 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8766 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008767
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008768 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008769 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8770 * representing the state of the modem.
8771 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008772 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8773 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008774 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008775 */
8776 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008777 public void requestModemActivityInfo(ResultReceiver result) {
8778 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008779
Tomasz Wasilczyk708d16e2024-09-12 14:49:51 -07008780 if (!mApp.getResources().getBoolean(
8781 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8782 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8783 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8784 }
joonhunshin4ac60942023-11-15 15:23:39 +00008785
vagdeviaf9a5b92018-08-15 16:01:53 -07008786 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008787
8788 final long identity = Binder.clearCallingIdentity();
8789 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008790 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008791 } finally {
8792 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008793 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008794 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008795
Gary Jian76280a42022-12-07 16:18:33 +08008796 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008797 // less than total activity duration.
8798 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8799 if (info == null) {
8800 return false;
8801 }
8802 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008803 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008804 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8805
Hall Liu49656c02020-10-09 19:00:11 -07008806 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8807
Siddharth Rayb8114062018-06-17 15:02:38 -07008808 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008809 && (info.getSleepTimeMillis() <= activityDurationMs)
8810 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008811 }
8812
Gary Jian3aa9a762022-01-24 16:41:19 +08008813 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8814 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8815 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8816 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8817
8818 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8819 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8820 }
8821
8822 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8823 mLastModemActivityInfo.setReceiveTimeMillis(
8824 rat,
8825 freq,
8826 info.getReceiveTimeMillis(rat, freq)
8827 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8828 }
8829
8830 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8831 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8832 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8833 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8834
8835 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8836 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8837 }
8838 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8839 mLastModemActivityInfo.setReceiveTimeMillis(
8840 rat,
8841 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8842 }
8843
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008844 /**
8845 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8846 * @param info recent ModemActivityInfo
8847 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008848 private void mergeModemActivityInfo(ModemActivityInfo info) {
8849 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008850 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008851 boolean matched;
8852 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8853 matched = false;
8854 int rat = info.getSpecificInfoRat(i);
8855 int freq = info.getSpecificInfoFrequencyRange(i);
8856 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8857 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8858 //if it already exists
8859 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8860 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8861 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8862 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8863 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8864 updateLastModemActivityInfo(info, rat, freq);
8865 matched = true;
8866 }
8867 } else {
8868 updateLastModemActivityInfo(info, rat);
8869 matched = true;
8870 }
8871 }
8872 }
8873
8874 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008875 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008876 new ActivityStatsTechSpecificInfo(
8877 rat,
8878 freq,
8879 info.getTransmitTimeMillis(rat, freq),
8880 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008881 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008882 }
8883 }
8884 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8885 mLastModemActivitySpecificInfo =
8886 new ActivityStatsTechSpecificInfo[merged.size()];
8887 merged.toArray(mLastModemActivitySpecificInfo);
8888
8889 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8890 mLastModemActivityInfo.setSleepTimeMillis(
8891 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008892 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008893 mLastModemActivityInfo.setIdleTimeMillis(
8894 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008895 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008896
8897 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008898 new ModemActivityInfo(
8899 mLastModemActivityInfo.getTimestampMillis(),
8900 mLastModemActivityInfo.getSleepTimeMillis(),
8901 mLastModemActivityInfo.getIdleTimeMillis(),
8902 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008903 }
8904
8905 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8906 ActivityStatsTechSpecificInfo[] info) {
8907 int infoSize = info.length;
8908 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8909 for (int i = 0; i < infoSize; i++) {
8910 ret[i] = new ActivityStatsTechSpecificInfo(
8911 info[i].getRat(), info[i].getFrequencyRange(),
8912 info[i].getTransmitTimeMillis(),
8913 (int) info[i].getReceiveTimeMillis());
8914 }
8915 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008916 }
8917
Jack Yu85bd38a2015-11-09 11:34:32 -08008918 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008919 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008920 */
8921 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008922 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8923 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8924 Phone phone = PhoneFactory.getPhone(slotIndex);
8925 if (phone == null) {
8926 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8927 return null;
8928 }
8929
8930 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008931 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008932 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008933 return null;
8934 }
8935
joonhunshin4ac60942023-11-15 15:23:39 +00008936 enforceTelephonyFeatureWithException(callingPackage,
8937 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8938
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008939 boolean hasFinePermission = false;
8940 boolean hasCoarsePermission = false;
8941 if (!renounceFineLocationAccess) {
8942 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8943 LocationAccessPolicy.checkLocationPermission(mApp,
8944 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8945 .setCallingPackage(callingPackage)
8946 .setCallingFeatureId(callingFeatureId)
8947 .setCallingPid(Binder.getCallingPid())
8948 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008949 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008950 .setLogAsInfo(true)
8951 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8952 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8953 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8954 .build());
8955 hasFinePermission =
8956 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8957 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008958
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008959 if (!renounceCoarseLocationAccess) {
8960 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8961 LocationAccessPolicy.checkLocationPermission(mApp,
8962 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8963 .setCallingPackage(callingPackage)
8964 .setCallingFeatureId(callingFeatureId)
8965 .setCallingPid(Binder.getCallingPid())
8966 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008967 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008968 .setLogAsInfo(true)
8969 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8970 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8971 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8972 .build());
8973 hasCoarsePermission =
8974 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8975 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008976
Jordan Liu0f2bc442020-11-18 16:47:37 -08008977 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008978 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008979 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8980 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008981 if (subInfo != null && !subInfo.isActive()) {
8982 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008983 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008984 }
8985
Hall Liuf19c44f2018-11-27 14:38:17 -08008986 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008987 boolean isCallingPackageDataService = phone.getDataServicePackages()
8988 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008989
8990 // Scrub out the location info in ServiceState depending on what level of access
8991 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008992 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008993 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8994 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008995 } finally {
8996 Binder.restoreCallingIdentity(identity);
8997 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008998 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008999
9000 /**
9001 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
9002 *
9003 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9004 * voicemail ringtone.
9005 * @return The URI for the ringtone to play when receiving a voicemail from a specific
9006 * PhoneAccount.
9007 */
9008 @Override
9009 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009010 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9011 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
9012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009013 final long identity = Binder.clearCallingIdentity();
9014 try {
9015 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9016 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009017 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009018 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009020 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009024 }
9025
9026 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009027 * Sets the per-account voicemail ringtone.
9028 *
9029 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9030 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9031 *
9032 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9033 * voicemail ringtone.
9034 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
9035 * PhoneAccount.
9036 */
9037 @Override
9038 public void setVoicemailRingtoneUri(String callingPackage,
9039 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009040 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009042 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9043 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9045 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9046 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009048
joonhunshin4ac60942023-11-15 15:23:39 +00009049 enforceTelephonyFeatureWithException(callingPackage,
9050 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
9051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009052 final long identity = Binder.clearCallingIdentity();
9053 try {
9054 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9055 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009056 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009057 }
9058 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9059 } finally {
9060 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009061 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009062 }
9063
9064 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009065 * Returns whether vibration is set for voicemail notification in Phone settings.
9066 *
9067 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9068 * voicemail vibration setting.
9069 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9070 */
9071 @Override
9072 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009073 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9074 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009076 final long identity = Binder.clearCallingIdentity();
9077 try {
9078 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9079 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009080 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009081 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009083 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9084 } finally {
9085 Binder.restoreCallingIdentity(identity);
9086 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009087 }
9088
Youhan Wange64578a2016-05-02 15:32:42 -07009089 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009090 * Sets the per-account voicemail vibration.
9091 *
9092 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9093 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9094 *
9095 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9096 * voicemail vibration setting.
9097 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9098 * specific PhoneAccount.
9099 */
9100 @Override
9101 public void setVoicemailVibrationEnabled(String callingPackage,
9102 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009103 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009104 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009105 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9106 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9108 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9109 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009110 }
9111
joonhunshin4ac60942023-11-15 15:23:39 +00009112 enforceTelephonyFeatureWithException(callingPackage,
9113 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009115 final long identity = Binder.clearCallingIdentity();
9116 try {
9117 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9118 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009119 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009120 }
9121 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9122 } finally {
9123 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009124 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009125 }
9126
9127 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009128 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9129 *
9130 * @throws SecurityException if the caller does not have the required permission
9131 */
arunvoddud7401012022-12-15 16:08:12 +00009132 @VisibleForTesting
9133 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009134 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009135 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009136 }
9137
9138 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009139 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9140 * permission.
9141 *
9142 * @throws SecurityException if the caller does not have the required permission
9143 */
9144 private void enforceSendSmsPermission() {
9145 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9146 }
9147
9148 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009149 * Make sure either called from same process as self (phone) or IPC caller has interact across
9150 * users permission.
9151 *
9152 * @throws SecurityException if the caller does not have the required permission
9153 */
9154 private void enforceInteractAcrossUsersPermission(String message) {
9155 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9156 }
9157
9158 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009159 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009160 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009161 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009162 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009163 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009164 final long identity = Binder.clearCallingIdentity();
9165 try {
9166 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009167 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009168 if (componentName == null) {
9169 throw new SecurityException(
9170 "Caller not current active visual voicemail package[null]");
9171 }
9172 String vvmPackage = componentName.getPackageName();
9173 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009174 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009175 }
9176 } finally {
9177 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009178 }
9179 }
9180
9181 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009182 * Return the application ID for the app type.
9183 *
9184 * @param subId the subscription ID that this request applies to.
9185 * @param appType the uicc app type.
9186 * @return Application ID for specificied app type, or null if no uicc.
9187 */
9188 @Override
9189 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009190 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009191
9192 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9193 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9194
Youhan Wange64578a2016-05-02 15:32:42 -07009195 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009196
9197 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009198 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009199 if (phone == null) {
9200 return null;
9201 }
9202 String aid = null;
9203 try {
Tomasz Wasilczyk58e46ca2024-12-06 12:09:51 -08009204 UiccCardApplication app = UiccController.getInstance()
9205 .getUiccPort(phone.getPhoneId()).getApplicationByType(appType);
9206 if (app == null) return null;
9207 aid = app.getAid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009208 } catch (Exception e) {
Tomasz Wasilczyk58e46ca2024-12-06 12:09:51 -08009209 Log.e(LOG_TAG, "Not getting aid", e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009210 }
9211 return aid;
9212 } finally {
9213 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009214 }
Youhan Wange64578a2016-05-02 15:32:42 -07009215 }
9216
Youhan Wang4001d252016-05-11 10:29:41 -07009217 /**
9218 * Return the Electronic Serial Number.
9219 *
9220 * @param subId the subscription ID that this request applies to.
9221 * @return ESN or null if error.
9222 */
9223 @Override
9224 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009225 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009226 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009227
9228 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009229 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009230 if (phone == null) {
9231 return null;
9232 }
9233 String esn = null;
9234 try {
9235 esn = phone.getEsn();
9236 } catch (Exception e) {
Tomasz Wasilczyk58e46ca2024-12-06 12:09:51 -08009237 Log.e(LOG_TAG, "Not getting ESN", e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009238 }
9239 return esn;
9240 } finally {
9241 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009242 }
Youhan Wang4001d252016-05-11 10:29:41 -07009243 }
9244
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009245 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009246 * Return the Preferred Roaming List Version.
9247 *
9248 * @param subId the subscription ID that this request applies to.
9249 * @return PRLVersion or null if error.
9250 */
9251 @Override
9252 public String getCdmaPrlVersion(int subId) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -08009253 if (mFeatureFlags.cleanupCdma()) return null;
9254
Brad Ebinger35c841c2018-10-01 10:40:55 -07009255 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009256
9257 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9258 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9259
Youhan Wang66ad5d72016-07-18 17:56:58 -07009260 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009261
9262 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009263 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009264 if (phone == null) {
9265 return null;
9266 }
9267 String cdmaPrlVersion = null;
9268 try {
9269 cdmaPrlVersion = phone.getCdmaPrlVersion();
9270 } catch (Exception e) {
9271 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9272 }
9273 return cdmaPrlVersion;
9274 } finally {
9275 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009276 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009277 }
9278
9279 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009280 * Get snapshot of Telephony histograms
9281 * @return List of Telephony histograms
9282 * @hide
9283 */
9284 @Override
9285 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9287 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009288
9289 final long identity = Binder.clearCallingIdentity();
9290 try {
9291 return RIL.getTelephonyRILTimingHistograms();
9292 } finally {
9293 Binder.restoreCallingIdentity(identity);
9294 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009295 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009296
9297 /**
9298 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009299 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9300 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009301 * Require system privileges. In the future we may add this to carrier APIs.
9302 *
Michele Berionne482f8202018-11-27 18:57:59 -08009303 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009304 */
9305 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009306 @TelephonyManager.SetCarrierRestrictionResult
9307 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009308 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009309
9310 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9311 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9312
vagdeviaf9a5b92018-08-15 16:01:53 -07009313 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009314
Michele Berionne482f8202018-11-27 18:57:59 -08009315 if (carrierRestrictionRules == null) {
9316 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009317 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009319 final long identity = Binder.clearCallingIdentity();
9320 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009321 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009322 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009323 } finally {
9324 Binder.restoreCallingIdentity(identity);
9325 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009326 }
9327
9328 /**
9329 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009330 * Get the allowed carrier list and the excluded carrier list, including the priority between
9331 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009332 * Require system privileges. In the future we may add this to carrier APIs.
9333 *
Michele Berionne482f8202018-11-27 18:57:59 -08009334 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009335 */
9336 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009337 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009338 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009339
9340 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9341 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9342
vagdeviaf9a5b92018-08-15 16:01:53 -07009343 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009344
9345 final long identity = Binder.clearCallingIdentity();
9346 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009347 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9348 if (response instanceof CarrierRestrictionRules) {
9349 return (CarrierRestrictionRules) response;
9350 }
9351 // Response is an Exception of some kind,
9352 // which is signalled to the user as a NULL retval
9353 return null;
9354 } catch (Exception e) {
9355 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9356 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009357 } finally {
9358 Binder.restoreCallingIdentity(identity);
9359 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009360 }
9361
fionaxu59545b42016-05-25 15:53:37 -07009362 /**
arunvoddud7401012022-12-15 16:08:12 +00009363 * Fetches the carrier restriction status of the device and sends the status to the caller
9364 * through the callback.
9365 *
9366 * @param callback The callback that will be used to send the result.
9367 * @throws SecurityException if the caller does not have the required permission/privileges or
9368 * the caller is not allowlisted.
9369 */
9370 @Override
9371 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
arunvoddu181c74f2024-08-19 14:21:29 +00009372 String functionName = "getCarrierRestrictionStatus";
joonhunshin4ac60942023-11-15 15:23:39 +00009373 enforceTelephonyFeatureWithException(packageName,
arunvoddu181c74f2024-08-19 14:21:29 +00009374 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName);
9375 try {
9376 mApp.enforceCallingOrSelfPermission(
9377 android.Manifest.permission.READ_BASIC_PHONE_STATE,
9378 functionName);
9379 } catch (SecurityException e) {
9380 mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE,
9381 functionName);
9382 }
Steve Statia28b7cb32024-03-11 23:58:50 +00009383 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9384 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009385 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9386 throw new SecurityException("Not an authorized caller");
9387 }
9388 final long identity = Binder.clearCallingIdentity();
9389 try {
9390 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009391 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009392 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9393 } finally {
9394 Binder.restoreCallingIdentity(identity);
9395 }
9396 }
9397
arunvoddu567f2b42023-04-25 17:22:00 +00009398 @Override
9399 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9400 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9401 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9402 return allowListInfo.getShaIdList(pkgName, carrierId);
9403 }
9404
arunvoddud7401012022-12-15 16:08:12 +00009405 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009406 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009407 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009408 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009409 }
9410
9411 /**
fionaxu59545b42016-05-25 15:53:37 -07009412 * Action set from carrier signalling broadcast receivers to enable/disable radio
9413 * @param subId the subscription ID that this action applies to.
9414 * @param enabled control enable or disable radio.
9415 * {@hide}
9416 */
9417 @Override
9418 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9419 enforceModifyPermission();
9420 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009421
9422 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009423 if (phone == null) {
9424 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9425 return;
9426 }
9427 try {
9428 phone.carrierActionSetRadioEnabled(enabled);
9429 } catch (Exception e) {
9430 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009431 } finally {
9432 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009433 }
9434 }
9435
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009436 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009437 * Enable or disable Voice over NR (VoNR)
9438 * @param subId the subscription ID that this action applies to.
9439 * @param enabled enable or disable VoNR.
9440 * @return operation result.
9441 */
9442 @Override
9443 public int setVoNrEnabled(int subId, boolean enabled) {
9444 enforceModifyPermission();
9445 final Phone phone = getPhone(subId);
9446
9447 final long identity = Binder.clearCallingIdentity();
9448 if (phone == null) {
9449 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9450 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9451 }
9452
9453 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9454 try {
9455 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9456 workSource);
9457 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009458
9459 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9460 if (DBG) {
9461 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9462 }
9463 SubscriptionManager.setSubscriptionProperty(
9464 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9465 (enabled ? "1" : "0"));
9466 }
9467
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009468 return result;
9469 } finally {
9470 Binder.restoreCallingIdentity(identity);
9471 }
9472 }
9473
9474 /**
9475 * Is voice over NR enabled
9476 * @return true if VoNR is enabled else false
9477 */
9478 @Override
9479 public boolean isVoNrEnabled(int subId) {
9480 enforceReadPrivilegedPermission("isVoNrEnabled");
9481 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9482 final long identity = Binder.clearCallingIdentity();
9483 try {
9484 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9485 null, subId, workSource);
9486 if (DBG) log("isVoNrEnabled: " + isEnabled);
9487 return isEnabled;
9488 } finally {
9489 Binder.restoreCallingIdentity(identity);
9490 }
9491 }
9492
9493 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009494 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9495 * network status based on which carrier apps could apply actions accordingly,
9496 * enable/disable default url handler for example.
9497 *
9498 * @param subId the subscription ID that this action applies to.
9499 * @param report control start/stop reporting the default network status.
9500 * {@hide}
9501 */
9502 @Override
9503 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9504 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009505
9506 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9507 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9508 "carrierActionReportDefaultNetworkStatus");
9509
fionaxu8da9cb12017-05-23 15:02:46 -07009510 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009511
9512 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009513 if (phone == null) {
9514 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9515 return;
9516 }
9517 try {
9518 phone.carrierActionReportDefaultNetworkStatus(report);
9519 } catch (Exception e) {
9520 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009521 } finally {
9522 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009523 }
9524 }
9525
9526 /**
fionaxud9622282017-07-17 17:51:30 -07009527 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9528 * @param subId the subscription ID that this action applies to.
9529 * {@hide}
9530 */
9531 @Override
9532 public void carrierActionResetAll(int subId) {
9533 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009534
9535 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9536 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9537
fionaxud9622282017-07-17 17:51:30 -07009538 final Phone phone = getPhone(subId);
9539 if (phone == null) {
9540 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9541 return;
9542 }
9543 try {
9544 phone.carrierActionResetAll();
9545 } catch (Exception e) {
9546 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9547 }
9548 }
9549
9550 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009551 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9552 * bug report is being generated.
9553 */
9554 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009555 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009556 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9557 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009558 writer.println("Permission Denial: can't dump Phone from pid="
9559 + Binder.getCallingPid()
9560 + ", uid=" + Binder.getCallingUid()
9561 + "without permission "
9562 + android.Manifest.permission.DUMP);
9563 return;
9564 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009565 try {
9566 DumpsysHandler.dump(mApp, fd, writer, args);
9567 } catch (Exception e) {
9568 writer.println("Failed to dump phone information: " + e);
9569 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009570 }
Jack Yueb89b242016-06-22 13:27:47 -07009571
Brad Ebingerdac2f002018-04-03 15:17:52 -07009572 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009573 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9574 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9575 @NonNull String[] args) {
9576 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9577 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009578 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009579 }
9580
Jack Yueb89b242016-06-22 13:27:47 -07009581 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009582 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009583 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009584 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009585 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009586 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009587 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009588 */
9589 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009590 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009591 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009592 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9593 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9594 try {
9595 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009596 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009597 } catch (SecurityException se) {
9598 enforceModifyPermission();
9599 }
9600 } else {
9601 enforceModifyPermission();
9602 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009603
joonhunshin4ac60942023-11-15 15:23:39 +00009604 enforceTelephonyFeatureWithException(callingPackage,
9605 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9606
Nate Myren116695d2024-02-09 09:36:01 -08009607 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009608 final long identity = Binder.clearCallingIdentity();
9609 try {
Nate Myren116695d2024-02-09 09:36:01 -08009610 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9611 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009612 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009613 callingUid, callingPackage, null, null);
9614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009615 Phone phone = getPhone(subId);
9616 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009617 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9618 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009619 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009620 phone.getDataSettingsManager().setDataEnabled(
9621 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009623 }
9624 } finally {
9625 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009626 }
9627 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009628
9629 /**
9630 * Get Client request stats
9631 * @return List of Client Request Stats
9632 * @hide
9633 */
9634 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009635 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9636 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009637 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009638 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009639 return null;
9640 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009641 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009643 final long identity = Binder.clearCallingIdentity();
9644 try {
9645 if (phone != null) {
9646 return phone.getClientRequestStats();
9647 }
9648
9649 return null;
9650 } finally {
9651 Binder.restoreCallingIdentity(identity);
9652 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009653 }
9654
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009655 private WorkSource getWorkSource(int uid) {
Jack Yube3fa442024-09-16 14:39:45 -07009656 PackageManager pm;
9657 if (mFeatureFlags.hsumPackageManager()) {
9658 pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0)
9659 .getPackageManager();
9660 } else {
9661 pm = mApp.getPackageManager();
9662 }
9663
9664 String packageName = pm.getNameForUid(uid);
Jack Yu86374492024-09-16 13:05:44 -07009665 if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) {
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009666 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9667 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9668 // exception. ROOT_UID seems not to have a valid package name returned by
9669 // PackageManager, so just fake it here to avoid issues when running telephony shell
9670 // commands that plumb through the RIL as root, like so:
9671 // $ adb root
9672 // $ adb shell cmd phone ...
9673 packageName = "root";
9674 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009675 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009676 }
Jack Yueb4124c2017-02-16 15:32:43 -08009677
9678 /**
Grace Chen70990072017-03-24 17:21:30 -07009679 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009680 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009681 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009682 * @param state State of SIM (power down, power up, pass through)
9683 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9684 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9685 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009686 *
9687 **/
9688 @Override
Grace Chen70990072017-03-24 17:21:30 -07009689 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009690 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009691
9692 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9693 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9694
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009695 Phone phone = PhoneFactory.getPhone(slotIndex);
9696
vagdeviaf9a5b92018-08-15 16:01:53 -07009697 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009699 final long identity = Binder.clearCallingIdentity();
9700 try {
9701 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009702 phone.setSimPowerState(state, null, workSource);
9703 }
9704 } finally {
9705 Binder.restoreCallingIdentity(identity);
9706 }
9707 }
9708
9709 /**
9710 * Set SIM card power state.
9711 *
9712 * @param slotIndex SIM slot id.
9713 * @param state State of SIM (power down, power up, pass through)
9714 * @param callback callback to trigger after success or failure
9715 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9716 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9717 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9718 *
9719 **/
9720 @Override
9721 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9722 IIntegerConsumer callback) {
9723 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009724
9725 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9726 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9727 "setSimPowerStateForSlotWithCallback");
9728
Jordan Liu109698e2020-11-24 14:50:34 -08009729 Phone phone = PhoneFactory.getPhone(slotIndex);
9730
9731 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9732
9733 final long identity = Binder.clearCallingIdentity();
9734 try {
9735 if (phone != null) {
9736 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9737 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009738 }
9739 } finally {
9740 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009741 }
9742 }
Shuo Qiandd210312017-04-12 22:11:33 +00009743
Tyler Gunn65d45c22017-06-05 11:22:26 -07009744 private boolean isUssdApiAllowed(int subId) {
9745 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009746 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009747 if (configManager == null) {
9748 return false;
9749 }
9750 PersistableBundle pb = configManager.getConfigForSubId(subId);
9751 if (pb == null) {
9752 return false;
9753 }
9754 return pb.getBoolean(
9755 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9756 }
9757
Shuo Qiandd210312017-04-12 22:11:33 +00009758 /**
Ling Mac28f0212023-03-24 16:07:15 -07009759 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009760 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009761 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009762 */
goneil9c5f4872017-12-05 14:07:56 -08009763 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009764 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009765 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009766
9767 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9768 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009770 final long identity = Binder.clearCallingIdentity();
9771 try {
Ling Mac28f0212023-03-24 16:07:15 -07009772 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009773 } finally {
9774 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009775 }
9776 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009777
9778 /**
9779 * Get the current signal strength information for the given subscription.
9780 * Because this information is not updated when the device is in a low power state
9781 * it should not be relied-upon to be current.
9782 * @param subId Subscription index
9783 * @return the most recent cached signal strength info from the modem
9784 */
9785 @Override
9786 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009787 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9788 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009790 final long identity = Binder.clearCallingIdentity();
9791 try {
9792 Phone p = getPhone(subId);
9793 if (p == null) {
9794 return null;
9795 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009797 return p.getSignalStrength();
9798 } finally {
9799 Binder.restoreCallingIdentity(identity);
9800 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009801 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009802
Pengquan Meng77b7f132018-08-22 14:49:57 -07009803 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009804 * Get the current modem radio state for the given slot.
9805 * @param slotIndex slot index.
9806 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009807 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009808 * @return the current radio power state from the modem
9809 */
9810 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009811 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009812 Phone phone = PhoneFactory.getPhone(slotIndex);
9813 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9815 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009816 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9817 }
9818
joonhunshin4ac60942023-11-15 15:23:39 +00009819 enforceTelephonyFeatureWithException(callingPackage,
9820 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9821
Chen Xuf792fd62018-10-17 17:54:36 +00009822 final long identity = Binder.clearCallingIdentity();
9823 try {
9824 return phone.getRadioPowerState();
9825 } finally {
9826 Binder.restoreCallingIdentity(identity);
9827 }
9828 }
9829 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9830 }
9831
9832 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009833 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9834 *
9835 * <p>Requires one of the following permissions:
9836 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009837 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009838 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9839 * privileges.
9840 *
9841 * @param subId subscription id
9842 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9843 * {@code false}.
9844 */
9845 @Override
9846 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009847 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009848 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009849 try {
9850 mApp.enforceCallingOrSelfPermission(
9851 android.Manifest.permission.ACCESS_NETWORK_STATE,
9852 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009853 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009854 mApp.enforceCallingOrSelfPermission(
9855 permission.READ_BASIC_PHONE_STATE, functionName);
9856 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009857 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009858 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009859 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009860 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009861
joonhunshin4ac60942023-11-15 15:23:39 +00009862 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9863 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9864
Pengquan Menga1bb6272018-09-06 09:59:22 -07009865 boolean isEnabled = false;
9866 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009867 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009868 Phone phone = getPhone(subId);
9869 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009870 } finally {
9871 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009872 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009873 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009874 }
9875
9876
9877 /**
9878 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9879 *
9880 * <p> Requires permission:
9881 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9882 * privileges.
9883 *
9884 * @param subId subscription id
9885 * @param isEnabled {@code true} means enable, {@code false} means disable.
9886 */
9887 @Override
9888 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9890 mApp, subId, "setDataRoamingEnabled");
9891
joonhunshin4ac60942023-11-15 15:23:39 +00009892 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9893 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9894
Pengquan Menga1bb6272018-09-06 09:59:22 -07009895 final long identity = Binder.clearCallingIdentity();
9896 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009897 Phone phone = getPhone(subId);
9898 if (phone != null) {
9899 phone.setDataRoamingEnabled(isEnabled);
9900 }
9901 } finally {
9902 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009903 }
9904 }
9905
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009906 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009907 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009908 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009909 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009910 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009911
joonhunshin4ac60942023-11-15 15:23:39 +00009912 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9913 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9914
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009915 boolean isAllowed = true;
9916 final long identity = Binder.clearCallingIdentity();
9917 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009918 Phone phone = getPhone(subId);
9919 if (phone != null) {
9920 isAllowed = phone.isCspPlmnEnabled();
9921 }
9922 } finally {
9923 Binder.restoreCallingIdentity(identity);
9924 }
9925 return isAllowed;
9926 }
9927
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009928 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9929 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009930 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009931 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009932 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009933 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9934 if (phone == null) {
9935 return false;
9936 }
9937 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9938 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9939 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009940 }
9941
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009942 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009943 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009944 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009945 mApp.getSystemService(AppOpsManager.class)
9946 .checkPackage(Binder.getCallingUid(), callingPackage);
9947
Jordan Liu1e142fc2019-04-22 15:10:43 -07009948 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009949 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009950 try {
9951 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009952 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009953 } catch (SecurityException e) {
9954 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9955 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009956 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009957 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009958 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009959 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009960 }
joonhunshin4ac60942023-11-15 15:23:39 +00009961
9962 enforceTelephonyFeatureWithException(callingPackage,
9963 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9964
sandeepjsb6c87872021-09-27 15:34:44 +00009965 // checking compatibility, if calling app's target SDK is T and beyond.
9966 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9967 Binder.getCallingUid())) {
9968 isIccIdAccessRestricted = true;
9969 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009970 final long identity = Binder.clearCallingIdentity();
9971 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009972 UiccController uiccController = UiccController.getInstance();
9973 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009974 if (hasReadPermission) {
9975 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009976 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009977
9978 // Remove private info if the caller doesn't have access
9979 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9980 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009981 //setting the value after compatibility check
9982 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009983 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9984 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009985 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009986 if (card == null) {
9987 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009988 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009989 continue;
9990 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009991 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9992 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009993 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009994 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009995 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009996 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9997 for (UiccPortInfo portInfo : portInfos) {
9998 UiccPort port = uiccController.getUiccPortForSlot(
9999 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
10000 if (port == null) {
10001 // assume no access if port is null
10002 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
10003 continue;
10004 }
10005 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10006 uiccPortInfos.add(portInfo);
10007 } else {
10008 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
10009 }
10010 }
10011 filteredInfos.add(new UiccCardInfo(
10012 cardInfo.isEuicc(),
10013 cardInfo.getCardId(),
10014 null,
10015 cardInfo.getPhysicalSlotIndex(),
10016 cardInfo.isRemovable(),
10017 cardInfo.isMultipleEnabledProfilesSupported(),
10018 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -070010019 }
10020 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -080010021 } finally {
10022 Binder.restoreCallingIdentity(identity);
10023 }
10024 }
10025
sandeepjsb6c87872021-09-27 15:34:44 +000010026 /**
10027 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
10028 * generally private and require carrier privileges to view.
10029 *
10030 * @hide
10031 */
10032 @NonNull
10033 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
10034 List<UiccPortInfo> portinfo = new ArrayList<>();
10035 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
10036 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
10037 }
10038 return new UiccCardInfo(
10039 cardInfo.isEuicc(),
10040 cardInfo.getCardId(),
10041 null,
10042 cardInfo.getPhysicalSlotIndex(),
10043 cardInfo.isRemovable(),
10044 cardInfo.isMultipleEnabledProfilesSupported(),
10045 portinfo
10046 );
10047 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010048
sandeepjsb6c87872021-09-27 15:34:44 +000010049 /**
10050 * @hide
10051 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10052 * These values are generally private and require carrier privileges to view.
10053 */
10054 @NonNull
10055 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10056 return new UiccPortInfo(
10057 UiccPortInfo.ICCID_REDACTED,
10058 portInfo.getPortIndex(),
10059 portInfo.getLogicalSlotIndex(),
10060 portInfo.isActive()
10061 );
10062 }
10063 @Override
10064 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010065 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010066 mApp.getSystemService(AppOpsManager.class)
10067 .checkPackage(Binder.getCallingUid(), callingPackage);
10068
sandeepjsb6c87872021-09-27 15:34:44 +000010069 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010070
Aman Guptaf3c90b32022-03-17 04:54:16 +000010071 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10072 // we are reading iccId which is PII data.
10073 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010074
joonhunshin4ac60942023-11-15 15:23:39 +000010075 enforceTelephonyFeatureWithException(callingPackage,
10076 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
10077
sandeepjsb6c87872021-09-27 15:34:44 +000010078 // checking compatibility, if calling app's target SDK is T and beyond.
10079 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10080 Binder.getCallingUid())) {
10081 isLogicalSlotAccessRestricted = true;
10082 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010083 final long identity = Binder.clearCallingIdentity();
10084 try {
10085 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010086 if (slots == null || slots.length == 0) {
10087 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010088 return null;
10089 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010090 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10091 for (int i = 0; i < slots.length; i++) {
10092 UiccSlot slot = slots[i];
10093 if (slot == null) {
10094 continue;
10095 }
10096
Jordan Liu7be7e652019-05-06 18:55:02 +000010097 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010098 UiccCard card = slot.getUiccCard();
10099 if (card != null) {
10100 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010101 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010102 cardId = slot.getEid();
10103 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010104 // If cardId is null, use iccId of default port as cardId.
10105 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010106 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010107 }
10108
Jordan Liu857451f2019-05-09 16:35:35 -070010109 if (cardId != null) {
10110 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10111 // if cardId is an EID, it's all digits so this is fine
10112 cardId = IccUtils.stripTrailingFs(cardId);
10113 }
10114
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010115 int cardState = 0;
10116 switch (slot.getCardState()) {
10117 case CARDSTATE_ABSENT:
10118 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10119 break;
10120 case CARDSTATE_PRESENT:
10121 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10122 break;
10123 case CARDSTATE_ERROR:
10124 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10125 break;
10126 case CARDSTATE_RESTRICTED:
10127 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10128 break;
10129 default:
10130 break;
10131
10132 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010133 List<UiccPortInfo> portInfos = new ArrayList<>();
10134 int[] portIndexes = slot.getPortList();
10135 for (int portIdx : portIndexes) {
10136 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010137 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010138 portInfos.add(new UiccPortInfo(iccId, portIdx,
10139 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010141 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010142 slot.isEuicc(),
10143 cardId,
10144 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010145 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010146 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010147 //setting the value after compatibility check
10148 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010149 }
10150 return infos;
10151 } finally {
10152 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010153 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010154 }
10155
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010156 /* Returns null if doesn't have read permission or carrier privilege access. */
10157 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10158 boolean hasReadPermission) {
10159 String iccId = slot.getIccId(portIndex);
10160 if (hasReadPermission) { // if has read permission
10161 return iccId;
10162 } else {
10163 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10164 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10165 // if no read permission, checking carrier privilege access
10166 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10167 return iccId;
10168 }
10169 }
10170 }
10171 // No read permission or carrier privilege access.
10172 return UiccPortInfo.ICCID_REDACTED;
10173 }
10174
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010175 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010176 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010177 public boolean switchSlots(int[] physicalSlots) {
10178 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010179
joonhunshin4ac60942023-11-15 15:23:39 +000010180 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10181 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10182
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010183 final long identity = Binder.clearCallingIdentity();
10184 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010185 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10186 for (int i = 0; i < physicalSlots.length; i++) {
10187 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10188 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10189 physicalSlots[i], i));
10190 }
10191 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010192 } finally {
10193 Binder.restoreCallingIdentity(identity);
10194 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010195 }
Jack Yu4c988042018-02-27 15:30:01 -080010196
10197 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010198 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10199 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10200 enforceModifyPermission();
10201
joonhunshin4ac60942023-11-15 15:23:39 +000010202 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10203 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10204
sandeepjsb6c87872021-09-27 15:34:44 +000010205 final long identity = Binder.clearCallingIdentity();
10206 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010207 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010208 } finally {
10209 Binder.restoreCallingIdentity(identity);
10210 }
10211 }
10212
10213 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010214 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010215 enforceTelephonyFeatureWithException(callingPackage,
10216 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10217
Jordan Liu7de49fa2018-12-06 14:48:49 -080010218 final long identity = Binder.clearCallingIdentity();
10219 try {
10220 return UiccController.getInstance().getCardIdForDefaultEuicc();
10221 } finally {
10222 Binder.restoreCallingIdentity(identity);
10223 }
10224 }
10225
Pengquan Meng85728fb2018-03-12 16:31:21 -070010226 /**
goneil47ffb6e2018-04-06 15:40:58 -070010227 * A test API to reload the UICC profile.
10228 *
10229 * <p>Requires that the calling app has permission
10230 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10231 * @hide
10232 */
10233 @Override
10234 public void refreshUiccProfile(int subId) {
10235 enforceModifyPermission();
10236
10237 final long identity = Binder.clearCallingIdentity();
10238 try {
10239 Phone phone = getPhone(subId);
10240 if (phone == null) {
10241 return;
10242 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010243 UiccPort uiccPort = phone.getUiccPort();
10244 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010245 return;
10246 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010247 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010248 if (uiccProfile == null) {
10249 return;
10250 }
10251 uiccProfile.refresh();
10252 } finally {
10253 Binder.restoreCallingIdentity(identity);
10254 }
10255 }
10256
10257 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010258 * Returns false if the mobile data is disabled by default, otherwise return true.
10259 */
10260 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010261 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010262 }
10263
10264 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010265 * Returns the default network type for the given {@code subId}, if the default network type is
10266 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10267 */
10268 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010269 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010270 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010271 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10272 return list.get(phoneId);
10273 }
10274 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010275 }
fionaxua13278b2018-03-21 00:08:13 -070010276
10277 @Override
10278 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010279 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010280 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010281
10282 final long identity = Binder.clearCallingIdentity();
10283 try {
10284 final Phone phone = getPhone(subId);
10285 if (phone == null) {
10286 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10287 return;
10288 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010289 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10290 if (cpt != null) {
10291 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10292 }
10293 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010294 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10295 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010296 if (carrierPrivilegeRules == null) {
10297 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10298 } else {
10299 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010301 } finally {
10302 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010303 }
fionaxua13278b2018-03-21 00:08:13 -070010304 }
10305
10306 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010307 public void setCarrierServicePackageOverride(
10308 int subId, String carrierServicePackage, String callingPackage) {
10309 TelephonyPermissions.enforceShellOnly(
10310 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10311
Benedict Wong66477622023-02-03 23:30:57 +000010312 final long identity = Binder.clearCallingIdentity();
10313 try {
10314 final Phone phone = getPhone(subId);
10315 if (phone == null || phone.getSubId() != subId) {
10316 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10317 throw new IllegalArgumentException("No phone for subid");
10318 }
10319 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10320 if (cpt == null) {
10321 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10322 throw new IllegalStateException("No CPT for phone");
10323 }
10324 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10325 } finally {
10326 Binder.restoreCallingIdentity(identity);
10327 }
10328 }
10329
10330 @Override
fionaxua13278b2018-03-21 00:08:13 -070010331 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010332 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010333
10334 final long identity = Binder.clearCallingIdentity();
10335 try {
10336 final Phone phone = getPhone(subId);
10337 if (phone == null) {
10338 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10339 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10340 }
10341 return phone.getCarrierIdListVersion();
10342 } finally {
10343 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010344 }
fionaxua13278b2018-03-21 00:08:13 -070010345 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010346
10347 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010348 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10349 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010350 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010351 mApp, subId, callingPackage, callingFeatureId,
10352 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010353 return -1;
10354 }
10355
10356 final long identity = Binder.clearCallingIdentity();
10357 try {
10358 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10359 } finally {
10360 Binder.restoreCallingIdentity(identity);
10361 }
10362 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010363
10364 @Override
10365 public int getCdmaRoamingMode(int subId) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -080010366 if (mFeatureFlags.cleanupCdma()) return TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
10367
zoey chen7e6d4e52019-12-17 18:18:59 +080010368 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010369 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010370 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010371
joonhunshin4ac60942023-11-15 15:23:39 +000010372 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10373 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10374
Pengquan Menga1bb6272018-09-06 09:59:22 -070010375 final long identity = Binder.clearCallingIdentity();
10376 try {
10377 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10378 } finally {
10379 Binder.restoreCallingIdentity(identity);
10380 }
10381 }
10382
10383 @Override
10384 public boolean setCdmaRoamingMode(int subId, int mode) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -080010385 if (mFeatureFlags.cleanupCdma()) return false;
10386
Pengquan Menga1bb6272018-09-06 09:59:22 -070010387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10388 mApp, subId, "setCdmaRoamingMode");
10389
joonhunshin4ac60942023-11-15 15:23:39 +000010390 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10391 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10392
Pengquan Menga1bb6272018-09-06 09:59:22 -070010393 final long identity = Binder.clearCallingIdentity();
10394 try {
10395 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10396 } finally {
10397 Binder.restoreCallingIdentity(identity);
10398 }
10399 }
10400
10401 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010402 public int getCdmaSubscriptionMode(int subId) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -080010403 if (mFeatureFlags.cleanupCdma()) return TelephonyManager.CDMA_SUBSCRIPTION_UNKNOWN;
10404
Sarah Chinbaab1432020-10-28 13:46:24 -070010405 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010406 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010407 mApp, subId, "getCdmaSubscriptionMode");
10408
joonhunshin4ac60942023-11-15 15:23:39 +000010409 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10410 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10411
Sarah Chinbaab1432020-10-28 13:46:24 -070010412 final long identity = Binder.clearCallingIdentity();
10413 try {
10414 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10415 } finally {
10416 Binder.restoreCallingIdentity(identity);
10417 }
10418 }
10419
10420 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010421 public boolean setCdmaSubscriptionMode(int subId, int mode) {
Tomasz Wasilczykf5858b92024-12-05 15:07:01 -080010422 if (mFeatureFlags.cleanupCdma()) return false;
10423
Pengquan Menga1bb6272018-09-06 09:59:22 -070010424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10425 mApp, subId, "setCdmaSubscriptionMode");
10426
joonhunshin4ac60942023-11-15 15:23:39 +000010427 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10428 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10429
Pengquan Menga1bb6272018-09-06 09:59:22 -070010430 final long identity = Binder.clearCallingIdentity();
10431 try {
10432 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10433 } finally {
10434 Binder.restoreCallingIdentity(identity);
10435 }
10436 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010437
sqianc5eccab2018-10-19 18:46:41 -070010438 @Override
sqian8c685422019-02-22 15:55:18 -080010439 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010440 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010442 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10443 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010444 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10445 }
joonhunshin4ac60942023-11-15 15:23:39 +000010446
10447 enforceTelephonyFeatureWithException(callingPackage,
10448 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10449
sqian11b7a0e2018-12-05 18:48:28 -080010450 final long identity = Binder.clearCallingIdentity();
10451 try {
sqian854d44b2018-12-12 16:48:18 -080010452 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10453 for (Phone phone: PhoneFactory.getPhones()) {
10454 if (phone.getEmergencyNumberTracker() != null
10455 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10456 emergencyNumberListInternal.put(
10457 phone.getSubId(),
10458 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10459 }
sqian11b7a0e2018-12-05 18:48:28 -080010460 }
sqian854d44b2018-12-12 16:48:18 -080010461 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010462 } finally {
10463 Binder.restoreCallingIdentity(identity);
10464 }
sqianc5eccab2018-10-19 18:46:41 -070010465 }
10466
10467 @Override
sqian8c685422019-02-22 15:55:18 -080010468 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010469 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010470 if (!exactMatch) {
10471 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010472 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010473 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010474 }
joonhunshin4ac60942023-11-15 15:23:39 +000010475
Tomasz Wasilczykef763582024-09-17 13:50:32 -070010476 if (!mApp.getResources().getBoolean(
10477 com.android.internal.R.bool.config_force_phone_globals_creation)) {
10478 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10479 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10480 }
joonhunshin4ac60942023-11-15 15:23:39 +000010481
sqian11b7a0e2018-12-05 18:48:28 -080010482 final long identity = Binder.clearCallingIdentity();
10483 try {
sqian854d44b2018-12-12 16:48:18 -080010484 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010485 //Note: we ignore passed in param exactMatch. We can remove it once
10486 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010487 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010488 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010489 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010490 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010491 }
sqian11b7a0e2018-12-05 18:48:28 -080010492 }
10493 return false;
10494 } finally {
10495 Binder.restoreCallingIdentity(identity);
10496 }
10497 }
10498
sqianf4ca7ed2019-01-15 18:32:07 -080010499 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010500 * Start emergency callback mode for GsmCdmaPhone for testing.
10501 */
10502 @Override
10503 public void startEmergencyCallbackMode() {
10504 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10505 "startEmergencyCallbackMode");
10506 enforceModifyPermission();
10507 final long identity = Binder.clearCallingIdentity();
10508 try {
10509 for (Phone phone : PhoneFactory.getPhones()) {
10510 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10511 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10512 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10513 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10514 gsmCdmaPhone.obtainMessage(
10515 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10516 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10517 }
10518 }
10519 } finally {
10520 Binder.restoreCallingIdentity(identity);
10521 }
10522 }
10523
10524 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010525 * Update emergency number list for test mode.
10526 */
10527 @Override
10528 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10529 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10530 "updateEmergencyNumberListTestMode");
10531
10532 final long identity = Binder.clearCallingIdentity();
10533 try {
10534 for (Phone phone: PhoneFactory.getPhones()) {
10535 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10536 if (tracker != null) {
10537 tracker.executeEmergencyNumberTestModeCommand(action, num);
10538 }
10539 }
10540 } finally {
10541 Binder.restoreCallingIdentity(identity);
10542 }
10543 }
10544
10545 /**
10546 * Get the full emergency number list for test mode.
10547 */
10548 @Override
10549 public List<String> getEmergencyNumberListTestMode() {
10550 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10551 "getEmergencyNumberListTestMode");
10552
10553 final long identity = Binder.clearCallingIdentity();
10554 try {
10555 Set<String> emergencyNumbers = new HashSet<>();
10556 for (Phone phone: PhoneFactory.getPhones()) {
10557 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10558 if (tracker != null) {
10559 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10560 emergencyNumbers.add(num.getNumber());
10561 }
10562 }
10563 }
10564 return new ArrayList<>(emergencyNumbers);
10565 } finally {
10566 Binder.restoreCallingIdentity(identity);
10567 }
10568 }
10569
chen xud6b45bd2018-10-30 22:27:10 -070010570 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010571 public int getEmergencyNumberDbVersion(int subId) {
10572 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10573
joonhunshin4ac60942023-11-15 15:23:39 +000010574 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10575 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10576
Shuo Qian3b6ee772019-11-13 17:43:31 -080010577 final long identity = Binder.clearCallingIdentity();
10578 try {
10579 final Phone phone = getPhone(subId);
10580 if (phone == null) {
10581 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10582 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10583 }
10584 return phone.getEmergencyNumberDbVersion();
10585 } finally {
10586 Binder.restoreCallingIdentity(identity);
10587 }
10588 }
10589
10590 @Override
10591 public void notifyOtaEmergencyNumberDbInstalled() {
10592 enforceModifyPermission();
10593
joonhunshin4ac60942023-11-15 15:23:39 +000010594 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10595 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10596
Shuo Qian3b6ee772019-11-13 17:43:31 -080010597 final long identity = Binder.clearCallingIdentity();
10598 try {
10599 for (Phone phone: PhoneFactory.getPhones()) {
10600 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10601 if (tracker != null) {
10602 tracker.updateOtaEmergencyNumberDatabase();
10603 }
10604 }
10605 } finally {
10606 Binder.restoreCallingIdentity(identity);
10607 }
10608 }
10609
10610 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010611 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010612 enforceActiveEmergencySessionPermission();
10613
joonhunshin4ac60942023-11-15 15:23:39 +000010614 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10615 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10616
Shuo Qian3b6ee772019-11-13 17:43:31 -080010617 final long identity = Binder.clearCallingIdentity();
10618 try {
10619 for (Phone phone: PhoneFactory.getPhones()) {
10620 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10621 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010622 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10623 }
10624 }
10625 } finally {
10626 Binder.restoreCallingIdentity(identity);
10627 }
10628 }
10629
10630 @Override
10631 public void resetOtaEmergencyNumberDbFilePath() {
10632 enforceActiveEmergencySessionPermission();
10633
joonhunshin4ac60942023-11-15 15:23:39 +000010634 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10635 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10636
Shuo Qianc373f112020-03-05 17:55:34 -080010637 final long identity = Binder.clearCallingIdentity();
10638 try {
10639 for (Phone phone: PhoneFactory.getPhones()) {
10640 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10641 if (tracker != null) {
10642 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010643 }
10644 }
10645 } finally {
10646 Binder.restoreCallingIdentity(identity);
10647 }
10648 }
10649
10650 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010651 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10652 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10653 Phone phone = getPhone(subId);
10654 if (phone == null) {
10655 return null;
10656 }
10657 final long identity = Binder.clearCallingIdentity();
10658 try {
10659 UiccProfile profile = UiccController.getInstance()
10660 .getUiccProfileForPhone(phone.getPhoneId());
10661 if (profile != null) {
10662 return profile.getCertsFromCarrierPrivilegeAccessRules();
10663 }
10664 } finally {
10665 Binder.restoreCallingIdentity(identity);
10666 }
10667 return null;
10668 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010669
10670 /**
10671 * Enable or disable a modem stack.
10672 */
10673 @Override
10674 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10675 enforceModifyPermission();
10676
joonhunshin4ac60942023-11-15 15:23:39 +000010677 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10678 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10679
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010680 final long identity = Binder.clearCallingIdentity();
10681 try {
10682 Phone phone = PhoneFactory.getPhone(slotIndex);
10683 if (phone == null) {
10684 return false;
10685 } else {
10686 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10687 }
10688 } finally {
10689 Binder.restoreCallingIdentity(identity);
10690 }
10691 }
Michelecea4cf22018-12-21 15:00:11 -080010692
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010693 /**
10694 * Whether a modem stack is enabled or not.
10695 */
10696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010697 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10698 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010699 Phone phone = PhoneFactory.getPhone(slotIndex);
10700 if (phone == null) return false;
10701
10702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010703 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10704 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010705 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10706 }
10707
joonhunshin4ac60942023-11-15 15:23:39 +000010708 enforceTelephonyFeatureWithException(callingPackage,
10709 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10710
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010711 final long identity = Binder.clearCallingIdentity();
10712 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010713 try {
10714 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10715 } catch (NoSuchElementException ex) {
10716 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10717 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010718 } finally {
10719 Binder.restoreCallingIdentity(identity);
10720 }
10721 }
10722
Michelecea4cf22018-12-21 15:00:11 -080010723 @Override
Michele0ea7d782019-03-19 14:58:42 -070010724 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010725 enforceModifyPermission();
10726
joonhunshin4ac60942023-11-15 15:23:39 +000010727 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10728 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10729
Michelecea4cf22018-12-21 15:00:11 -080010730 final long identity = Binder.clearCallingIdentity();
10731 try {
10732 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010733 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010734 .commit();
10735 } finally {
10736 Binder.restoreCallingIdentity(identity);
10737 }
10738 }
10739
10740 @Override
Michele0ea7d782019-03-19 14:58:42 -070010741 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010742 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010744 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10745 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010746 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010747 }
Michelecea4cf22018-12-21 15:00:11 -080010748
joonhunshin4ac60942023-11-15 15:23:39 +000010749 enforceTelephonyFeatureWithException(callingPackage,
10750 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10751
Michelecea4cf22018-12-21 15:00:11 -080010752 final long identity = Binder.clearCallingIdentity();
10753 try {
Michele0ea7d782019-03-19 14:58:42 -070010754 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010755 } finally {
10756 Binder.restoreCallingIdentity(identity);
10757 }
10758 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010759
Michele0ea7d782019-03-19 14:58:42 -070010760 @TelephonyManager.IsMultiSimSupportedResult
10761 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010762 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10763 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10764 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010765 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10766 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010767 }
10768 // Check if the hardware supports multisim functionality. If usage of multisim is not
10769 // supported by the modem, indicate that it is restricted.
10770 PhoneCapability staticCapability =
10771 mPhoneConfigurationManager.getStaticPhoneCapability();
10772 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010773 loge("isMultiSimSupportedInternal: no static configuration available");
10774 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010775 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010776 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010777 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10778 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010779 }
10780 // Check if support of multiple SIMs is restricted by carrier
10781 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010782 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010783 }
10784
Michele0ea7d782019-03-19 14:58:42 -070010785 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010786 }
10787
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010788 /**
10789 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010790 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10791 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10792 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010793 * @param numOfSims number of active sims we want to switch to
10794 */
10795 @Override
10796 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010797 if (numOfSims == 1) {
10798 enforceModifyPermission();
10799 } else {
10800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10801 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10802 }
joonhunshin4ac60942023-11-15 15:23:39 +000010803
10804 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10805 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10806
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010807 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010808
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010809 try {
Michele30b57b22019-03-01 12:01:14 -080010810 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010811 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010812 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10813 return;
10814 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010815 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10816 } finally {
10817 Binder.restoreCallingIdentity(identity);
10818 }
10819 }
10820
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010821 @Override
10822 public boolean isApplicationOnUicc(int subId, int appType) {
10823 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010824
10825 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10826 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10827
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010828 Phone phone = getPhone(subId);
10829 if (phone == null) {
10830 return false;
10831 }
10832 final long identity = Binder.clearCallingIdentity();
10833 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010834 UiccPort uiccPort = phone.getUiccPort();
10835 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010836 return false;
10837 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010838 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010839 if (uiccProfile == null) {
10840 return false;
10841 }
10842 if (TelephonyManager.APPTYPE_SIM <= appType
10843 && appType <= TelephonyManager.APPTYPE_ISIM) {
10844 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10845 }
10846 return false;
10847 } finally {
10848 Binder.restoreCallingIdentity(identity);
10849 }
10850 }
10851
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010852 /**
chen xub4baa772019-04-03 10:23:41 -070010853 * Get whether making changes to modem configurations will trigger reboot.
10854 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010855 */
10856 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010857 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10858 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010859 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010860 mApp, subId, callingPackage, callingFeatureId,
10861 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010862 return false;
10863 }
joonhunshin4ac60942023-11-15 15:23:39 +000010864
10865 enforceTelephonyFeatureWithException(callingPackage,
10866 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10867 "doesSwitchMultiSimConfigTriggerReboot");
10868
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010869 final long identity = Binder.clearCallingIdentity();
10870 try {
10871 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10872 } finally {
10873 Binder.restoreCallingIdentity(identity);
10874 }
10875 }
10876
Nathan Harold29f5f052019-02-15 13:41:57 -080010877 private void updateModemStateMetrics() {
10878 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10879 // TODO: check the state for each modem if the api is ready.
10880 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10881 }
10882
Pengquan Meng3889a572019-01-23 11:16:29 -080010883 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010884 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010885 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010886 // Verify that the callingPackage belongs to the calling UID
10887 mApp.getSystemService(AppOpsManager.class)
10888 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010889
10890 enforceTelephonyFeatureWithException(callingPackage,
10891 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10892
Pengquan Meng3889a572019-01-23 11:16:29 -080010893 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010894 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010895 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010896 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10897 if (slotInfos != null) {
10898 for (int i = 0; i < slotInfos.length; i++) {
10899 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10900 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10901 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10902 portInfo.getLogicalSlotIndex()));
10903 }
10904 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010905 }
10906 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010907 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010908 } finally {
10909 Binder.restoreCallingIdentity(identity);
10910 }
10911 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010912
10913 /**
10914 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010915 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010916 */
jimsunf9ec1622022-09-13 21:18:43 +080010917 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010918 @Override
10919 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010920 return getHalVersion(HAL_SERVICE_RADIO);
10921 }
10922
10923 /**
10924 * Get the HAL Version of a specific service
10925 */
10926 @Override
10927 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010928 Phone phone = getDefaultPhone();
10929 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010930 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010931 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10932 return hv.major * 100 + hv.minor;
10933 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010934
10935 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010936 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010937 *
10938 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010939 */
10940 @Override
sangyun097dcf72024-01-04 10:35:49 +090010941 public @Nullable String getCurrentPackageName() {
Jack Yube3fa442024-09-16 14:39:45 -070010942 if (mFeatureFlags.hsumPackageManager()) {
10943 PackageManager pm = mApp.getBaseContext().createContextAsUser(
10944 Binder.getCallingUserHandle(), 0).getPackageManager();
10945 if (pm == null) return null;
10946 String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid());
10947 return (callingUids == null) ? null : callingUids[0];
10948 }
10949 if (mPackageManager == null) return null;
10950 String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid());
10951 return (callingUids == null) ? null : callingUids[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010952 }
10953
10954 /**
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010955 * @return The calling package name or "phone" if the caller is the phone process. This is done
10956 * because multiple Phone has multiple packages in it and the first element in the array is not
10957 * actually always the caller.
10958 * Note: This is for logging purposes only and should not be used for security checks.
10959 */
10960 private String getCurrentPackageNameOrPhone() {
Jack Yube3fa442024-09-16 14:39:45 -070010961 PackageManager pm;
10962 if (mFeatureFlags.hsumPackageManager()) {
10963 pm = mApp.getBaseContext().createContextAsUser(
10964 Binder.getCallingUserHandle(), 0).getPackageManager();
10965 } else {
10966 pm = mApp.getPackageManager();
10967 }
Brad Ebinger0df4fdf2024-07-19 17:26:12 -070010968 String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid());
10969 if (uidName != null && !uidName.isEmpty()) return uidName;
10970 return getCurrentPackageName();
10971 }
10972
10973 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010974 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10975 * corresponding network requests on a subId.
10976 *
10977 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010978 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010979 * 2) APN is un-metered for this subscription, or
10980 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010981 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010982 *
10983 * @return whether data is allowed for a apn type.
10984 *
10985 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010986 */
10987 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010988 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010989 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10990 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010991
joonhunshin4ac60942023-11-15 15:23:39 +000010992 enforceTelephonyFeatureWithException(callingPackage,
10993 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10994
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010995 // Now that all security checks passes, perform the operation as ourselves.
10996 final long identity = Binder.clearCallingIdentity();
10997 try {
10998 Phone phone = getPhone(subId);
10999 if (phone == null) return false;
11000
Jack Yu27422a52022-03-21 10:38:05 -070011001 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080011002 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070011003 isMetered = phone.getDataNetworkController().getDataConfigManager()
11004 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
11005 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011006 isDataEnabled = (phone.getDataSettingsManager() != null)
11007 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080011008 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070011009 } finally {
11010 Binder.restoreCallingIdentity(identity);
11011 }
11012 }
11013
11014 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070011015 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070011016 enforceReadPrivilegedPermission("isApnMetered");
11017
joonhunshin4ac60942023-11-15 15:23:39 +000011018 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11019 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
11020
Malcolm Chene5ad5792019-04-18 13:51:02 -070011021 // Now that all security checks passes, perform the operation as ourselves.
11022 final long identity = Binder.clearCallingIdentity();
11023 try {
11024 Phone phone = getPhone(subId);
11025 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070011026 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
11027 DataUtils.apnTypeToNetworkCapability(apnType),
11028 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070011029 } finally {
11030 Binder.restoreCallingIdentity(identity);
11031 }
11032 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011033
11034 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080011035 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
11036 int subscriptionId, IBooleanConsumer resultCallback) {
11037 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000011038
11039 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11040 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
11041
Hall Liu73f5d362020-01-20 13:42:00 -080011042 long token = Binder.clearCallingIdentity();
11043 try {
11044 Phone phone = getPhone(subscriptionId);
11045 if (phone == null) {
11046 try {
11047 if (resultCallback != null) {
11048 resultCallback.accept(false);
11049 }
11050 } catch (RemoteException e) {
11051 // ignore
11052 }
11053 return;
11054 }
11055 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
11056 Pair.create(specifiers, (x) -> {
11057 try {
11058 if (resultCallback != null) {
11059 resultCallback.accept(x);
11060 }
11061 } catch (RemoteException e) {
11062 // ignore
11063 }
11064 });
11065 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
11066 } finally {
11067 Binder.restoreCallingIdentity(token);
11068 }
11069 }
11070
11071 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080011072 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
11073 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070011074 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080011075 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000011076
11077 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11078 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
11079
Sarah Chin679c08a2020-11-18 13:39:35 -080011080 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11081 final long identity = Binder.clearCallingIdentity();
11082 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080011083 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
11084 if (result instanceof IllegalStateException) {
11085 throw (IllegalStateException) result;
11086 }
11087 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080011088 if (DBG) log("getSystemSelectionChannels: " + specifiers);
11089 return specifiers;
11090 } finally {
11091 Binder.restoreCallingIdentity(identity);
11092 }
11093 }
11094
11095 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070011096 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080011097 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000011098
11099 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11100 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
11101
Jack Yu8b766fc2022-03-21 09:42:33 -070011102 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080011103 }
11104
11105 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011106 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
11107 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080011108 if (callingPackage == null) {
11109 callingPackage = getCurrentPackageName();
11110 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070011111 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
11112 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070011113 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
11114 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070011115 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
11116 }
11117 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11118 Intent intent = new Intent();
11119 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11120 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11121 // Bring up choose default SMS subscription dialog right now
11122 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11123 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
Jack Yu58d04bd2024-09-10 17:32:39 -070011124 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Brad Ebingera63db5f2019-04-23 16:31:13 -070011125 }
chen xud5ca2d52019-05-28 15:20:57 -070011126
11127 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011128 public void showSwitchToManagedProfileDialog() {
11129 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011130 try {
11131 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11132 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11133 // for work telephony.
11134 Intent intent = new Intent(Intent.ACTION_SENDTO);
11135 intent.setData(Uri.parse("smsto:"));
11136 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011137 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011138 } catch (ActivityNotFoundException e) {
11139 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11140 Intent intent = new Intent();
11141 intent.setClass(mApp, ErrorDialogActivity.class);
11142 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jack Yu58d04bd2024-09-10 17:32:39 -070011143 mApp.startActivityAsUser(intent, UserHandle.CURRENT);
Anthony Alridge70ba5572023-05-02 12:14:14 +000011144 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011145 }
11146
11147 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011148 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011149 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11150 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11151
chen xud5ca2d52019-05-28 15:20:57 -070011152 //TODO investigate if this API should require proper permission check in R b/133791609
11153 final long identity = Binder.clearCallingIdentity();
11154 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011155 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11156 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11157 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11158 return carrierUAProfUrl;
11159 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011160 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11161 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011162 } finally {
11163 Binder.restoreCallingIdentity(identity);
11164 }
11165 }
11166
11167 @Override
11168 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011169 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11170 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11171
chen xud5ca2d52019-05-28 15:20:57 -070011172 //TODO investigate if this API should require proper permission check in R b/133791609
11173 final long identity = Binder.clearCallingIdentity();
11174 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011175 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11176 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11177 if (!TextUtils.isEmpty(carrierUserAgent)) {
11178 return carrierUserAgent;
11179 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011180 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11181 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011182 } finally {
11183 Binder.restoreCallingIdentity(identity);
11184 }
11185 }
Jack Yub07d4972019-05-28 16:12:25 -070011186
11187 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011188 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11189 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011190
joonhunshin4ac60942023-11-15 15:23:39 +000011191 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11192 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11193
Jack Yub07d4972019-05-28 16:12:25 -070011194 final long identity = Binder.clearCallingIdentity();
11195 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011196 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011197 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011198
Ling Maf188d502022-09-16 15:22:36 -070011199 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011200 } finally {
11201 Binder.restoreCallingIdentity(identity);
11202 }
11203 }
11204
11205 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011206 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011207 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011208 enforceModifyPermission();
11209
joonhunshin4ac60942023-11-15 15:23:39 +000011210 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11211 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11212
changbettyd5c246e2019-12-24 15:40:37 +080011213 final long identity = Binder.clearCallingIdentity();
11214 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011215 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011216 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011217
Ling Maf188d502022-09-16 15:22:36 -070011218 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011219 } finally {
11220 Binder.restoreCallingIdentity(identity);
11221 }
11222 }
11223
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011224 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011225 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011226 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11227 * otherwise.
11228 */
11229 @Override
11230 public void setCepEnabled(boolean isCepEnabled) {
11231 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11232
11233 final long identity = Binder.clearCallingIdentity();
11234 try {
11235 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11236 for (Phone phone : PhoneFactory.getPhones()) {
11237 Phone defaultPhone = phone.getImsPhone();
11238 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11239 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11240 ImsPhoneCallTracker imsPhoneCallTracker =
11241 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11242 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11243 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11244 + imsPhone.getMsisdn());
11245 }
11246 }
11247 } finally {
11248 Binder.restoreCallingIdentity(identity);
11249 }
11250 }
allenwtsu46dcc572020-01-08 18:24:03 +080011251
11252 /**
11253 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11254 *
11255 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11256 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11257 * before being read.
11258 */
11259 @Override
11260 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11261 isCompressed) {
11262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11263 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011264 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11265 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11266 }
joonhunshin4ac60942023-11-15 15:23:39 +000011267
11268 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11269 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11270 Binder.getCallingUserHandle())) {
11271 if (!isImsAvailableOnDevice()) {
11272 // ProvisioningManager can not handle ServiceSpecificException.
11273 // Throw the IllegalStateException and annotate ProvisioningManager.
11274 throw new IllegalStateException("IMS not available on device.");
11275 }
11276 } else {
11277 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11278 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11279 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011280 }
11281
11282 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011283 try {
Hui Wang761a6682020-10-31 05:12:53 +000011284 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11285 } finally {
11286 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011287 }
11288 }
zoey chene02881a2019-12-30 16:11:23 +080011289
11290 @Override
11291 public boolean isIccLockEnabled(int subId) {
11292 enforceReadPrivilegedPermission("isIccLockEnabled");
11293
joonhunshin4ac60942023-11-15 15:23:39 +000011294 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11295 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11296
zoey chene02881a2019-12-30 16:11:23 +080011297 // Now that all security checks passes, perform the operation as ourselves.
11298 final long identity = Binder.clearCallingIdentity();
11299 try {
11300 Phone phone = getPhone(subId);
11301 if (phone != null && phone.getIccCard() != null) {
11302 return phone.getIccCard().getIccLockEnabled();
11303 } else {
11304 return false;
11305 }
11306 } finally {
11307 Binder.restoreCallingIdentity(identity);
11308 }
11309 }
11310
11311 /**
11312 * Set the ICC pin lock enabled or disabled.
11313 *
11314 * @return an integer representing the status of IccLock enabled or disabled in the following
11315 * three cases:
11316 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11317 * successfully.
11318 * - Positive number and zero for remaining password attempts.
11319 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11320 *
11321 */
11322 @Override
11323 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11324 enforceModifyPermission();
11325
joonhunshin4ac60942023-11-15 15:23:39 +000011326 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11327 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11328
zoey chene02881a2019-12-30 16:11:23 +080011329 Phone phone = getPhone(subId);
11330 if (phone == null) {
11331 return 0;
11332 }
11333 // Now that all security checks passes, perform the operation as ourselves.
11334 final long identity = Binder.clearCallingIdentity();
11335 try {
11336 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11337 new Pair<Boolean, String>(enabled, password), phone, null);
11338 return attemptsRemaining;
11339
11340 } catch (Exception e) {
11341 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11342 } finally {
11343 Binder.restoreCallingIdentity(identity);
11344 }
11345 return 0;
11346 }
11347
11348 /**
11349 * Change the ICC password used in ICC pin lock.
11350 *
11351 * @return an integer representing the status of IccLock changed in the following three cases:
11352 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11353 * - Positive number and zero for remaining password attempts.
11354 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11355 *
11356 */
11357 @Override
11358 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11359 enforceModifyPermission();
11360
joonhunshin4ac60942023-11-15 15:23:39 +000011361 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11362 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11363
zoey chene02881a2019-12-30 16:11:23 +080011364 Phone phone = getPhone(subId);
11365 if (phone == null) {
11366 return 0;
11367 }
11368 // Now that all security checks passes, perform the operation as ourselves.
11369 final long identity = Binder.clearCallingIdentity();
11370 try {
11371 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11372 new Pair<String, String>(oldPassword, newPassword), phone, null);
11373 return attemptsRemaining;
11374
11375 } catch (Exception e) {
11376 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11377 } finally {
11378 Binder.restoreCallingIdentity(identity);
11379 }
11380 return 0;
11381 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011382
11383 /**
11384 * Request for receiving user activity notification
11385 */
11386 @Override
11387 public void requestUserActivityNotification() {
11388 if (!mNotifyUserActivity.get()
11389 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11390 mNotifyUserActivity.set(true);
11391 }
11392 }
11393
11394 /**
11395 * Called when userActivity is signalled in the power manager.
11396 * This is safe to call from any thread, with any window manager locks held or not.
11397 */
11398 @Override
11399 public void userActivity() {
11400 // ***************************************
11401 // * Inherited from PhoneWindowManager *
11402 // ***************************************
11403 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11404 // WITH ITS LOCKS HELD.
11405 //
11406 // This code must be VERY careful about the locks
11407 // it acquires.
11408 // In fact, the current code acquires way too many,
11409 // and probably has lurking deadlocks.
11410
Jack Yu86374492024-09-16 13:05:44 -070011411 if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
Peter Wangdafb9ac2020-01-15 14:13:38 -080011412 throw new SecurityException("Only the OS may call notifyUserActivity()");
11413 }
11414
11415 if (mNotifyUserActivity.getAndSet(false)) {
11416 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11417 USER_ACTIVITY_NOTIFICATION_DELAY);
11418 }
11419 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011420
11421 @Override
11422 public boolean canConnectTo5GInDsdsMode() {
11423 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11424 }
Jack Yud10cdd42020-09-28 20:28:01 -070011425
11426 @Override
11427 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11428 String callingFeatureId) {
11429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11430 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11431 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11432 }
11433
joonhunshin4ac60942023-11-15 15:23:39 +000011434 enforceTelephonyFeatureWithException(callingPackage,
11435 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11436
Jack Yud10cdd42020-09-28 20:28:01 -070011437 Phone phone = getPhone(subId);
11438 if (phone == null) {
11439 throw new RuntimeException("phone is not available");
11440 }
11441 // Now that all security checks passes, perform the operation as ourselves.
11442 final long identity = Binder.clearCallingIdentity();
11443 try {
11444 return phone.getEquivalentHomePlmns();
11445 } finally {
11446 Binder.restoreCallingIdentity(identity);
11447 }
11448 }
Daniel Bright59e67312020-11-13 11:49:37 -080011449
11450 @Override
11451 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011452 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011453 if (!mApp.getResources().getBoolean(
11454 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11455 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11456 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11457 "isRadioInterfaceCapabilitySupported");
11458 }
joonhunshin4ac60942023-11-15 15:23:39 +000011459
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011460 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011461 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011462 if (radioInterfaceCapabilities == null) {
11463 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011464 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011465 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011466 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011467
Hui Wang641e81c2020-10-12 12:14:23 -070011468 @Override
11469 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11470 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011471 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11472 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11473 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11474 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11475 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011476
11477 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11478 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11479
Hui Wang641e81c2020-10-12 12:14:23 -070011480 if (DBG) {
11481 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11482 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11483 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11484 }
11485
11486 if (!SubscriptionManager.isValidSubscriptionId(subId)
11487 || appType < TelephonyManager.APPTYPE_UNKNOWN
11488 || appType > TelephonyManager.APPTYPE_ISIM
11489 || nafUrl == null || securityProtocol == null || callback == null) {
11490 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11491 if (callback != null) {
11492 try {
11493 callback.onAuthenticationFailure(
11494 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11495 } catch (RemoteException exception) {
11496 log("Fail to notify onAuthenticationFailure due to " + exception);
11497 }
11498 return;
11499 }
11500 }
11501
11502 final long token = Binder.clearCallingIdentity();
11503 try {
11504 getGbaManager(subId).bootstrapAuthenticationRequest(
11505 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011506 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011507 } finally {
11508 Binder.restoreCallingIdentity(token);
11509 }
11510 }
11511
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011512 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011513 * Attempts to set the radio power state for all phones for thermal reason.
11514 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011515 * requested radio power state will actually be set. See {@link
11516 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11517 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011518 * @param enable {@code true} if trying to turn radio on.
11519 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11520 * false}.
11521 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011522 private boolean setRadioPowerForThermal(boolean enable) {
11523 boolean isPhoneAvailable = false;
11524 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11525 Phone phone = PhoneFactory.getPhone(i);
11526 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011527 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011528 isPhoneAvailable = true;
11529 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011530 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011531
11532 // return true if successfully informed the phone object about the thermal radio power
11533 // request.
11534 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011535 }
11536
11537 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011538 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011539 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11540 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11541 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11542 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11543 throw new IllegalArgumentException("modem does not support data throttling");
11544 }
11545
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011546 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11547 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011548 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011549 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11550 }
11551
Sarah Chinecc78c42022-03-31 21:16:48 -070011552 setDataEnabledForReason(
11553 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011554
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011555 if (isDataThrottlingSupported) {
11556 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011557 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011558 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11559 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11560 } else if (thermalMitigationResult
11561 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011562 log("Modem likely does not support data throttling on secondary carrier. Data " +
11563 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11564 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011565 }
11566 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011567 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011568
11569 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011570 }
11571
Jack Nudelman644b91a2021-03-12 14:09:48 -080011572 private static List<String> getThermalMitigationAllowlist(Context context) {
11573 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11574 for (String pckg : context.getResources()
11575 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11576 sThermalMitigationAllowlistedPackages.add(pckg);
11577 }
11578 }
11579
11580 return sThermalMitigationAllowlistedPackages;
11581 }
11582
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011583 private boolean isAnyPhoneInEmergencyState() {
11584 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11585 if (tm.isInEmergencyCall()) {
11586 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11587 return true;
11588 }
11589 for (Phone phone : PhoneFactory.getPhones()) {
11590 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11591 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011592 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11593 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011594 return true;
11595 }
11596 }
11597
11598 return false;
11599 }
11600
Jack Nudelman644b91a2021-03-12 14:09:48 -080011601 /**
11602 * Used by shell commands to add an authorized package name for thermal mitigation.
11603 * @param packageName name of package to be allowlisted
11604 * @param context
11605 */
11606 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11607 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11608 sThermalMitigationAllowlistedPackages.add(packageName);
11609 }
11610
11611 /**
11612 * Used by shell commands to remove an authorized package name for thermal mitigation.
11613 * @param packageName name of package to remove from allowlist
11614 * @param context
11615 */
11616 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11617 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11618 sThermalMitigationAllowlistedPackages.remove(packageName);
11619 }
11620
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011621 /**
11622 * Thermal mitigation request to control functionalities at modem.
11623 *
11624 * @param subId the id of the subscription.
11625 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011626 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011627 *
11628 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11629 */
11630 @Override
11631 @ThermalMitigationResult
11632 public int sendThermalMitigationRequest(
11633 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011634 ThermalMitigationRequest thermalMitigationRequest,
11635 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011636 enforceModifyPermission();
11637
Jack Nudelman644b91a2021-03-12 14:09:48 -080011638 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011639
11640 enforceTelephonyFeatureWithException(callingPackage,
11641 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11642
Jack Nudelman644b91a2021-03-12 14:09:48 -080011643 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11644 .contains(callingPackage)) {
11645 throw new SecurityException("Calling package must be configured in the device config. "
11646 + "calling package: " + callingPackage);
11647 }
11648
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011649 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11650 final long identity = Binder.clearCallingIdentity();
11651
11652 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11653 try {
11654 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11655 switch (thermalMitigationAction) {
11656 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11657 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011658 handleDataThrottlingRequest(subId,
11659 thermalMitigationRequest.getDataThrottlingRequest(),
11660 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011661 break;
11662 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11663 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11664 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11665 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11666 }
11667
11668 // Ensure that radio is on. If not able to power on due to phone being
11669 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011670 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011671 thermalMitigationResult =
11672 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11673 break;
11674 }
11675
11676 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011677 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011678 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11679 break;
11680 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11681 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11682 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11683 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11684 }
11685
11686 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11687 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011688 Phone phone = getPhone(subId);
11689 if (phone == null) {
11690 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011691 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011692 break;
11693 }
11694
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011695 TelephonyConnectionService service =
11696 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011697 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011698 Log.e(LOG_TAG, "An emergency call is pending");
11699 thermalMitigationResult =
11700 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11701 break;
11702 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011703 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011704 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011705 break;
11706 }
11707 } else {
11708 thermalMitigationResult =
11709 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11710 break;
11711 }
11712
11713 // Turn radio off. If not able to power off due to phone being unavailable,
11714 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011715 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011716 thermalMitigationResult =
11717 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11718 break;
11719 }
11720 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011721 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011722 break;
11723 default:
11724 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11725 + "not exist. Requested action: " + thermalMitigationAction);
11726 }
11727 } catch (IllegalArgumentException e) {
11728 throw e;
11729 } catch (Exception e) {
11730 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11731 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11732 } finally {
11733 Binder.restoreCallingIdentity(identity);
11734 }
11735
11736 if (DBG) {
11737 log("thermalMitigationRequest returning with thermalMitigationResult: "
11738 + thermalMitigationResult);
11739 }
11740
11741 return thermalMitigationResult;
11742 }
Hui Wang641e81c2020-10-12 12:14:23 -070011743
11744 /**
11745 * Set the GbaService Package Name that Telephony will bind to.
11746 *
11747 * @param subId The sim that the GbaService is associated with.
11748 * @param packageName The name of the package to be replaced with.
11749 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11750 */
11751 @Override
11752 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11753 enforceModifyPermission();
Jack Yu02533f12024-10-03 18:44:32 -070011754 int userId = ActivityManager.getCurrentUser();
Hui Wang641e81c2020-10-12 12:14:23 -070011755 final long identity = Binder.clearCallingIdentity();
11756 try {
Jack Yu02533f12024-10-03 18:44:32 -070011757 return getGbaManager(subId).overrideServicePackage(packageName, userId);
Hui Wang641e81c2020-10-12 12:14:23 -070011758 } finally {
11759 Binder.restoreCallingIdentity(identity);
11760 }
11761 }
11762
11763 /**
11764 * Return the package name of the currently bound GbaService.
11765 *
11766 * @param subId The sim that the GbaService is associated with.
11767 * @return the package name of the GbaService configuration, null if GBA is not supported.
11768 */
11769 @Override
11770 public String getBoundGbaService(int subId) {
11771 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11772
11773 final long identity = Binder.clearCallingIdentity();
11774 try {
11775 return getGbaManager(subId).getServicePackage();
11776 } finally {
11777 Binder.restoreCallingIdentity(identity);
11778 }
11779 }
11780
11781 /**
11782 * Set the release time for telephony to unbind GbaService.
11783 *
11784 * @param subId The sim that the GbaService is associated with.
11785 * @param interval The release time to unbind GbaService by millisecond.
11786 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11787 */
11788 @Override
11789 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11790 enforceModifyPermission();
11791
11792 final long identity = Binder.clearCallingIdentity();
11793 try {
11794 return getGbaManager(subId).overrideReleaseTime(interval);
11795 } finally {
11796 Binder.restoreCallingIdentity(identity);
11797 }
11798 }
11799
11800 /**
11801 * Return the release time for telephony to unbind GbaService.
11802 *
11803 * @param subId The sim that the GbaService is associated with.
11804 * @return The release time to unbind GbaService by millisecond.
11805 */
11806 @Override
11807 public int getGbaReleaseTime(int subId) {
11808 enforceReadPrivilegedPermission("getGbaReleaseTime");
11809
11810 final long identity = Binder.clearCallingIdentity();
11811 try {
11812 return getGbaManager(subId).getReleaseTime();
11813 } finally {
11814 Binder.restoreCallingIdentity(identity);
11815 }
11816 }
11817
11818 private GbaManager getGbaManager(int subId) {
11819 GbaManager instance = GbaManager.getInstance(subId);
11820 if (instance == null) {
11821 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11822 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11823 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11824 }
11825 return instance;
11826 }
Hui Wang761a6682020-10-31 05:12:53 +000011827
11828 /**
11829 * indicate whether the device and the carrier can support
11830 * RCS VoLTE single registration.
11831 */
11832 @Override
11833 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011834 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11835 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11836 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11837 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011838
11839 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11840 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11841 }
11842
11843 final long identity = Binder.clearCallingIdentity();
11844 try {
11845 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11846 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011847 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11848 if (isCapable != null) {
11849 return isCapable;
11850 }
Hui Wang761a6682020-10-31 05:12:53 +000011851 }
Hui Wang67af90e2021-06-04 16:57:15 -070011852 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11853 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011854 } finally {
11855 Binder.restoreCallingIdentity(identity);
11856 }
11857 }
11858
11859 /**
11860 * Register RCS provisioning callback.
11861 */
11862 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011863 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011864 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011865 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011866 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011867 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11868 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011869
11870 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11871 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11872 }
joonhunshin4ac60942023-11-15 15:23:39 +000011873 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11874 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11875 Binder.getCallingUserHandle())) {
11876 if (!isImsAvailableOnDevice()) {
11877 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11878 "IMS not available on device.");
11879 }
11880 } else {
11881 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11882 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011883 }
11884
11885 final long identity = Binder.clearCallingIdentity();
11886 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011887 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011888 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011889 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11890 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011891 }
Hui Wang761a6682020-10-31 05:12:53 +000011892 } finally {
11893 Binder.restoreCallingIdentity(identity);
11894 }
11895 }
11896
11897 /**
11898 * Unregister RCS provisioning callback.
11899 */
11900 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011901 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011902 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011903 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011904 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011905 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11906 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011907
11908 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11909 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11910 }
joonhunshin4ac60942023-11-15 15:23:39 +000011911
11912 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11913 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11914 Binder.getCallingUserHandle())) {
11915 if (!isImsAvailableOnDevice()) {
11916 // operation failed silently
11917 Rlog.w(LOG_TAG, "IMS not available on device.");
11918 return;
11919 }
11920 } else {
11921 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11922 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11923 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011924 }
11925
11926 final long identity = Binder.clearCallingIdentity();
11927 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011928 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011929 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011930 } finally {
11931 Binder.restoreCallingIdentity(identity);
11932 }
11933 }
11934
11935 /**
11936 * trigger RCS reconfiguration.
11937 */
11938 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011939 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11940 "triggerRcsReconfiguration",
11941 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011942
11943 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11944 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11945 }
joonhunshin4ac60942023-11-15 15:23:39 +000011946 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11947 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11948 Binder.getCallingUserHandle())) {
11949 if (!isImsAvailableOnDevice()) {
11950 // ProvisioningManager can not handle ServiceSpecificException.
11951 // Throw the IllegalStateException and annotate ProvisioningManager.
11952 throw new IllegalStateException("IMS not available on device.");
11953 }
11954 } else {
11955 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11956 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011957 }
11958
11959 final long identity = Binder.clearCallingIdentity();
11960 try {
11961 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11962 } finally {
11963 Binder.restoreCallingIdentity(identity);
11964 }
11965 }
11966
11967 /**
11968 * Provide the client configuration parameters of the RCS application.
11969 */
11970 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011971 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11972 "setRcsClientConfiguration",
11973 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011974
11975 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11976 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11977 }
joonhunshin4ac60942023-11-15 15:23:39 +000011978 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11979 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11980 Binder.getCallingUserHandle())) {
11981 if (!isImsAvailableOnDevice()) {
11982 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11983 "IMS not available on device.");
11984 }
11985 } else {
11986 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11987 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011988 }
11989
11990 final long identity = Binder.clearCallingIdentity();
11991
11992 try {
11993 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11994 if (configBinder == null) {
11995 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011996 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11997 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011998 } else {
11999 configBinder.setRcsClientConfiguration(rcc);
12000 }
joonhunshin3e154242021-09-17 06:33:39 +000012001
12002 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
12003 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000012004 } catch (RemoteException e) {
12005 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070012006 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
12007 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000012008 } finally {
12009 Binder.restoreCallingIdentity(identity);
12010 }
12011 }
12012
12013 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080012014 * Enables or disables the test mode for RCS VoLTE single registration.
12015 */
12016 @Override
12017 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
12018 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12019 "setRcsSingleRegistrationTestModeEnabled");
12020
12021 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
12022 }
12023
12024 /**
12025 * Gets the test mode for RCS VoLTE single registration.
12026 */
12027 @Override
12028 public boolean getRcsSingleRegistrationTestModeEnabled() {
12029 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12030 "getRcsSingleRegistrationTestModeEnabled");
12031
12032 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
12033 }
12034
12035 /**
Hui Wang761a6682020-10-31 05:12:53 +000012036 * Overrides the config of RCS VoLTE single registration enabled for the device.
12037 */
12038 @Override
12039 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
12040 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12041 "setDeviceSingleRegistrationEnabledOverride");
12042 enforceModifyPermission();
12043
12044 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12045 : Boolean.parseBoolean(enabledStr);
12046 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000012047 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000012048 }
12049
12050 /**
Tyler Gunn92479152021-01-20 16:30:10 -080012051 * Sends a device to device communication message. Only usable via shell.
12052 * @param message message to send.
12053 * @param value message value.
12054 */
12055 @Override
12056 public void sendDeviceToDeviceMessage(int message, int value) {
12057 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080012058 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080012059 enforceModifyPermission();
12060
12061 final long identity = Binder.clearCallingIdentity();
12062 try {
12063 TelephonyConnectionService service =
12064 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12065 if (service == null) {
12066 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
12067 return;
12068 }
12069 service.sendTestDeviceToDeviceMessage(message, value);
12070 } finally {
12071 Binder.restoreCallingIdentity(identity);
12072 }
12073 }
12074
Tyler Gunnbabbda02021-02-10 11:05:02 -080012075 /**
12076 * Sets the specified device to device transport active.
12077 * @param transport The transport to set active.
12078 */
12079 @Override
12080 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
12081 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12082 "setActiveDeviceToDeviceTransport");
12083 enforceModifyPermission();
12084
12085 final long identity = Binder.clearCallingIdentity();
12086 try {
12087 TelephonyConnectionService service =
12088 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
12089 if (service == null) {
12090 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
12091 return;
12092 }
12093 service.setActiveDeviceToDeviceTransport(transport);
12094 } finally {
12095 Binder.restoreCallingIdentity(identity);
12096 }
12097 }
Tyler Gunn92479152021-01-20 16:30:10 -080012098
Tyler Gunnd4339262021-05-03 14:46:49 -070012099 @Override
12100 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
12101 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12102 "setDeviceToDeviceForceEnabled");
12103
12104 final long identity = Binder.clearCallingIdentity();
12105 try {
12106 Arrays.stream(PhoneFactory.getPhones()).forEach(
12107 p -> {
12108 Phone thePhone = p.getImsPhone();
12109 if (thePhone != null && thePhone instanceof ImsPhone) {
12110 ImsPhone imsPhone = (ImsPhone) thePhone;
12111 CallTracker tracker = imsPhone.getCallTracker();
12112 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
12113 ImsPhoneCallTracker imsPhoneCallTracker =
12114 (ImsPhoneCallTracker) tracker;
12115 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
12116 }
12117 }
12118 }
12119 );
12120 } finally {
12121 Binder.restoreCallingIdentity(identity);
12122 }
12123 }
12124
Tyler Gunn92479152021-01-20 16:30:10 -080012125 /**
Hui Wang761a6682020-10-31 05:12:53 +000012126 * Gets the config of RCS VoLTE single registration enabled for the device.
12127 */
12128 @Override
12129 public boolean getDeviceSingleRegistrationEnabled() {
12130 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12131 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12132 }
12133
12134 /**
12135 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12136 */
12137 @Override
12138 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12139 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12140 "setCarrierSingleRegistrationEnabledOverride");
12141 enforceModifyPermission();
12142
12143 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12144 : Boolean.parseBoolean(enabledStr);
12145 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12146 subId, enabled);
12147 }
12148
12149 /**
12150 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12151 */
12152 @Override
12153 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12154 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12155 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12156 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012157
12158 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012159 * Overrides the ims feature validation result
12160 */
12161 @Override
12162 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12163 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12164 "setImsFeatureValidationOverride");
12165
12166 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12167 : Boolean.parseBoolean(enabledStr);
12168 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12169 subId, enabled);
12170 }
12171
12172 /**
12173 * Gets the ims feature validation override value
12174 */
12175 @Override
12176 public boolean getImsFeatureValidationOverride(int subId) {
12177 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12178 "getImsFeatureValidationOverride");
12179 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12180 }
12181
12182 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012183 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12184 * their mobile plan.
12185 */
12186 @Override
12187 public String getMobileProvisioningUrl() {
12188 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12189 final long identity = Binder.clearCallingIdentity();
12190 try {
12191 return getDefaultPhone().getMobileProvisioningUrl();
12192 } finally {
12193 Binder.restoreCallingIdentity(identity);
12194 }
12195 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012196
James.cf Linbcdf8b32021-01-14 16:44:13 +080012197 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012198 * Get the EAB contact from the EAB database.
12199 */
12200 @Override
12201 public String getContactFromEab(String contact) {
12202 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12203 enforceModifyPermission();
12204 final long identity = Binder.clearCallingIdentity();
12205 try {
12206 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12207 } finally {
12208 Binder.restoreCallingIdentity(identity);
12209 }
12210 }
12211
12212 /**
Calvin Pana1434322021-07-01 19:27:01 +080012213 * Get the EAB capability from the EAB database.
12214 */
12215 @Override
12216 public String getCapabilityFromEab(String contact) {
12217 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12218 enforceModifyPermission();
12219 final long identity = Binder.clearCallingIdentity();
12220 try {
12221 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12222 } finally {
12223 Binder.restoreCallingIdentity(identity);
12224 }
12225 }
12226
12227 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012228 * Remove the EAB contacts from the EAB database.
12229 */
12230 @Override
12231 public int removeContactFromEab(int subId, String contacts) {
12232 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12233 enforceModifyPermission();
12234 final long identity = Binder.clearCallingIdentity();
12235 try {
12236 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12237 } finally {
12238 Binder.restoreCallingIdentity(identity);
12239 }
12240 }
12241
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012242 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012243 public boolean getDeviceUceEnabled() {
12244 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12245 final long identity = Binder.clearCallingIdentity();
12246 try {
12247 return mApp.getDeviceUceEnabled();
12248 } finally {
12249 Binder.restoreCallingIdentity(identity);
12250 }
12251 }
12252
12253 @Override
12254 public void setDeviceUceEnabled(boolean isEnabled) {
12255 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12256 final long identity = Binder.clearCallingIdentity();
12257 try {
12258 mApp.setDeviceUceEnabled(isEnabled);
12259 } finally {
12260 Binder.restoreCallingIdentity(identity);
12261 }
12262 }
12263
Brad Ebinger14d467f2021-02-12 06:18:28 +000012264 /**
12265 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12266 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12267 */
12268 // Used for SHELL command only right now.
12269 @Override
12270 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12271 List<String> featureTags) {
12272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12273 "addUceRegistrationOverrideShell");
12274 final long identity = Binder.clearCallingIdentity();
12275 try {
12276 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12277 new ArraySet<>(featureTags));
12278 } catch (ImsException e) {
12279 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12280 } finally {
12281 Binder.restoreCallingIdentity(identity);
12282 }
12283 }
12284
12285 /**
12286 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12287 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12288 */
12289 // Used for SHELL command only right now.
12290 @Override
12291 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12292 List<String> featureTags) {
12293 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12294 "removeUceRegistrationOverrideShell");
12295 final long identity = Binder.clearCallingIdentity();
12296 try {
12297 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12298 new ArraySet<>(featureTags));
12299 } catch (ImsException e) {
12300 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12301 } finally {
12302 Binder.restoreCallingIdentity(identity);
12303 }
12304 }
12305
12306 /**
12307 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12308 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12309 */
12310 // Used for SHELL command only right now.
12311 @Override
12312 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12313 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12314 "clearUceRegistrationOverrideShell");
12315 final long identity = Binder.clearCallingIdentity();
12316 try {
12317 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12318 } catch (ImsException e) {
12319 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12320 } finally {
12321 Binder.restoreCallingIdentity(identity);
12322 }
12323 }
12324
12325 /**
12326 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12327 */
12328 // Used for SHELL command only right now.
12329 @Override
12330 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12331 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12332 "getLatestRcsContactUceCapabilityShell");
12333 final long identity = Binder.clearCallingIdentity();
12334 try {
12335 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12336 } catch (ImsException e) {
12337 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12338 } finally {
12339 Binder.restoreCallingIdentity(identity);
12340 }
12341 }
12342
12343 /**
12344 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12345 * device does not have an active PUBLISH.
12346 */
12347 // Used for SHELL command only right now.
12348 @Override
12349 public String getLastUcePidfXmlShell(int subId) {
12350 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12351 final long identity = Binder.clearCallingIdentity();
12352 try {
12353 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12354 } catch (ImsException e) {
12355 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12356 } finally {
12357 Binder.restoreCallingIdentity(identity);
12358 }
12359 }
12360
James.cf Line8713a42021-04-29 16:04:26 +080012361 /**
12362 * Remove UCE requests cannot be sent to the network status.
12363 */
12364 // Used for SHELL command only right now.
12365 @Override
12366 public boolean removeUceRequestDisallowedStatus(int subId) {
12367 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12368 final long identity = Binder.clearCallingIdentity();
12369 try {
12370 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12371 } catch (ImsException e) {
12372 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12373 } finally {
12374 Binder.restoreCallingIdentity(identity);
12375 }
12376 }
12377
James.cf Lin18bb9002021-05-25 01:37:38 +080012378 /**
12379 * Remove UCE requests cannot be sent to the network status.
12380 */
12381 // Used for SHELL command only.
12382 @Override
12383 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12384 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12385 final long identity = Binder.clearCallingIdentity();
12386 try {
12387 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12388 } catch (ImsException e) {
12389 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12390 } finally {
12391 Binder.restoreCallingIdentity(identity);
12392 }
12393 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012394
James.cf Lin4b784aa2021-01-31 03:25:15 +080012395 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012396 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12397 String callingPackage) {
12398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12399 mApp, subId, "setSignalStrengthUpdateRequest");
12400
joonhunshin4ac60942023-11-15 15:23:39 +000012401 enforceTelephonyFeatureWithException(callingPackage,
12402 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12403
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012404 final int callingUid = Binder.getCallingUid();
12405 // Verify that tha callingPackage belongs to the calling UID
12406 mApp.getSystemService(AppOpsManager.class)
12407 .checkPackage(callingUid, callingPackage);
12408
Rambo Wang3607f502021-02-01 21:51:40 -080012409 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012410
12411 final long identity = Binder.clearCallingIdentity();
12412 try {
12413 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12414 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12415
12416 if (result instanceof IllegalStateException) {
12417 throw (IllegalStateException) result;
12418 }
12419 } finally {
12420 Binder.restoreCallingIdentity(identity);
12421 }
12422 }
12423
12424 @Override
12425 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12426 String callingPackage) {
12427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12428 mApp, subId, "clearSignalStrengthUpdateRequest");
12429
joonhunshin4ac60942023-11-15 15:23:39 +000012430 enforceTelephonyFeatureWithException(callingPackage,
12431 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12432
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012433 final int callingUid = Binder.getCallingUid();
12434 // Verify that tha callingPackage belongs to the calling UID
12435 mApp.getSystemService(AppOpsManager.class)
12436 .checkPackage(callingUid, callingPackage);
12437
12438 final long identity = Binder.clearCallingIdentity();
12439 try {
12440 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12441 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12442
12443 if (result instanceof IllegalStateException) {
12444 throw (IllegalStateException) result;
12445 }
12446 } finally {
12447 Binder.restoreCallingIdentity(identity);
12448 }
12449 }
12450
Rambo Wang3607f502021-02-01 21:51:40 -080012451 private static void validateSignalStrengthUpdateRequest(Context context,
12452 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012453 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012454 // phone/system process do not have further restriction on request
12455 return;
12456 }
12457
12458 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012459 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012460 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012461 context.enforceCallingOrSelfPermission(
12462 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12463 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012464 }
12465
12466 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012467 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012468 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012469 || info.isEnabled()) {
12470 throw new IllegalArgumentException(
12471 "Only system can set hide fields in SignalThresholdInfo");
12472 }
12473
12474 // Thresholds length for each RAN need in range. This has been validated in
12475 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12476 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12477 final int[] thresholds = info.getThresholds();
12478 Objects.requireNonNull(thresholds);
12479 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12480 || thresholds.length
12481 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12482 throw new IllegalArgumentException(
12483 "thresholds length is out of range: " + thresholds.length);
12484 }
12485 }
12486 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012487
12488 /**
12489 * Gets the current phone capability.
12490 *
12491 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12492 * @return the PhoneCapability which describes the data connection capability of modem.
12493 * It's used to evaluate possible phone config change, for example from single
12494 * SIM device to multi-SIM device.
12495 */
12496 @Override
12497 public PhoneCapability getPhoneCapability() {
12498 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012499
12500 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12501 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12502
SongFerngWang8236caa2021-01-17 21:51:44 +080012503 final long identity = Binder.clearCallingIdentity();
12504 try {
12505 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12506 } finally {
12507 Binder.restoreCallingIdentity(identity);
12508 }
12509 }
Michele Berionne5e411512020-11-13 02:36:59 +000012510
12511 /**
12512 * Prepare TelephonyManager for an unattended reboot. The reboot is
12513 * required to be done shortly after the API is invoked.
12514 */
12515 @Override
12516 @TelephonyManager.PrepareUnattendedRebootResult
12517 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012518 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012519 enforceRebootPermission();
12520
joonhunshin4ac60942023-11-15 15:23:39 +000012521 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12522 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12523
Michele Berionne5e411512020-11-13 02:36:59 +000012524 final long identity = Binder.clearCallingIdentity();
12525 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012526 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012527 } finally {
12528 Binder.restoreCallingIdentity(identity);
12529 }
12530 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012531
12532 /**
12533 * Request to get the current slicing configuration including URSP rules and
12534 * NSSAIs (configured, allowed and rejected).
12535 *
12536 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12537 */
12538 @Override
12539 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012540 TelephonyPermissions
12541 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12542 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012543
joonhunshin4ac60942023-11-15 15:23:39 +000012544 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12545 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12546 "getSlicingConfig");
12547
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012548 final long identity = Binder.clearCallingIdentity();
12549 try {
12550 Phone phone = getDefaultPhone();
12551 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12552 } finally {
12553 Binder.restoreCallingIdentity(identity);
12554 }
12555 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012556
12557 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012558 * Check whether the given premium capability is available for purchase from the carrier.
12559 *
12560 * @param capability The premium capability to check.
12561 * @param subId The subId to check the premium capability for.
12562 *
12563 * @return Whether the given premium capability is available to purchase.
12564 */
12565 @Override
12566 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12567 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12568 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12569 log("Premium capability "
12570 + TelephonyManager.convertPremiumCapabilityToString(capability)
12571 + " is not available for purchase due to missing permissions.");
12572 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12573 + "permission READ_BASIC_PHONE_STATE.");
12574 }
12575
joonhunshin4ac60942023-11-15 15:23:39 +000012576 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12577 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12578
Sarah Chin2ec39f62022-08-31 17:03:26 -070012579 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012580 if (phone == null) {
12581 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12582 return false;
12583 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012584 final long identity = Binder.clearCallingIdentity();
12585 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012586 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012587 .isPremiumCapabilityAvailableForPurchase(capability);
12588 } finally {
12589 Binder.restoreCallingIdentity(identity);
12590 }
12591 }
12592
12593 /**
12594 * Purchase the given premium capability from the carrier.
12595 *
12596 * @param capability The premium capability to purchase.
12597 * @param callback The result of the purchase request.
12598 * @param subId The subId to purchase the premium capability for.
12599 */
12600 @Override
12601 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12602 log("purchasePremiumCapability: capability="
12603 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12604 + getCurrentPackageName());
12605
12606 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12607 mApp, "purchasePremiumCapability")) {
12608 log("purchasePremiumCapability "
12609 + TelephonyManager.convertPremiumCapabilityToString(capability)
12610 + " failed due to missing permissions.");
12611 throw new SecurityException("purchasePremiumCapability requires permission "
12612 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012613 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12614 mApp, "purchasePremiumCapability")) {
12615 log("purchasePremiumCapability "
12616 + TelephonyManager.convertPremiumCapabilityToString(capability)
12617 + " failed due to missing permissions.");
12618 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012619 }
12620
joonhunshin4ac60942023-11-15 15:23:39 +000012621 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12622 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12623
Sarah Chin2ec39f62022-08-31 17:03:26 -070012624 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012625 if (phone == null) {
12626 try {
12627 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12628 callback.accept(result);
12629 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12630 } catch (RemoteException e) {
12631 String logStr = "Purchase premium capability "
12632 + TelephonyManager.convertPremiumCapabilityToString(capability)
12633 + " failed due to RemoteException handling null phone: " + e;
12634 if (DBG) log(logStr);
12635 AnomalyReporter.reportAnomaly(
12636 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12637 }
12638 return;
12639 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012640
12641 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012642 try {
Jack Yube3fa442024-09-16 14:39:45 -070012643 if (mFeatureFlags.hsumPackageManager()) {
12644 callingProcess = mApp.getPackageManager().getApplicationInfoAsUser(
12645 getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName;
12646 } else {
12647 callingProcess = mApp.getPackageManager().getApplicationInfo(
12648 getCurrentPackageName(), 0).processName;
12649 }
Sarah Chin71b3a852022-09-28 15:54:19 -070012650 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012651 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012652 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012653
12654 boolean isVisible = false;
12655 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12656 if (am != null) {
12657 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12658 if (processes != null) {
12659 for (ActivityManager.RunningAppProcessInfo process : processes) {
12660 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012661 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012662 if (process.processName.equals(callingProcess) && process.importance
12663 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12664 isVisible = true;
12665 break;
12666 }
12667 }
12668 }
12669 }
12670
12671 if (!isVisible) {
12672 try {
12673 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12674 callback.accept(result);
12675 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12676 } catch (RemoteException e) {
12677 String logStr = "Purchase premium capability "
12678 + TelephonyManager.convertPremiumCapabilityToString(capability)
12679 + " failed due to RemoteException handling background application: " + e;
12680 if (DBG) log(logStr);
12681 AnomalyReporter.reportAnomaly(
12682 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12683 }
12684 return;
12685 }
12686
Sarah Chin71b3a852022-09-28 15:54:19 -070012687 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012688 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012689 }
12690
12691 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012692 * Register an IMS connection state callback
12693 */
12694 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012695 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12696 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012697 if (feature == ImsFeature.FEATURE_MMTEL) {
12698 // ImsMmTelManager
12699 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12700 TelephonyPermissions
12701 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12702 mApp, subId, "registerImsStateCallback");
12703 } else if (feature == ImsFeature.FEATURE_RCS) {
12704 // ImsRcsManager or SipDelegateManager
12705 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12706 Binder.getCallingUid(), "registerImsStateCallback",
12707 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12708 Manifest.permission.READ_PRECISE_PHONE_STATE,
12709 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12710 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12711 }
12712
12713 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12714 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12715 "IMS not available on device.");
12716 }
12717
12718 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12719 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12720 }
12721
12722 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12723 if (controller == null) {
12724 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12725 "IMS not available on device.");
12726 }
12727
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012728 if (callingPackage == null) {
12729 callingPackage = getCurrentPackageName();
12730 }
12731
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012732 final long token = Binder.clearCallingIdentity();
12733 try {
12734 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012735 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012736 } catch (ImsException e) {
12737 throw new ServiceSpecificException(e.getCode());
12738 } finally {
12739 Binder.restoreCallingIdentity(token);
12740 }
12741 }
12742
12743 /**
12744 * Unregister an IMS connection state callback
12745 */
12746 @Override
12747 public void unregisterImsStateCallback(IImsStateCallback cb) {
12748 final long token = Binder.clearCallingIdentity();
12749 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12750 if (controller == null) {
12751 return;
12752 }
12753 try {
12754 controller.unregisterImsStateCallback(cb);
12755 } finally {
12756 Binder.restoreCallingIdentity(token);
12757 }
12758 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012759
12760 /**
12761 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12762 *
12763 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012764 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012765 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012766 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012767 * If there is current registered network this value will be same as the registered cell
12768 * identity. If the device goes out of service the previous cell identity is cached and
12769 * will be returned. If the cache age of the Cell identity is more than 24 hours
12770 * it will be cleared and null will be returned.
12771 *
12772 */
12773 @Override
12774 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12775 String callingFeatureId) {
12776 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12777 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12778 LocationAccessPolicy.checkLocationPermission(mApp,
12779 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12780 .setCallingPackage(callingPackage)
12781 .setCallingFeatureId(callingFeatureId)
12782 .setCallingPid(Binder.getCallingPid())
12783 .setCallingUid(Binder.getCallingUid())
12784 .setMethod("getLastKnownCellIdentity")
12785 .setLogAsInfo(true)
12786 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12787 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12788 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12789 .build());
12790
12791 boolean hasFinePermission =
12792 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12793 if (!hasFinePermission
12794 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12795 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012796 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012797 }
12798
12799 final long identity = Binder.clearCallingIdentity();
12800 try {
Ling Mac28f0212023-03-24 16:07:15 -070012801 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012802 if (sst == null) return null;
12803 return sst.getLastKnownCellIdentity();
12804 } finally {
12805 Binder.restoreCallingIdentity(identity);
12806 }
12807 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012808
jimsun3b9ccac2021-10-26 15:01:23 +080012809 /**
12810 * Sets the modem service class Name that Telephony will bind to.
12811 *
12812 * @param serviceName The class name of the modem service.
12813 * @return true if the operation is succeed, otherwise false.
12814 */
12815 public boolean setModemService(String serviceName) {
12816 Log.d(LOG_TAG, "setModemService - " + serviceName);
12817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012819 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12820 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012821 return mPhoneConfigurationManager.setModemService(serviceName);
12822 }
12823
12824 /**
12825 * Return the class name of the currently bounded modem service.
12826 *
12827 * @return the class name of the modem service.
12828 */
12829 public String getModemService() {
12830 String result;
12831 Log.d(LOG_TAG, "getModemService");
12832 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12833 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012834 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012835 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12836 "getModemService");
12837 result = mPhoneConfigurationManager.getModemService();
12838 Log.d(LOG_TAG, "result = " + result);
12839 return result;
12840 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012841
Hakjun Choi3ee81112023-12-19 15:40:58 +000012842 /**
12843 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12844 * including carrier config, entitlement server, and config update.
12845 *
12846 * @param subId subId The subscription ID of the carrier.
12847 *
12848 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12849 * be returned.
12850 *
12851 * @throws SecurityException if the caller doesn't have the required permission.
12852 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012853 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12854 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012855 final long identity = Binder.clearCallingIdentity();
12856 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012857 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012858 } finally {
12859 Binder.restoreCallingIdentity(identity);
12860 }
12861 }
12862
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012863 @Override
12864 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12865 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12866 mApp.enforceCallingOrSelfPermission(
12867 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12868 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12869
12870 final long identity = Binder.clearCallingIdentity();
12871 try {
12872 Phone phone = getPhone(subId);
12873 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012874 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12875 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012876 phone.setVoiceServiceStateOverride(hasService);
12877 } finally {
12878 Binder.restoreCallingIdentity(identity);
12879 }
12880 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012881
12882 /**
12883 * set removable eSIM as default eUICC.
12884 *
12885 * @hide
12886 */
12887 @Override
12888 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12889 enforceModifyPermission();
12890 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12891
12892 final long identity = Binder.clearCallingIdentity();
12893 try {
12894 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12895 } finally {
12896 Binder.restoreCallingIdentity(identity);
12897 }
12898 }
12899
12900 /**
12901 * Returns whether the removable eSIM is default eUICC or not.
12902 *
12903 * @hide
12904 */
12905 @Override
12906 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12907 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12908 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12909
12910 final long identity = Binder.clearCallingIdentity();
12911 try {
12912 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12913 } finally {
12914 Binder.restoreCallingIdentity(identity);
12915 }
12916 }
12917
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012918 /**
12919 * Get the component name of the default app to direct respond-via-message intent for the
12920 * user associated with this subscription, update the cache if there is no respond-via-message
12921 * application currently configured for this user.
12922 * @return component name of the app and class to direct Respond Via Message intent to, or
12923 * {@code null} if the functionality is not supported.
12924 * @hide
12925 */
12926 @Override
12927 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12928 boolean updateIfNeeded) {
12929 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012930
joonhunshin4ac60942023-11-15 15:23:39 +000012931 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12932 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12933 "getDefaultRespondViaMessageApplication");
12934
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012935 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12936
Grant Menkeb0372492024-09-19 18:01:29 -070012937 if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){
12938 UserHandle mainUser = null;
12939 Context userContext = null;
12940 final long identity = Binder.clearCallingIdentity();
12941 try {
12942 mainUser = mUserManager.getMainUser();
12943 userContext = context.createContextAsUser(mainUser, 0);
12944 Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser);
12945 } finally {
12946 Binder.restoreCallingIdentity(identity);
12947 }
12948 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext,
12949 updateIfNeeded, mainUser);
12950 } else {
12951 UserHandle userHandle = null;
12952 final long identity = Binder.clearCallingIdentity();
12953 try {
12954 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12955 } finally {
12956 Binder.restoreCallingIdentity(identity);
12957 }
12958 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12959 updateIfNeeded, userHandle);
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012960 }
Grant Menkeb0372492024-09-19 18:01:29 -070012961
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012962 }
Jack Yuf5badd92022-12-08 00:50:53 -080012963
12964 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012965 * Set whether the device is able to connect with null ciphering or integrity
12966 * algorithms. This is a global setting and will apply to all active subscriptions
12967 * and all new subscriptions after this.
12968 *
12969 * @param enabled when true, null cipher and integrity algorithms are allowed.
12970 * @hide
12971 */
12972 @Override
12973 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12974 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12975 enforceModifyPermission();
12976 checkForNullCipherAndIntegritySupport();
12977
12978 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12979 // for listening to these preference changes and applying them immediately.
12980 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12981 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12982 editor.apply();
12983
12984 for (Phone phone: PhoneFactory.getPhones()) {
12985 phone.handleNullCipherEnabledChange();
12986 }
12987 }
12988
12989
12990 /**
12991 * Get whether the device is able to connect with null ciphering or integrity
12992 * algorithms. Note that this retrieves the phone-global preference and not
12993 * the state of the radio.
12994 *
12995 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12996 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12997 * version for this feature.
12998 * @hide
12999 */
13000 @Override
13001 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
13002 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
13003 enforceReadPermission();
13004 checkForNullCipherAndIntegritySupport();
13005 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
13006 }
13007
13008 private void checkForNullCipherAndIntegritySupport() {
13009 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
13010 throw new UnsupportedOperationException(
13011 "Null cipher and integrity operations require HAL 2.1 or above");
13012 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000013013 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
13014 throw new UnsupportedOperationException(
13015 "Null cipher and integrity operations unsupported by modem");
13016 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000013017 }
13018
Gil Cukierman06403e12023-11-29 16:33:03 +000013019 private void checkForIdentifierDisclosureNotificationSupport() {
13020 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
13021 throw new UnsupportedOperationException(
13022 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
13023 + "above");
13024 }
13025 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
13026 throw new UnsupportedOperationException(
13027 "Cellular identifier disclosure transparency operations unsupported by modem");
13028 }
13029 }
13030
Michael Groover826b71d2023-12-21 22:08:06 -060013031 private void checkForNullCipherNotificationSupport() {
13032 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
13033 throw new UnsupportedOperationException(
13034 "Null cipher notification operations require HAL 2.2 or above");
13035 }
13036 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
13037 throw new UnsupportedOperationException(
13038 "Null cipher notification operations unsupported by modem");
13039 }
13040 }
13041
Gil Cukierman1c0eb932022-12-06 22:28:24 +000013042 /**
Jack Yuf5badd92022-12-08 00:50:53 -080013043 * Get the SIM state for the slot index.
13044 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
13045 *
13046 * @return SIM state as the ordinal of {@link IccCardConstants.State}
13047 */
13048 @Override
13049 @SimState
13050 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070013051 if (!mApp.getResources().getBoolean(
13052 com.android.internal.R.bool.config_force_phone_globals_creation)) {
13053 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13054 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
13055 }
joonhunshin4ac60942023-11-15 15:23:39 +000013056
Jack Yuf5badd92022-12-08 00:50:53 -080013057 IccCardConstants.State simState;
13058 if (slotIndex < 0) {
13059 simState = IccCardConstants.State.UNKNOWN;
13060 } else {
13061 Phone phone = null;
13062 try {
13063 phone = PhoneFactory.getPhone(slotIndex);
13064 } catch (IllegalStateException e) {
13065 // ignore
13066 }
13067 if (phone == null) {
13068 simState = IccCardConstants.State.UNKNOWN;
13069 } else {
13070 IccCard icc = phone.getIccCard();
13071 if (icc == null) {
13072 simState = IccCardConstants.State.UNKNOWN;
13073 } else {
13074 simState = icc.getState();
13075 }
13076 }
13077 }
13078 return simState.ordinal();
13079 }
Hui Wang9b5793a2022-12-05 14:38:06 -060013080
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013081 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
13082 boolean enableLogcat,
13083 long logcatStartTimestampMillis, boolean enableTelecomDump,
13084 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013085 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013086 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
13087 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
13088 ecdDataBuilder
13089 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
13090 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013091 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013092 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080013093 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013094 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
13095 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080013096 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
13097 Executors.newCachedThreadPool(), db,
13098 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013099 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013100 }
13101
13102 /**
13103 * Request telephony to persist state for debugging emergency call failures.
13104 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080013105 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013106 * @param enableLogcat whether to collect logcat output
13107 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
13108 * @param enableTelecomDump whether to collect telecom dumpsys
13109 * @param enableTelephonyDump whether to collect telephony dumpsys
13110 */
13111 @Override
13112 @RequiresPermission(android.Manifest.permission.DUMP)
13113 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
13114 long logcatStartTimestampMillis, boolean enableTelecomDump,
13115 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080013116 // Verify that the caller has READ_DROPBOX_DATA permission.
13117 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
13118 && Flags.enableReadDropboxPermission()) {
13119 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
13120 "persistEmergencyCallDiagnosticData");
13121 } else {
13122 // Otherwise, enforce legacy permission.
13123 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
13124 "persistEmergencyCallDiagnosticData");
13125 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080013126 final long identity = Binder.clearCallingIdentity();
13127 try {
13128 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
13129 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
13130
13131 } finally {
13132 Binder.restoreCallingIdentity(identity);
13133 }
13134 }
13135
Hui Wang9b5793a2022-12-05 14:38:06 -060013136 /**
13137 * Get current cell broadcast ranges.
13138 */
13139 @Override
13140 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13141 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13142 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13143 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013144
13145 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13146 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13147
Hui Wang9b5793a2022-12-05 14:38:06 -060013148 final long identity = Binder.clearCallingIdentity();
13149 try {
13150 return getPhone(subId).getCellBroadcastIdRanges();
13151 } finally {
13152 Binder.restoreCallingIdentity(identity);
13153 }
13154 }
13155
13156 /**
13157 * Set reception of cell broadcast messages with the list of the given ranges
13158 *
13159 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13160 */
13161 @Override
13162 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13163 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13164 @Nullable IIntegerConsumer callback) {
13165 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13166 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013167
13168 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13169 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13170
Hui Wang9b5793a2022-12-05 14:38:06 -060013171 final long identity = Binder.clearCallingIdentity();
13172 try {
13173 Phone phone = getPhoneFromSubId(subId);
13174 if (DBG) {
13175 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13176 }
13177 phone.setCellBroadcastIdRanges(ranges, result -> {
13178 if (callback != null) {
13179 try {
13180 callback.accept(result);
13181 } catch (RemoteException e) {
13182 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13183 }
13184 }
13185 });
13186 } finally {
13187 Binder.restoreCallingIdentity(identity);
13188 }
13189 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013190
13191 /**
13192 * Returns whether the device supports the domain selection service.
13193 *
13194 * @return {@code true} if the device supports the domain selection service.
13195 */
13196 @Override
13197 public boolean isDomainSelectionSupported() {
13198 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13199 "isDomainSelectionSupported");
13200
13201 final long identity = Binder.clearCallingIdentity();
13202 try {
13203 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13204 } finally {
13205 Binder.restoreCallingIdentity(identity);
13206 }
13207 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013208
13209 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013210 * Returns whether the AOSP domain selection service is supported.
13211 *
13212 * @return {@code true} if the AOSP domain selection service is supported,
13213 * {@code false} otherwise.
13214 */
13215 @Override
13216 public boolean isAospDomainSelectionService() {
13217 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13218 "isAospDomainSelectionService");
13219
13220 final long identity = Binder.clearCallingIdentity();
13221 try {
13222 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13223 String dssComponentName = mApp.getResources().getString(
13224 R.string.config_domain_selection_service_component_name);
13225 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13226 TelephonyDomainSelectionService.class.getName());
13227 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13228 + ", aosp=" + componentName.flattenToString());
13229 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13230 }
13231 } finally {
13232 Binder.restoreCallingIdentity(identity);
13233 }
13234 return false;
13235 }
13236
13237 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013238 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13239 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13240 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013241 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013242 * @param enableSatellite {@code true} to enable the satellite modem and
13243 * {@code false} to disable.
13244 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013245 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013246 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013247 *
13248 * @throws SecurityException if the caller doesn't have the required permission.
13249 */
13250 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013251 public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013252 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013253 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013254 final long identity = Binder.clearCallingIdentity();
13255 try {
13256 if (enableSatellite) {
youngtaecha3a9c8a62024-11-01 20:46:08 +000013257 String caller = "PIM:requestSatelliteEnabled";
Hyosun322782b2024-10-24 11:37:59 +000013258 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13259 @Override
13260 protected void onReceiveResult(int resultCode, Bundle resultData) {
13261 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13262 + ", resultData=" + resultData);
youngtaecha3a9c8a62024-11-01 20:46:08 +000013263 mSatelliteController.decrementResultReceiverCount(caller);
13264
Hyosun322782b2024-10-24 11:37:59 +000013265 boolean isAllowed = false;
13266 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13267 callback::accept);
13268 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13269 if (resultData != null
13270 && resultData.containsKey(
13271 KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13272 isAllowed = resultData.getBoolean(
13273 KEY_SATELLITE_COMMUNICATION_ALLOWED);
13274 } else {
13275 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13276 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013277 } else {
Hyosun322782b2024-10-24 11:37:59 +000013278 result.accept(resultCode);
13279 return;
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013280 }
Sangyun Yun8bb66452024-11-25 15:46:10 +000013281 List<Integer> disallowedReasons =
13282 mSatelliteAccessController.getSatelliteDisallowedReasons();
13283 if (disallowedReasons.stream().anyMatch(r ->
13284 (r == SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP
13285 || r == SATELLITE_DISALLOWED_REASON_NOT_PROVISIONED
13286 || r == SATELLITE_DISALLOWED_REASON_NOT_SUPPORTED))) {
13287 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13288 return;
13289 }
Hyosun322782b2024-10-24 11:37:59 +000013290 if (isAllowed) {
Thomas Nguyendd8e0832024-11-01 00:18:58 +000013291 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13292 @Override
13293 protected void onReceiveResult(int resultCode, Bundle resultData) {
13294 Log.d(LOG_TAG, "updateSystemSelectionChannels resultCode="
13295 + resultCode);
13296 mSatelliteController.requestSatelliteEnabled(
Duke Lee8852e512024-10-06 12:55:43 +090013297 enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyendd8e0832024-11-01 00:18:58 +000013298 }
13299 };
13300 mSatelliteAccessController.updateSystemSelectionChannels(
13301 resultReceiver);
Hyosun322782b2024-10-24 11:37:59 +000013302 } else {
13303 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13304 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013305 }
Hyosun322782b2024-10-24 11:37:59 +000013306 };
13307 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
13308 resultReceiver, true);
youngtaecha3a9c8a62024-11-01 20:46:08 +000013309 mSatelliteController.incrementResultReceiverCount(caller);
Hyosun322782b2024-10-24 11:37:59 +000013310 } else {
13311 // No need to check if satellite is allowed at current location when disabling
13312 // satellite
13313 mSatelliteController.requestSatelliteEnabled(
13314 enableSatellite, enableDemoMode, isEmergency, callback);
13315 }
13316 } finally {
13317 Binder.restoreCallingIdentity(identity);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013318 }
Sarah Chin503828c2023-02-01 23:54:20 -080013319 }
13320
13321 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013322 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013323 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013324 * @param result The result receiver that returns whether the satellite modem is enabled
13325 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013326 *
13327 * @throws SecurityException if the caller doesn't have the required permission.
13328 */
13329 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013330 public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013331 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013332 final long identity = Binder.clearCallingIdentity();
13333 try {
13334 mSatelliteController.requestIsSatelliteEnabled(result);
13335 } finally {
13336 Binder.restoreCallingIdentity(identity);
13337 }
Sarah Chin503828c2023-02-01 23:54:20 -080013338 }
13339
13340 /**
Sarah Chin43457982023-02-15 17:50:38 -080013341 * Request to get whether the satellite service demo mode is enabled.
13342 *
Sarah Chin43457982023-02-15 17:50:38 -080013343 * @param result The result receiver that returns whether the satellite demo mode is enabled
13344 * if the request is successful or an error code if the request failed.
13345 *
13346 * @throws SecurityException if the caller doesn't have the required permission.
13347 */
13348 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013349 public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) {
Sarah Chinabf081b2023-03-09 23:00:57 -080013350 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013351 final long identity = Binder.clearCallingIdentity();
13352 try {
13353 mSatelliteController.requestIsDemoModeEnabled(result);
13354 } finally {
13355 Binder.restoreCallingIdentity(identity);
13356 }
Sarah Chin43457982023-02-15 17:50:38 -080013357 }
13358
13359 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013360 * Request to get whether the satellite service is enabled with emergency mode.
13361 *
Thomas Nguyena8062672024-02-05 14:18:19 -080013362 * @param result The result receiver that returns whether the satellite emergency mode is
13363 * enabled if the request is successful or an error code if the request failed.
13364 *
13365 * @throws SecurityException if the caller doesn't have the required permission.
13366 */
13367 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013368 public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) {
Thomas Nguyena8062672024-02-05 14:18:19 -080013369 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
Hyosun322782b2024-10-24 11:37:59 +000013370 final long identity = Binder.clearCallingIdentity();
13371 try {
13372 mSatelliteController.requestIsEmergencyModeEnabled(result);
13373 } finally {
13374 Binder.restoreCallingIdentity(identity);
13375 }
Thomas Nguyena8062672024-02-05 14:18:19 -080013376 }
13377
13378 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013379 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013380 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013381 * @param result The result receiver that returns whether the satellite service is supported on
13382 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013383 */
13384 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013385 public void requestIsSatelliteSupported(@NonNull ResultReceiver result) {
Hyosun322782b2024-10-24 11:37:59 +000013386 final long identity = Binder.clearCallingIdentity();
13387 try {
13388 mSatelliteController.requestIsSatelliteSupported(result);
13389 } finally {
13390 Binder.restoreCallingIdentity(identity);
13391 }
Sarah Chin503828c2023-02-01 23:54:20 -080013392 }
13393
13394 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013395 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013396 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013397 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13398 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013399 *
13400 * @throws SecurityException if the caller doesn't have required permission.
13401 */
13402 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013403 public void requestSatelliteCapabilities(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013404 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Hyosun322782b2024-10-24 11:37:59 +000013405 final long identity = Binder.clearCallingIdentity();
13406 try {
13407 mSatelliteController.requestSatelliteCapabilities(result);
13408 } finally {
13409 Binder.restoreCallingIdentity(identity);
13410 }
Sarah Chin503828c2023-02-01 23:54:20 -080013411 }
13412
13413 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013414 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013415 * This can be called by the pointing UI when the user starts pointing to the satellite.
13416 * Modem should continue to report the pointing input as the device or satellite moves.
13417 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013418 * @param resultCallback The callback to get the result of the request.
13419 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013420 *
13421 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013422 */
13423 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013424 public void startSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013425 @NonNull IIntegerConsumer resultCallback,
13426 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13427 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013428 final long identity = Binder.clearCallingIdentity();
13429 try {
13430 mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback);
13431 } finally {
13432 Binder.restoreCallingIdentity(identity);
13433 }
Sarah Chineccfbd12023-01-20 19:00:35 -080013434 }
13435
13436 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013437 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013438 * This can be called by the pointing UI when the user stops pointing to the satellite.
13439 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013440 * @param resultCallback The callback to get the result of the request.
13441 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
joonhunshin83da7cd2024-08-22 08:53:35 +000013442 * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013443 *
13444 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013445 */
13446 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013447 public void stopSatelliteTransmissionUpdates(
Sarah Chinabf081b2023-03-09 23:00:57 -080013448 @NonNull IIntegerConsumer resultCallback,
13449 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13450 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
Hyosun322782b2024-10-24 11:37:59 +000013451 final long identity = Binder.clearCallingIdentity();
13452 try {
13453 mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback);
13454 } finally {
13455 Binder.restoreCallingIdentity(identity);
13456 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013457 }
13458
13459 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013460 * Register the subscription with a satellite provider.
13461 * This is needed to register the subscription if the provider allows dynamic registration.
13462 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013463 * @param token The token to be used as a unique identifier for provisioning with satellite
13464 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013465 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013466 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013467 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013468 * @return The signal transport used by the caller to cancel the provision request,
13469 * or {@code null} if the request failed.
13470 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013471 * @throws SecurityException if the caller doesn't have the required permission.
13472 */
13473 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013474 @Nullable public ICancellationSignal provisionSatelliteService(
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013475 @NonNull String token, @NonNull byte[] provisionData,
13476 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013477 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013478 final long identity = Binder.clearCallingIdentity();
13479 try {
13480 return mSatelliteController.provisionSatelliteService(token, provisionData,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013481 callback);
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013482 } finally {
13483 Binder.restoreCallingIdentity(identity);
13484 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013485 }
13486
13487 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013488 * Unregister the device/subscription with the satellite provider.
13489 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013490 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013491 * should report as deprovisioned.
13492 *
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013493 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013494 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013495 *
13496 * @throws SecurityException if the caller doesn't have the required permission.
13497 */
13498 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013499 public void deprovisionSatelliteService(
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013500 @NonNull String token, @NonNull IIntegerConsumer callback) {
13501 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Thomas Nguyen9c3d57b2024-10-23 20:17:21 +000013502 final long identity = Binder.clearCallingIdentity();
13503 try {
13504 mSatelliteController.deprovisionSatelliteService(token, callback);
13505 } finally {
13506 Binder.restoreCallingIdentity(identity);
13507 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013508 }
13509
13510 /**
Sarah Chin43457982023-02-15 17:50:38 -080013511 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013512 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013513 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013514 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013515 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013516 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013517 * @throws SecurityException if the caller doesn't have the required permission.
13518 */
13519 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013520 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013521 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013522 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013523 final long identity = Binder.clearCallingIdentity();
13524 try {
13525 return mSatelliteController.registerForSatelliteProvisionStateChanged(callback);
13526 } finally {
13527 Binder.restoreCallingIdentity(identity);
13528 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013529 }
13530
13531 /**
Sarah Chin43457982023-02-15 17:50:38 -080013532 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013533 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013534 *
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013535 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013536 * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013537 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013538 * @throws SecurityException if the caller doesn't have the required permission.
13539 */
13540 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013541 public void unregisterForSatelliteProvisionStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000013542 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013543 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013544 final long identity = Binder.clearCallingIdentity();
13545 try {
13546 mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback);
13547 } finally {
13548 Binder.restoreCallingIdentity(identity);
13549 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013550 }
13551
13552 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013553 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013554 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013555 * @param result The result receiver that returns whether the device is provisioned with a
13556 * satellite provider if the request is successful or an error code if the
13557 * request failed.
13558 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013559 * @throws SecurityException if the caller doesn't have the required permission.
13560 */
13561 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013562 public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013563 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Hyosun322782b2024-10-24 11:37:59 +000013564 final long identity = Binder.clearCallingIdentity();
13565 try {
13566 mSatelliteController.requestIsSatelliteProvisioned(result);
13567 } finally {
13568 Binder.restoreCallingIdentity(identity);
13569 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013570 }
13571
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013572 /**
Sarah Chin43457982023-02-15 17:50:38 -080013573 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013574 *
Sarah Chin43457982023-02-15 17:50:38 -080013575 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013576 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013577 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013578 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013579 * @throws SecurityException if the caller doesn't have the required permission.
13580 */
13581 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013582 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(
Hakjun Choid4a52a22023-12-13 09:48:24 +000013583 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013584 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013585 final long identity = Binder.clearCallingIdentity();
13586 try {
13587 return mSatelliteController.registerForSatelliteModemStateChanged(callback);
13588 } finally {
13589 Binder.restoreCallingIdentity(identity);
13590 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013591 }
13592
13593 /**
Sarah Chin43457982023-02-15 17:50:38 -080013594 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013595 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013596 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013597 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013598 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013599 *
13600 * @throws SecurityException if the caller doesn't have the required permission.
13601 */
13602 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013603 public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013604 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000013605 final long identity = Binder.clearCallingIdentity();
13606 try {
13607 mSatelliteController.unregisterForModemStateChanged(callback);
13608 } finally {
13609 Binder.restoreCallingIdentity(identity);
13610 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013611 }
13612
13613 /**
13614 * Register to receive incoming datagrams over satellite.
13615 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013616 * @param callback The callback to handle incoming datagrams over satellite.
13617 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013618 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013619 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013620 * @throws SecurityException if the caller doesn't have the required permission.
13621 */
13622 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013623 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013624 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013625 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013626 final long identity = Binder.clearCallingIdentity();
13627 try {
13628 return mSatelliteController.registerForIncomingDatagram(callback);
13629 } finally {
13630 Binder.restoreCallingIdentity(identity);
13631 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013632 }
13633
13634 /**
13635 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013636 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013637 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013638 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000013639 * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013640 *
13641 * @throws SecurityException if the caller doesn't have the required permission.
13642 */
13643 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013644 public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013645 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013646 final long identity = Binder.clearCallingIdentity();
13647 try {
13648 mSatelliteController.unregisterForIncomingDatagram(callback);
13649 } finally {
13650 Binder.restoreCallingIdentity(identity);
13651 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013652 }
13653
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013654 /**
13655 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013656 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013657 * This method requests modem to check if there are any pending datagrams to be received over
13658 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013659 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013660 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013661 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013662 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013663 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013664 */
joonhunshin83da7cd2024-08-22 08:53:35 +000013665 public void pollPendingDatagrams(IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013666 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
Hyosun322782b2024-10-24 11:37:59 +000013667 final long identity = Binder.clearCallingIdentity();
13668 try {
13669 mSatelliteController.pollPendingDatagrams(callback);
13670 } finally {
13671 Binder.restoreCallingIdentity(identity);
13672 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013673 }
13674
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013675 /**
13676 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013677 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013678 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13679 * input to this method. Datagram received here will be passed down to modem without any
13680 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013681 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013682 * @param datagramType datagram type indicating whether the datagram is of type
13683 * SOS_SMS or LOCATION_SHARING.
13684 * @param datagram encoded gateway datagram which is encrypted by the caller.
13685 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013686 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13687 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013688 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013689 *
13690 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013691 */
13692 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013693 public void sendDatagram(@SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013694 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13695 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013696 enforceSatelliteCommunicationPermission("sendDatagram");
Hyosun322782b2024-10-24 11:37:59 +000013697 final long identity = Binder.clearCallingIdentity();
13698 try {
13699 mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI,
13700 callback);
13701 } finally {
13702 Binder.restoreCallingIdentity(identity);
13703 }
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013704 }
13705
Sarah Chindf715ec2023-02-13 13:46:24 -080013706 /**
Duke Lee8852e512024-10-06 12:55:43 +090013707 * Returns integer array of disallowed reasons of satellite.
13708 *
13709 * @return Integer array of disallowed reasons of satellite.
13710 *
13711 * @throws SecurityException if the caller doesn't have the required permission.
13712 */
13713 @NonNull public int[] getSatelliteDisallowedReasons() {
13714 enforceSatelliteCommunicationPermission("getSatelliteDisallowedReasons");
13715 final long identity = Binder.clearCallingIdentity();
13716 try {
13717 return mSatelliteAccessController.getSatelliteDisallowedReasons()
13718 .stream().mapToInt(Integer::intValue).toArray();
13719 } finally {
13720 Binder.restoreCallingIdentity(identity);
13721 }
13722 }
13723
13724 /**
13725 * Registers for disallowed reasons change event from satellite service.
13726 *
13727 * @param callback The callback to handle disallowed reasons changed event.
13728 *
13729 * @throws SecurityException if the caller doesn't have the required permission.
13730 */
13731 @Override
13732 public void registerForSatelliteDisallowedReasonsChanged(
13733 @NonNull ISatelliteDisallowedReasonsCallback callback) {
13734 enforceSatelliteCommunicationPermission("registerForSatelliteDisallowedReasonsChanged");
13735 final long identity = Binder.clearCallingIdentity();
13736 try {
13737 mSatelliteAccessController.registerForSatelliteDisallowedReasonsChanged(callback);
13738 } finally {
13739 Binder.restoreCallingIdentity(identity);
13740 }
13741 }
13742
13743 /**
13744 * Unregisters for disallowed reasons change event from satellite service.
13745 * If callback was not registered before, the request will be ignored.
13746 *
13747 * @param callback The callback to handle disallowed reasons changed event.
13748 * {@link #registerForSatelliteDisallowedReasonsChanged(
13749 * ISatelliteDisallowedReasonsCallback)}.
13750 * @throws SecurityException if the caller doesn't have the required permission.
13751 */
13752 @Override
13753 public void unregisterForSatelliteDisallowedReasonsChanged(
13754 @NonNull ISatelliteDisallowedReasonsCallback callback) {
13755 enforceSatelliteCommunicationPermission("unregisterForSatelliteDisallowedReasonsChanged");
13756 final long identity = Binder.clearCallingIdentity();
13757 try {
13758 mSatelliteAccessController.unregisterForSatelliteDisallowedReasonsChanged(callback);
13759 } finally {
13760 Binder.restoreCallingIdentity(identity);
13761 }
13762 }
13763
13764 /**
Sarah Chindf715ec2023-02-13 13:46:24 -080013765 * Request to get whether satellite communication is allowed for the current location.
13766 *
13767 * @param subId The subId of the subscription to check whether satellite communication is
13768 * allowed for the current location for.
13769 * @param result The result receiver that returns whether satellite communication is allowed
13770 * for the current location if the request is successful or an error code
13771 * if the request failed.
13772 *
13773 * @throws SecurityException if the caller doesn't have the required permission.
13774 */
13775 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013776 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013777 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013778 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
Hyosun322782b2024-10-24 11:37:59 +000013779 final long identity = Binder.clearCallingIdentity();
13780 try {
13781 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result,
13782 false);
13783 } finally {
13784 Binder.restoreCallingIdentity(identity);
13785 }
Sarah Chindf715ec2023-02-13 13:46:24 -080013786 }
13787
13788 /**
youngtaechaedc8a1c2024-10-15 09:07:25 +000013789 * Request to get satellite access configuration for the current location.
13790 *
13791 * @param result The result receiver that returns the satellite access configuration
13792 * for the current location if the request is successful or an error code
13793 * if the request failed.
13794 *
13795 * @throws SecurityException if the caller doesn't have the required permission.
13796 */
13797 @Override
13798 public void requestSatelliteAccessConfigurationForCurrentLocation(
13799 @NonNull ResultReceiver result) {
13800 enforceSatelliteCommunicationPermission(
13801 "requestSatelliteAccessConfigurationForCurrentLocation");
13802 final long identity = Binder.clearCallingIdentity();
13803 try {
13804 mSatelliteAccessController
13805 .requestSatelliteAccessConfigurationForCurrentLocation(result);
13806 } finally {
13807 Binder.restoreCallingIdentity(identity);
13808 }
13809 }
13810
13811 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013812 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013813 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013814 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013815 * be visible if the request is successful or an error code if the request failed.
13816 *
13817 * @throws SecurityException if the caller doesn't have the required permission.
13818 */
13819 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000013820 public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013821 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Hyosun322782b2024-10-24 11:37:59 +000013822 final long identity = Binder.clearCallingIdentity();
13823 try {
13824 mSatelliteController.requestTimeForNextSatelliteVisibility(result);
13825 } finally {
13826 Binder.restoreCallingIdentity(identity);
13827 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013828 }
13829
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013830 /**
Adrian8e30ad02024-11-21 17:22:29 +000013831 * Request to get the name to display for Satellite subscription.
13832 *
13833 * @param result The result receiver that returns the display name to use for satellite feature
13834 * in the UI for current satellite subscription if the request is successful,
13835 * or an error code if the request failed.
13836 *
13837 * @throws SecurityException if the caller doesn't have the required permission.
13838 */
13839 @Override
13840 public void requestSatelliteDisplayName(@NonNull ResultReceiver result) {
13841 enforceSatelliteCommunicationPermission("requestSatelliteDisplayName");
13842 final long identity = Binder.clearCallingIdentity();
13843 try {
13844 mSatelliteController.requestSatelliteDisplayName(result);
13845 } finally {
13846 Binder.restoreCallingIdentity(identity);
13847 }
13848 }
13849
13850 /**
Daniel Banta99cc7532024-11-15 02:31:08 +000013851 * Request to get the currently selected satellite subscription id.
13852 *
13853 * @param result The result receiver that returns the currently selected satellite subscription
13854 * id if the request is successful or an error code if the request failed.
13855 *
13856 * @throws SecurityException if the caller doesn't have the required permission.
13857 */
13858 @Override
13859 public void requestSelectedNbIotSatelliteSubscriptionId(@NonNull ResultReceiver result) {
13860 enforceSatelliteCommunicationPermission("requestSelectedNbIotSatelliteSubscriptionId");
13861 final long identity = Binder.clearCallingIdentity();
13862 try {
13863 mSatelliteController.requestSelectedNbIotSatelliteSubscriptionId(result);
13864 } finally {
13865 Binder.restoreCallingIdentity(identity);
13866 }
13867 }
13868
13869 /**
Daniel Banta93320242024-11-21 00:34:41 +000013870 * Registers for selected satellite subscription changed event from the satellite service.
13871 *
13872 * @param callback The callback to handle the satellite subscription changed event.
13873 *
13874 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13875 *
13876 * @throws SecurityException if the caller doesn't have required permission.
13877 */
13878 @Override
13879 @SatelliteManager.SatelliteResult
13880 public int registerForSelectedNbIotSatelliteSubscriptionChanged(
13881 @NonNull ISelectedNbIotSatelliteSubscriptionCallback callback) {
13882 enforceSatelliteCommunicationPermission(
13883 "registerForSelectedNbIotSatelliteSubscriptionChanged");
13884 final long identity = Binder.clearCallingIdentity();
13885 try {
13886 return mSatelliteController.registerForSelectedNbIotSatelliteSubscriptionChanged(
13887 callback);
13888 } finally {
13889 Binder.restoreCallingIdentity(identity);
13890 }
13891 }
13892
13893 /**
13894 * Unregisters for selected satellite subscription changed event from the satellite service.
13895 * If callback was not registered before, the request will be ignored.
13896 *
13897 * @param callback The callback that was passed to {@link
13898 * #registerForSelectedNbIotSatelliteSubscriptionChanged(
13899 * ISelectedNbIotSatelliteSubscriptionCallback)}.
13900 *
13901 * @throws SecurityException if the caller doesn't have required permission.
13902 */
13903 @Override
13904 public void unregisterForSelectedNbIotSatelliteSubscriptionChanged(
13905 @NonNull ISelectedNbIotSatelliteSubscriptionCallback callback) {
13906 enforceSatelliteCommunicationPermission(
13907 "unregisterForSelectedNbIotSatelliteSubscriptionChanged");
13908 final long identity = Binder.clearCallingIdentity();
13909 try {
13910 mSatelliteController.unregisterForSelectedNbIotSatelliteSubscriptionChanged(
13911 callback);
13912 } finally {
13913 Binder.restoreCallingIdentity(identity);
13914 }
13915 }
13916
13917 /**
joonhunshin59104152024-09-11 09:55:35 +000013918 * Inform whether the device is aligned with the satellite in both real and demo mode.
Hakjun Choiae365972023-04-25 11:00:31 +000013919 *
joonhunshin59104152024-09-11 09:55:35 +000013920 * @param isAligned {@code true} Device is aligned with the satellite.
13921 * {@code false} Device fails to align with the satellite.
Hakjun Choiae365972023-04-25 11:00:31 +000013922 *
13923 * @throws SecurityException if the caller doesn't have required permission.
13924 */
13925 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13926
joonhunshin83da7cd2024-08-22 08:53:35 +000013927 public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) {
Hyosun322782b2024-10-24 11:37:59 +000013928 enforceSatelliteCommunicationPermission("setDeviceAlignedWithSatellite");
13929 final long identity = Binder.clearCallingIdentity();
13930 try {
13931 mSatelliteController.setDeviceAlignedWithSatellite(isAligned);
13932 } finally {
13933 Binder.restoreCallingIdentity(identity);
13934 }
Hakjun Choiae365972023-04-25 11:00:31 +000013935 }
13936
13937 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013938 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13939 * by modem.
13940 *
13941 * @param subId The subId of the subscription to request for.
13942 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013943 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013944 * operation.
13945 *
13946 * @throws SecurityException if the caller doesn't have required permission.
13947 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013948 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013949 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13950 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013951 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013952 final long identity = Binder.clearCallingIdentity();
13953 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013954 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013955 } finally {
13956 Binder.restoreCallingIdentity(identity);
13957 }
13958 }
13959
13960 /**
13961 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13962 * by modem.
13963 *
13964 * @param subId The subId of the subscription to request for.
13965 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013966 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013967 * operation.
13968 *
13969 * @throws SecurityException if the caller doesn't have required permission.
13970 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013971 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013972 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13973 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013974 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013975 final long identity = Binder.clearCallingIdentity();
13976 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013977 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013978 } finally {
13979 Binder.restoreCallingIdentity(identity);
13980 }
13981 }
13982
13983 /**
13984 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013985 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013986 *
13987 * @param subId The subId of the subscription to request for.
13988 *
13989 * @return Integer array of reasons for disallowing satellite communication.
13990 *
13991 * @throws SecurityException if the caller doesn't have the required permission.
13992 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013993 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013994 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013995 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013996 final long identity = Binder.clearCallingIdentity();
13997 try {
13998 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013999 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000014000 return reasonSet.stream().mapToInt(i->i).toArray();
14001 } finally {
14002 Binder.restoreCallingIdentity(identity);
14003 }
14004 }
14005
14006 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000014007 * Request to get the signal strength of the satellite connection.
14008 *
Hakjun Choifa3e6172023-09-22 03:56:34 +000014009 * @param result Result receiver to get the error code of the request and the current signal
14010 * strength of the satellite connection.
14011 *
14012 * @throws SecurityException if the caller doesn't have required permission.
14013 */
14014 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000014015 public void requestNtnSignalStrength(@NonNull ResultReceiver result) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000014016 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
14017 final long identity = Binder.clearCallingIdentity();
14018 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000014019 mSatelliteController.requestNtnSignalStrength(result);
Hakjun Choifa3e6172023-09-22 03:56:34 +000014020 } finally {
14021 Binder.restoreCallingIdentity(identity);
14022 }
14023 }
14024
14025 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000014026 * Registers for NTN signal strength changed from satellite modem. If the registration operation
14027 * is not successful, a {@link ServiceSpecificException} that contains
14028 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000014029 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000014030 * @param callback The callback to handle the NTN signal strength changed event. If the
14031 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
14032 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
14033 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
14034 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000014035 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000014036 * @throws SecurityException If the caller doesn't have the required permission.
14037 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000014038 */
14039 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000014040 public void registerForNtnSignalStrengthChanged(
Hakjun Choi4c3668a2023-12-05 11:55:36 +000014041 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000014042 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
14043 final long identity = Binder.clearCallingIdentity();
14044 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000014045 mSatelliteController.registerForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000014046 } finally {
14047 Binder.restoreCallingIdentity(identity);
14048 }
14049 }
14050
14051 /**
14052 * Unregisters for NTN signal strength changed from satellite modem.
14053 * If callback was not registered before, the request will be ignored.
14054 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000014055 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000014056 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000014057 * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)}
Hakjun Choifa3e6172023-09-22 03:56:34 +000014058 *
14059 * @throws SecurityException if the caller doesn't have the required permission.
14060 */
14061 @Override
14062 public void unregisterForNtnSignalStrengthChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014063 @NonNull INtnSignalStrengthCallback callback) {
Hakjun Choifa3e6172023-09-22 03:56:34 +000014064 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
14065 final long identity = Binder.clearCallingIdentity();
14066 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000014067 mSatelliteController.unregisterForNtnSignalStrengthChanged(callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000014068 } finally {
14069 Binder.restoreCallingIdentity(identity);
14070 }
14071 }
14072
14073 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000014074 * Registers for satellite capabilities change event from the satellite service.
14075 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000014076 * @param callback The callback to handle the satellite capabilities changed event.
14077 *
14078 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14079 *
14080 * @throws SecurityException if the caller doesn't have required permission.
14081 */
14082 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000014083 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014084 @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000014085 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000014086 final long identity = Binder.clearCallingIdentity();
14087 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000014088 return mSatelliteController.registerForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000014089 } finally {
14090 Binder.restoreCallingIdentity(identity);
14091 }
14092 }
14093
14094 /**
14095 * Unregisters for satellite capabilities change event from the satellite service.
14096 * If callback was not registered before, the request will be ignored.
14097 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000014098 * @param callback The callback that was passed to.
joonhunshin83da7cd2024-08-22 08:53:35 +000014099 * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000014100 *
14101 * @throws SecurityException if the caller doesn't have required permission.
14102 */
14103 @Override
joonhunshin83da7cd2024-08-22 08:53:35 +000014104 public void unregisterForCapabilitiesChanged(
Hakjun Choi3c9303b2023-12-21 06:37:41 +000014105 @NonNull ISatelliteCapabilitiesCallback callback) {
14106 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000014107 final long identity = Binder.clearCallingIdentity();
14108 try {
joonhunshin83da7cd2024-08-22 08:53:35 +000014109 mSatelliteController.unregisterForCapabilitiesChanged(callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000014110 } finally {
14111 Binder.restoreCallingIdentity(identity);
14112 }
14113 }
14114
14115 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000014116 * Registers for the satellite supported state changed.
14117 *
Hakjun Choif92ac752024-03-18 19:34:29 +000014118 * @param callback The callback to handle the satellite supported state changed event.
14119 *
14120 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14121 *
14122 * @throws SecurityException if the caller doesn't have the required permission.
14123 */
14124 @Override
14125 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014126 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000014127 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000014128 final long identity = Binder.clearCallingIdentity();
14129 try {
14130 return mSatelliteController.registerForSatelliteSupportedStateChanged(callback);
14131 } finally {
14132 Binder.restoreCallingIdentity(identity);
14133 }
Hakjun Choif92ac752024-03-18 19:34:29 +000014134 }
14135
14136 /**
14137 * Unregisters for the satellite supported state changed.
14138 * If callback was not registered before, the request will be ignored.
14139 *
Hakjun Choif92ac752024-03-18 19:34:29 +000014140 * @param callback The callback that was passed to
joonhunshin83da7cd2024-08-22 08:53:35 +000014141 * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}.
Hakjun Choif92ac752024-03-18 19:34:29 +000014142 *
14143 * @throws SecurityException if the caller doesn't have the required permission.
14144 */
14145 @Override
14146 public void unregisterForSatelliteSupportedStateChanged(
joonhunshin83da7cd2024-08-22 08:53:35 +000014147 @NonNull ISatelliteSupportedStateCallback callback) {
Hakjun Choif92ac752024-03-18 19:34:29 +000014148 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
Hyosun322782b2024-10-24 11:37:59 +000014149 final long identity = Binder.clearCallingIdentity();
14150 try {
14151 mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback);
14152 } finally {
14153 Binder.restoreCallingIdentity(identity);
14154 }
Hakjun Choif92ac752024-03-18 19:34:29 +000014155 }
14156
14157 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014158 * This API can be used by only CTS to update satellite vendor service package name.
14159 *
14160 * @param servicePackageName The package name of the satellite vendor service.
Hakjun Choic3393242024-06-26 18:02:08 +000014161 * @param provisioned Whether satellite should be provisioned or not.
14162 *
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014163 * @return {@code true} if the satellite vendor service is set successfully,
14164 * {@code false} otherwise.
14165 */
Hakjun Choic3393242024-06-26 18:02:08 +000014166 public boolean setSatelliteServicePackageName(String servicePackageName,
14167 String provisioned) {
14168 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName
14169 + ", provisioned=" + provisioned);
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014170 TelephonyPermissions.enforceShellOnly(
14171 Binder.getCallingUid(), "setSatelliteServicePackageName");
14172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14173 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14174 "setSatelliteServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000014175 final long identity = Binder.clearCallingIdentity();
14176 try {
14177 return mSatelliteController.setSatelliteServicePackageName(servicePackageName,
14178 provisioned);
14179 } finally {
14180 Binder.restoreCallingIdentity(identity);
14181 }
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070014182 }
14183
14184 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070014185 * This API can be used by only CTS to update satellite gateway service package name.
14186 *
14187 * @param servicePackageName The package name of the satellite gateway service.
14188 * @return {@code true} if the satellite gateway service is set successfully,
14189 * {@code false} otherwise.
14190 */
14191 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
14192 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
14193 TelephonyPermissions.enforceShellOnly(
14194 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
14195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14196 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14197 "setSatelliteGatewayServicePackageName");
Hyosun322782b2024-10-24 11:37:59 +000014198 final long identity = Binder.clearCallingIdentity();
14199 try {
14200 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
14201 } finally {
14202 Binder.restoreCallingIdentity(identity);
14203 }
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070014204 }
14205
14206 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070014207 * This API can be used by only CTS to update satellite pointing UI app package and class names.
14208 *
14209 * @param packageName The package name of the satellite pointing UI app.
14210 * @param className The class name of the satellite pointing UI app.
14211 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
14212 * {@code false} otherwise.
14213 */
14214 public boolean setSatellitePointingUiClassName(
14215 @Nullable String packageName, @Nullable String className) {
14216 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
14217 + ", className=" + className);
14218 TelephonyPermissions.enforceShellOnly(
14219 Binder.getCallingUid(), "setSatellitePointingUiClassName");
14220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14221 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000014222 "setSatellitePointingUiClassName");
14223 final long identity = Binder.clearCallingIdentity();
14224 try {
14225 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
14226 } finally {
14227 Binder.restoreCallingIdentity(identity);
14228 }
Thomas Nguyen87dce732023-04-20 18:27:16 -070014229 }
14230
14231 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070014232 * This API can be used by only CTS to update the timeout duration in milliseconds that
14233 * satellite should stay at listening mode to wait for the next incoming page before disabling
14234 * listening mode.
14235 *
14236 * @param timeoutMillis The timeout duration in millisecond.
14237 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14238 */
14239 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
14240 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
14241 TelephonyPermissions.enforceShellOnly(
14242 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
14243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14244 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14245 "setSatelliteListeningTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014246 final long identity = Binder.clearCallingIdentity();
14247 try {
14248 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
14249 } finally {
14250 Binder.restoreCallingIdentity(identity);
14251 }
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070014252 }
14253
14254 /**
joonhunshinf46f0d62024-09-27 14:06:26 +000014255 * This API can be used by only CTS to control ingoring cellular service state event.
14256 *
14257 * @param enabled Whether to enable boolean config.
14258 * @return {@code true} if the value is set successfully, {@code false} otherwise.
14259 */
14260 public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) {
Hyosun322782b2024-10-24 11:37:59 +000014261 Log.d(LOG_TAG, "setSatelliteIgnoreCellularServiceState - " + enabled);
joonhunshinf46f0d62024-09-27 14:06:26 +000014262 TelephonyPermissions.enforceShellOnly(
Hyosun322782b2024-10-24 11:37:59 +000014263 Binder.getCallingUid(), "setSatelliteIgnoreCellularServiceState");
joonhunshinf46f0d62024-09-27 14:06:26 +000014264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14265 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Hyosun322782b2024-10-24 11:37:59 +000014266 "setSatelliteIgnoreCellularServiceState");
14267 final long identity = Binder.clearCallingIdentity();
14268 try {
14269 return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled);
14270 } finally {
14271 Binder.restoreCallingIdentity(identity);
14272 }
joonhunshinf46f0d62024-09-27 14:06:26 +000014273 }
14274
14275 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014276 * This API can be used by only CTS to override the timeout durations used by the
14277 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000014278 *
14279 * @param timeoutMillis The timeout duration in millisecond.
14280 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14281 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014282 public boolean setDatagramControllerTimeoutDuration(
14283 boolean reset, int timeoutType, long timeoutMillis) {
14284 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
14285 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000014286 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014287 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000014288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14289 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014290 "setDatagramControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014291 final long identity = Binder.clearCallingIdentity();
14292 try {
14293 return mSatelliteController.setDatagramControllerTimeoutDuration(
14294 reset, timeoutType, timeoutMillis);
14295 } finally {
14296 Binder.restoreCallingIdentity(identity);
14297 }
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014298 }
14299
14300 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014301 * This API can be used by only CTS to override the boolean configs used by the
14302 * DatagramController module.
14303 *
14304 * @param enable Whether to enable or disable boolean config.
14305 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
14306 */
14307 public boolean setDatagramControllerBooleanConfig(
14308 boolean reset, int booleanType, boolean enable) {
14309 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
14310 + ", reset=" + reset + ", enable=" + enable);
14311 TelephonyPermissions.enforceShellOnly(
14312 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
14313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14314 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14315 "ssetDatagramControllerBooleanConfig");
Hyosun322782b2024-10-24 11:37:59 +000014316 final long identity = Binder.clearCallingIdentity();
14317 try {
14318 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType,
14319 enable);
14320 } finally {
14321 Binder.restoreCallingIdentity(identity);
14322 }
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000014323 }
14324
14325
14326 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080014327 * This API can be used by only CTS to override the timeout durations used by the
14328 * SatelliteController module.
14329 *
14330 * @param timeoutMillis The timeout duration in millisecond.
14331 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
14332 */
14333 public boolean setSatelliteControllerTimeoutDuration(
14334 boolean reset, int timeoutType, long timeoutMillis) {
14335 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
14336 + reset + ", timeoutMillis=" + timeoutMillis);
14337 TelephonyPermissions.enforceShellOnly(
14338 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
14339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14340 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14341 "setSatelliteControllerTimeoutDuration");
Hyosun322782b2024-10-24 11:37:59 +000014342 final long identity = Binder.clearCallingIdentity();
14343 try {
14344 return mSatelliteController.setSatelliteControllerTimeoutDuration(
14345 reset, timeoutType, timeoutMillis);
14346 } finally {
14347 Binder.restoreCallingIdentity(identity);
14348 }
Hakjun Choiae365972023-04-25 11:00:31 +000014349 }
14350
14351 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014352 * This API can be used in only testing to override connectivity status in monitoring emergency
14353 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
14354 *
14355 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
14356 * of the following values to enable the override:
14357 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
14358 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
14359 * To disable the override, use -1 for handoverType.
14360 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
14361 * delaySeconds after the emergency call starts.
14362 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
14363 */
14364 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
14365 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
14366 TelephonyPermissions.enforceShellOnly(
14367 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
14368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14369 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14370 "setEmergencyCallToSatelliteHandoverType");
Hyosun322782b2024-10-24 11:37:59 +000014371 final long identity = Binder.clearCallingIdentity();
14372 try {
14373 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
14374 handoverType, delaySeconds);
14375 } finally {
14376 Binder.restoreCallingIdentity(identity);
14377 }
Thomas Nguyen11a051f2023-10-25 10:14:55 -070014378 }
14379
14380 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080014381 * This API can be used in only testing to override oem-enabled satellite provision status.
14382 *
14383 * @param reset {@code true} mean the overriding status should not be used, {@code false}
14384 * otherwise.
14385 * @param isProvisioned The overriding provision status.
14386 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
14387 */
14388 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
14389 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
14390 + ", isProvisioned=" + isProvisioned);
14391 TelephonyPermissions.enforceShellOnly(
14392 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
14393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14394 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14395 "setOemEnabledSatelliteProvisionStatus");
Hyosun322782b2024-10-24 11:37:59 +000014396 final long identity = Binder.clearCallingIdentity();
14397 try {
14398 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
14399 } finally {
14400 Binder.restoreCallingIdentity(identity);
14401 }
Thomas Nguyen3d602742024-01-19 11:29:35 -080014402 }
14403
14404 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014405 * This API should be used by only CTS tests to forcefully set telephony country codes.
14406 *
14407 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
14408 */
14409 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
14410 Map cachedNetworkCountryCodes, String locationCountryCode,
14411 long locationCountryCodeTimestampNanos) {
14412 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
14413 + String.join(", ", currentNetworkCountryCodes)
14414 + ", locationCountryCode=" + locationCountryCode
14415 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
14416 + ", reset=" + reset + ", cachedNetworkCountryCodes="
14417 + String.join(", ", cachedNetworkCountryCodes.keySet()));
Hyosun322782b2024-10-24 11:37:59 +000014418 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCountryCodes");
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Hyosun322782b2024-10-24 11:37:59 +000014420 SubscriptionManager.INVALID_SUBSCRIPTION_ID, "setCountryCodes");
14421 final long identity = Binder.clearCallingIdentity();
14422 try {
14423 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(),
14424 mFeatureFlags).setCountryCodes(reset, currentNetworkCountryCodes,
14425 cachedNetworkCountryCodes, locationCountryCode,
14426 locationCountryCodeTimestampNanos);
14427 } finally {
14428 Binder.restoreCallingIdentity(identity);
14429 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014430 }
14431
14432 /**
14433 * This API should be used by only CTS tests to override the overlay configs of satellite
14434 * access controller.
14435 *
14436 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
14437 * otherwise.
14438 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
14439 */
14440 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
14441 String s2CellFile, long locationFreshDurationNanos,
Hakjun Choi364b6ff2024-11-20 07:38:44 +000014442 List<String> satelliteCountryCodes, String satelliteAccessConfigurationFile) {
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014443 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
14444 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
14445 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
14446 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
Hakjun Choi364b6ff2024-11-20 07:38:44 +000014447 ? String.join(", ", satelliteCountryCodes) : null)
14448 + ", satelliteAccessConfigurationFile=" + satelliteAccessConfigurationFile);
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014449 TelephonyPermissions.enforceShellOnly(
14450 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
14451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14452 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14453 "setSatelliteAccessControlOverlayConfigs");
Hyosun322782b2024-10-24 11:37:59 +000014454 final long identity = Binder.clearCallingIdentity();
14455 try {
14456 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset,
Hakjun Choi364b6ff2024-11-20 07:38:44 +000014457 isAllowed, s2CellFile, locationFreshDurationNanos, satelliteCountryCodes,
14458 satelliteAccessConfigurationFile);
Hyosun322782b2024-10-24 11:37:59 +000014459 } finally {
14460 Binder.restoreCallingIdentity(identity);
14461 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080014462 }
14463
14464 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000014465 * This API can be used by only CTS to override the cached value for the device overlay config
14466 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
14467 * outgoing satellite datagrams should be sent to modem in demo mode.
14468 *
14469 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
14470 * satellite modem or not.
14471 *
14472 * @return {@code true} if the operation is successful, {@code false} otherwise.
14473 */
14474 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
14475 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14476 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
14477 + "disabled");
14478 return false;
14479 }
14480 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
14481 TelephonyPermissions.enforceShellOnly(
14482 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
14483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14484 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14485 "setShouldSendDatagramToModemInDemoMode");
Hyosun322782b2024-10-24 11:37:59 +000014486 final long identity = Binder.clearCallingIdentity();
14487 try {
14488 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
14489 shouldSendToModemInDemoMode);
14490 } finally {
14491 Binder.restoreCallingIdentity(identity);
14492 }
Hakjun Choibc6ce992023-11-07 16:04:33 +000014493 }
14494
14495 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000014496 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
14497 *
14498 * @param state a state indicates whether satellite access allowed state should be cached and
14499 * the allowed state.
14500 * @return {@code true} if the setting is successful, {@code false} otherwise.
14501 */
14502 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
14503 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
14504 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14505 + "oemEnabledSatelliteFlag is disabled");
14506 return false;
14507 }
14508
14509 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14510 + "state=" + state);
14511 TelephonyPermissions.enforceShellOnly(
14512 Binder.getCallingUid(),
14513 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14515 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14516 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
Hyosun322782b2024-10-24 11:37:59 +000014517 final long identity = Binder.clearCallingIdentity();
14518 try {
14519 return mSatelliteAccessController
14520 .setIsSatelliteCommunicationAllowedForCurrentLocationCache(state);
14521 } finally {
14522 Binder.restoreCallingIdentity(identity);
14523 }
Hakjun Choi4a832d12024-05-28 22:23:55 +000014524 }
14525
14526 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014527 * Sets the service defined in ComponentName to be bound.
14528 *
14529 * This should only be used for testing.
14530 * @return {@code true} if the DomainSelectionService to bind to was set,
14531 * {@code false} otherwise.
14532 */
14533 @Override
14534 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14535 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14536
14537 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14538 "setDomainSelectionServiceOverride");
14539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14540 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14541
14542 final long identity = Binder.clearCallingIdentity();
14543 try {
14544 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14545 return DomainSelectionResolver.getInstance()
14546 .setDomainSelectionServiceOverride(componentName);
14547 }
14548 } finally {
14549 Binder.restoreCallingIdentity(identity);
14550 }
14551 return false;
14552 }
14553
14554 /**
14555 * Clears the DomainSelectionService override.
14556 *
14557 * This should only be used for testing.
14558 * @return {@code true} if the DomainSelectionService override was cleared,
14559 * {@code false} otherwise.
14560 */
14561 @Override
14562 public boolean clearDomainSelectionServiceOverride() {
14563 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14564
14565 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14566 "clearDomainSelectionServiceOverride");
14567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14568 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14569
14570 final long identity = Binder.clearCallingIdentity();
14571 try {
14572 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14573 return DomainSelectionResolver.getInstance()
14574 .clearDomainSelectionServiceOverride();
14575 }
14576 } finally {
14577 Binder.restoreCallingIdentity(identity);
14578 }
14579 return false;
14580 }
14581
14582 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014583 * Enable or disable notifications sent for cellular identifier disclosure events.
14584 *
14585 * Disclosure events are defined as instances where a device has sent a cellular identifier
14586 * on the Non-access stratum (NAS) before a security context is established. As a result the
14587 * identifier is sent in the clear, which has privacy implications for the user.
14588 *
14589 * @param enable if notifications about disclosure events should be enabled
14590 * @throws SecurityException if the caller does not have the required privileges
14591 * @throws UnsupportedOperationException if the modem does not support this feature.
14592 */
14593 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014594 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014595 enforceModifyPermission();
14596 checkForIdentifierDisclosureNotificationSupport();
14597
14598 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14599 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14600 editor.apply();
14601
14602 // Each phone instance is responsible for updating its respective modem immediately
14603 // after we've made a preference change.
14604 for (Phone phone : PhoneFactory.getPhones()) {
14605 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14606 }
14607 }
14608
14609 /**
14610 * Get whether or not cellular identifier disclosure notifications are enabled.
14611 *
14612 * @throws SecurityException if the caller does not have the required privileges
14613 * @throws UnsupportedOperationException if the modem does not support this feature.
14614 */
14615 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014616 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014617 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14618 checkForIdentifierDisclosureNotificationSupport();
14619 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14620 }
14621
14622 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014623 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14624 * are in use by the cellular modem.
14625 *
14626 * @throws IllegalStateException if the Telephony process is not currently available
14627 * @throws SecurityException if the caller does not have the required privileges
14628 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14629 * and integrity algorithms in use
14630 * @hide
14631 */
14632 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014633 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014634 enforceModifyPermission();
14635 checkForNullCipherNotificationSupport();
14636
14637 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14638 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14639 editor.apply();
14640
14641 // Each phone instance is responsible for updating its respective modem immediately
14642 // after a preference change.
14643 for (Phone phone : PhoneFactory.getPhones()) {
14644 phone.handleNullCipherNotificationPreferenceChanged();
14645 }
14646 }
14647
14648 /**
14649 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14650 * cellular modem.
14651 *
14652 * @throws IllegalStateException if the Telephony process is not currently available
14653 * @throws SecurityException if the caller does not have the required privileges
14654 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14655 * and integrity algorithms in use
14656 * @hide
14657 */
14658 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14659 public boolean isNullCipherNotificationsEnabled() {
14660 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14661 checkForNullCipherNotificationSupport();
14662 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14663 }
14664
14665 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014666 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14667 *
14668 * <p>This method behaves in one of the following ways:
14669 * <ul>
14670 * <li>return true : if the calling package has the appop permission {@link
14671 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14672 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14673 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14674 * Owner device identifier access check, or the calling package has carrier privileges</>
14675 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14676 * </ul>
14677 */
14678 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14679 String callingPackage, @Nullable String callingFeatureId, String message) {
14680 for (Phone phone : PhoneFactory.getPhones()) {
14681 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14682 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14683 return true;
14684 }
14685 }
14686 return false;
14687 }
arunvoddud7401012022-12-15 16:08:12 +000014688
14689 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014690 * @return The subscription manager service instance.
14691 */
14692 public SubscriptionManagerService getSubscriptionManagerService() {
14693 return SubscriptionManagerService.getInstance();
14694 }
14695
14696 /**
arunvoddud7401012022-12-15 16:08:12 +000014697 * Class binds the consumer[callback] and carrierId.
14698 */
14699 private static class CallerCallbackInfo {
14700 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014701 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014702
Steve Statia28b7cb32024-03-11 23:58:50 +000014703 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014704 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014705 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014706 }
14707
14708 public Consumer<Integer> getConsumer() {
14709 return mConsumer;
14710 }
14711
Steve Statia28b7cb32024-03-11 23:58:50 +000014712 public Set<Integer> getCarrierIds() {
14713 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014714 }
14715 }
joonhunshin4ac60942023-11-15 15:23:39 +000014716
14717 /*
14718 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14719 * But the context that is passed in is unused if the phone app is already alive.
14720 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14721 */
14722 @VisibleForTesting
14723 public void setPackageManager(PackageManager packageManager) {
14724 mPackageManager = packageManager;
14725 }
14726
14727 /*
Nate Myren453c3472024-03-13 11:28:11 -070014728 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14729 * But the context that is passed in is unused if the phone app is already alive.
14730 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14731 */
14732 @VisibleForTesting
14733 public void setAppOpsManager(AppOpsManager appOps) {
14734 mAppOps = appOps;
14735 }
14736
14737 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014738 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14739 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14740 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14741 */
14742 @VisibleForTesting
14743 public void setFeatureFlags(FeatureFlags featureFlags) {
14744 mFeatureFlags = featureFlags;
14745 }
14746
14747 /**
14748 * Make sure the device has required telephony feature
14749 *
14750 * @throws UnsupportedOperationException if the device does not have required telephony feature
14751 */
14752 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14753 @NonNull String telephonyFeature, @NonNull String methodName) {
14754 if (callingPackage == null || mPackageManager == null) {
14755 return;
14756 }
14757
14758 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14759 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014760 Binder.getCallingUserHandle())
14761 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14762 // Skip to check associated telephony feature,
14763 // if compatibility change is not enabled for the current process or
14764 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014765 return;
14766 }
14767
14768 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14769 throw new UnsupportedOperationException(
14770 methodName + " is unsupported without " + telephonyFeature);
14771 }
14772 }
youngtaecha5d483d52024-04-29 17:05:45 +000014773
14774 /**
14775 * Registers for the satellite communication allowed state changed.
14776 *
14777 * @param subId The subId of the subscription to register for the satellite communication
14778 * allowed state changed.
14779 * @param callback The callback to handle the satellite communication allowed
14780 * state changed event.
14781 *
14782 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14783 *
14784 * @throws SecurityException if the caller doesn't have the required permission.
14785 */
14786 @Override
14787 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14788 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14789 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014790 final long identity = Binder.clearCallingIdentity();
14791 try {
14792 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14793 subId, callback);
14794 } finally {
14795 Binder.restoreCallingIdentity(identity);
14796 }
youngtaecha5d483d52024-04-29 17:05:45 +000014797 }
14798
14799 /**
14800 * Unregisters for the satellite communication allowed state changed.
14801 * If callback was not registered before, the request will be ignored.
14802 *
14803 * @param subId The subId of the subscription to unregister for the satellite communication
14804 * allowed state changed.
14805 * @param callback The callback that was passed to
14806 * {@link #registerForCommunicationAllowedStateChanged(int,
14807 * ISatelliteCommunicationAllowedStateCallback)}. *
14808 * @throws SecurityException if the caller doesn't have the required permission.
14809 */
14810 @Override
14811 public void unregisterForCommunicationAllowedStateChanged(
14812 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14813 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014814 final long identity = Binder.clearCallingIdentity();
14815 try {
14816 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId,
14817 callback);
14818 } finally {
14819 Binder.restoreCallingIdentity(identity);
14820 }
youngtaecha5d483d52024-04-29 17:05:45 +000014821 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014822
14823 /**
14824 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14825 *
14826 * @param subId The subId of the subscription to the satellite session stats for.
14827 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14828 * if the request is successful or an error code if the request failed.
14829 *
14830 * @throws SecurityException if the caller doesn't have required permission.
14831 */
14832 @Override
14833 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14834 enforceModifyPermission();
14835 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014836 final long identity = Binder.clearCallingIdentity();
14837 try {
14838 mSatelliteController.requestSatelliteSessionStats(subId, result);
14839 } finally {
14840 Binder.restoreCallingIdentity(identity);
14841 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014842 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014843
14844 /**
14845 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14846 *
14847 * @param result The result receiver, which returns the list of prioritized satellite tokens
14848 * to be used for provision if the request is successful or an error code if the request failed.
14849 *
14850 * @throws SecurityException if the caller doesn't have the required permission.
14851 */
14852 @Override
Hyosun6dbe8542024-08-15 02:52:48 +000014853 public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) {
14854 enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014855 final long identity = Binder.clearCallingIdentity();
14856 try {
14857 mSatelliteController.requestSatelliteSubscriberProvisionStatus(result);
14858 } finally {
14859 Binder.restoreCallingIdentity(identity);
14860 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014861 }
14862
14863 /**
14864 * Deliver the list of provisioned satellite subscriber ids.
14865 *
14866 * @param list List of provisioned satellite subscriber ids.
14867 * @param result The result receiver that returns whether deliver success or fail.
14868 *
14869 * @throws SecurityException if the caller doesn't have the required permission.
14870 */
14871 @Override
Hyosun Kimb11f3ea2024-08-07 23:35:59 +000014872 public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014873 @NonNull ResultReceiver result) {
14874 enforceSatelliteCommunicationPermission("provisionSatellite");
Hyosun Kim0ab6b932024-08-16 04:45:09 +000014875 final long identity = Binder.clearCallingIdentity();
14876 try {
14877 mSatelliteController.provisionSatellite(list, result);
14878 } finally {
14879 Binder.restoreCallingIdentity(identity);
14880 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014881 }
Hyosund6aaf062024-08-23 23:02:10 +000014882
14883 /**
Hyosun Kim578cdcd2024-09-24 13:29:19 +000014884 * Deliver the list of deprovisioned satellite subscriber ids.
14885 *
14886 * @param list List of deprovisioned satellite subscriber ids.
14887 * @param result The result receiver that returns whether deliver success or fail.
14888 *
14889 * @throws SecurityException if the caller doesn't have the required permission.
14890 */
14891 @Override
14892 public void deprovisionSatellite(@NonNull List<SatelliteSubscriberInfo> list,
14893 @NonNull ResultReceiver result) {
14894 enforceSatelliteCommunicationPermission("deprovisionSatellite");
14895 final long identity = Binder.clearCallingIdentity();
14896 try {
14897 mSatelliteController.deprovisionSatellite(list, result);
14898 } finally {
14899 Binder.restoreCallingIdentity(identity);
14900 }
14901 }
14902
Aishwarya Mallampatia646bc12024-11-08 23:33:24 +000014903
14904 /**
14905 * Inform whether application supports NTN SMS in satellite mode.
14906 *
14907 * This method is used by default messaging application to inform framework whether it supports
14908 * NTN SMS or not.
14909 *
14910 * @param ntnSmsSupported {@code true} If application supports NTN SMS, else {@code false}.
14911 *
14912 * @throws SecurityException if the caller doesn't have required permission.
14913 */
14914 @Override
14915 public void setNtnSmsSupported(boolean ntnSmsSupported) {
14916 enforceSatelliteCommunicationPermission("setNtnSmsSupported");
14917 enforceSendSmsPermission();
Aishwarya Mallampatidcd19f32024-11-22 17:26:54 +000014918
14919 final long identity = Binder.clearCallingIdentity();
14920 try {
14921 mSatelliteController.setNtnSmsSupportedByMessagesApp(ntnSmsSupported);
14922 } finally {
14923 Binder.restoreCallingIdentity(identity);
14924 }
Aishwarya Mallampatia646bc12024-11-08 23:33:24 +000014925 }
14926
Hyosun Kim578cdcd2024-09-24 13:29:19 +000014927 /**
Hyosund6aaf062024-08-23 23:02:10 +000014928 * This API can be used by only CTS to override the cached value for the device overlay config
14929 * value :
14930 * config_satellite_gateway_service_package and
14931 * config_satellite_carrier_roaming_esos_provisioned_class.
14932 * These values are set before sending an intent to broadcast there are any change to list of
14933 * subscriber informations.
14934 *
14935 * @param name the name is one of the following that constitute an intent.
14936 * Component package name, or component class name.
14937 * @return {@code true} if the setting is successful, {@code false} otherwise.
14938 */
14939 @Override
14940 public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) {
14941 if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
14942 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:"
14943 + " carrierRoamingNbIotNtn is disabled");
14944 return false;
14945 }
14946 Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent");
14947 TelephonyPermissions.enforceShellOnly(
14948 Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent");
14949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14950 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14951 "setSatelliteSubscriberIdListChangedIntentComponent");
14952 final long identity = Binder.clearCallingIdentity();
14953 try {
14954 return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name);
14955 } finally {
14956 Binder.restoreCallingIdentity(identity);
14957 }
14958 }
Jack Yu26735292024-09-25 14:33:49 -070014959
14960 /**
14961 * This API can be used by only CTS to override the Euicc UI component.
14962 *
14963 * @param componentName ui component to be launched for testing. {@code null} to reset.
14964 *
14965 * @hide
14966 */
14967 @Override
14968 public void setTestEuiccUiComponent(@Nullable ComponentName componentName) {
14969 enforceModifyPermission();
14970 log("setTestEuiccUiComponent: " + componentName);
14971 mTestEuiccUiComponent = componentName;
14972 }
14973
14974 /**
14975 * This API can be used by only CTS to retrieve the Euicc UI component.
14976 *
14977 * @return Euicc UI component. {@code null} if not available.
14978 * @hide
14979 */
14980 @Override
14981 @Nullable
14982 public ComponentName getTestEuiccUiComponent() {
14983 enforceReadPrivilegedPermission("getTestEuiccUiComponent");
14984 return mTestEuiccUiComponent;
14985 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000014986
14987 /**
14988 * This API can be used only for test purpose to override the carrier roaming Ntn eligibility
14989 *
14990 * @param state to update Ntn Eligibility.
14991 * @param resetRequired to reset the overridden flag in satellite controller.
14992 * @return {@code true} if the shell command is successful, {@code false} otherwise.
14993 */
14994 public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state,
14995 boolean resetRequired) {
Hyosun322782b2024-10-24 11:37:59 +000014996 final long identity = Binder.clearCallingIdentity();
14997 try {
14998 return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state,
14999 resetRequired);
15000 } finally {
15001 Binder.restoreCallingIdentity(identity);
15002 }
arunvoddue3a6dbc2024-09-27 16:27:08 +000015003 }
jinjeongc29c54e2024-11-15 08:11:18 +000015004
15005 /**
15006 * Returns carrier id maps to the passing {@link CarrierIdentifier}.
15007 *
15008 * @param carrierIdentifier {@link CarrierIdentifier}.
15009 *
15010 * @return carrier id from passing {@link CarrierIdentifier} or UNKNOWN_CARRIER_ID
15011 * if the carrier cannot be identified
15012 */
15013 public int getCarrierIdFromIdentifier(@NonNull CarrierIdentifier carrierIdentifier) {
15014 enforceReadPrivilegedPermission("getCarrierIdFromIdentifier");
15015 enforceTelephonyFeatureWithException(getCurrentPackageName(),
15016 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromIdentifier");
15017
15018 final long identity = Binder.clearCallingIdentity();
15019 try {
15020 return CarrierResolver.getCarrierIdFromIdentifier(mApp, carrierIdentifier);
15021 } finally {
15022 Binder.restoreCallingIdentity(identity);
15023 }
15024 }
Jack Yufa8ed012023-02-11 15:42:28 -080015025}