blob: b3bd1310e6d57508e78e778c63a010f8da77b6e1 [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;
Thomas Nguyena8062672024-02-05 14:18:19 -080028import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080029import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
Hall Liud892bec2018-11-30 14:51:45 -080030
Shuo Qianccbaf742021-02-22 18:32:21 -080031import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
32import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070033import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070034import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000035import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070036
Brad Ebinger34c09a52021-02-17 23:23:21 +000037import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080038import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080039import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070040import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000041import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080042import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080044import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070045import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000046import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080047import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000048import android.compat.annotation.ChangeId;
49import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000050import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070051import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070052import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.content.Context;
54import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070055import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070056import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070057import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.net.Uri;
59import android.os.AsyncResult;
60import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080061import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080063import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070065import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080066import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080067import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.os.Looper;
69import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070070import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080071import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070072import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080074import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080075import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070076import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070077import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080078import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070080import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070081import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070082import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070083import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080084import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070085import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000086import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090087import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080088import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080089import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070090import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080091import android.telephony.AccessNetworkConstants;
92import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070093import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070094import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080095import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070096import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080097import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070098import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080099import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600100import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700101import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800102import android.telephony.CellIdentityCdma;
103import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700105import android.telephony.CellInfoGsm;
106import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700107import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700109import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700110import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700111import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800112import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700113import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800114import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700115import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800116import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800117import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700118import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800119import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800121import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800122import android.telephony.SignalStrengthUpdateRequest;
123import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800124import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800126import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700127import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800129import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800130import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800131import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800132import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000133import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000134import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000135import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700136import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700137import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800138import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800139import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700140import android.telephony.gba.GbaAuthRequest;
141import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700142import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800143import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000145import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700146import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000147import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700148import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800149import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700150import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800151import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700152import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000153import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700154import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800155import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800156import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000157import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000158import android.telephony.satellite.ISatelliteCapabilitiesCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800159import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000160import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800161import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000162import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800163import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000164import android.telephony.satellite.NtnSignalStrength;
165import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800166import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000167import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800168import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800169import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800170import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800172import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700173import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800175import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800176
Andrew Lee312e8172014-10-23 17:01:36 -0700177import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800178import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800179import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800180import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800181import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700183import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700184import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800185import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800186import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700187import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700188import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800189import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700190import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800191import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800192import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800193import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700194import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000195import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700196import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800197import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800199import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800200import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800201import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700202import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700203import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700204import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700206import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800207import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700208import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700209import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700210import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700211import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800212import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800213import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700214import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000215import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700216import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700217import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800218import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800219import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800220import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700221import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000222import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800223import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700224import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700225import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800226import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700227import com.android.internal.telephony.imsphone.ImsPhone;
228import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000229import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800230import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000231import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800232import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
233import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700234import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700235import com.android.internal.telephony.uicc.IccIoResult;
236import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800237import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700238import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700240import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000241import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800242import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000243import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800244import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000245import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700246import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700247import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800248import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800249import com.android.phone.callcomposer.CallComposerPictureManager;
250import com.android.phone.callcomposer.CallComposerPictureTransfer;
251import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800252import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000253import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700254import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700255import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000256import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700257import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800258import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700259import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700260import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800261import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800262import com.android.services.telephony.TelecomAccountRegistry;
263import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800264import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800265
Hall Liu82694d52020-12-11 18:22:04 -0800266import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700267import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800268import java.io.IOException;
269import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700270import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800272import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000273import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800274import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800275import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800276import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800277import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100278import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800279import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700280import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800281import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800282import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700283import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800284import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800285import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800286import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
288/**
289 * Implementation of the ITelephony interface.
290 */
Santos Cordon117fee72014-05-16 17:56:12 -0700291public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292 private static final String LOG_TAG = "PhoneInterfaceManager";
293 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
294 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800295 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296
297 // Message codes used with mMainThreadHandler
298 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700299 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
300 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700301 private static final int CMD_OPEN_CHANNEL = 9;
302 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
303 private static final int CMD_CLOSE_CHANNEL = 11;
304 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800305 private static final int CMD_NV_READ_ITEM = 13;
306 private static final int EVENT_NV_READ_ITEM_DONE = 14;
307 private static final int CMD_NV_WRITE_ITEM = 15;
308 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
309 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
310 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700311 private static final int CMD_RESET_MODEM_CONFIG = 19;
312 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800313 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
314 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800315 private static final int CMD_SEND_ENVELOPE = 25;
316 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700317 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
318 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
319 private static final int CMD_EXCHANGE_SIM_IO = 31;
320 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800321 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
322 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700323 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
324 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700325 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
326 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700327 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
328 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
329 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
330 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700331 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
332 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
333 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
334 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700335 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800336 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
337 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000338 private static final int CMD_SWITCH_SLOTS = 50;
339 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700340 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
341 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
342 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
343 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
344 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
345 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
346 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
347 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700348 private static final int CMD_GET_ALL_CELL_INFO = 60;
349 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
350 private static final int CMD_GET_CELL_LOCATION = 62;
351 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700352 private static final int CMD_MODEM_REBOOT = 64;
353 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700354 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
355 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800356 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
357 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700358 private static final int CMD_GET_MODEM_STATUS = 70;
359 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700360 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
361 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700362 private static final int CMD_ERASE_MODEM_CONFIG = 74;
363 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800364 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
365 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
366 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
367 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800368 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
369 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800370 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800371 private static final int CMD_GET_CALL_FORWARDING = 83;
372 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
373 private static final int CMD_SET_CALL_FORWARDING = 85;
374 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
375 private static final int CMD_GET_CALL_WAITING = 87;
376 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
377 private static final int CMD_SET_CALL_WAITING = 89;
378 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700379 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
380 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
381 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
382 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700383 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
384 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800385 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
386 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800387 private static final int CMD_SET_DATA_THROTTLING = 99;
388 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800389 private static final int CMD_SET_SIM_POWER = 101;
390 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800391 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
392 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
393 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
394 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800395 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
396 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000397 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800398 private static final int CMD_GET_SLICING_CONFIG = 110;
399 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800400 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700401 private static final int CMD_ENABLE_VONR = 113;
402 private static final int EVENT_ENABLE_VONR_DONE = 114;
403 private static final int CMD_IS_VONR_ENABLED = 115;
404 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700405 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
406 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000407
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800408 // Parameters of select command.
409 private static final int SELECT_COMMAND = 0xA4;
410 private static final int SELECT_P1 = 0x04;
411 private static final int SELECT_P2 = 0;
412 private static final int SELECT_P3 = 0x10;
413
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000414 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
415 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000416 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
417 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600418 // Null cipher notification support was added in IRadioNetwork 2.2
419 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000420
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 /** The singleton instance. */
422 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800423 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424
Sarah Chin4beb2b72023-02-14 14:47:54 -0800425 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000426 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800427 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800428 private final CallManager mCM;
429 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000430
431 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800432 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800433 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800434 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800435 private final SharedPreferences mTelephonySharedPreferences;
436 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800437 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700438 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000439 private PackageManager mPackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440
Peter Wangdafb9ac2020-01-15 14:13:38 -0800441 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800442 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800443 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800444 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800445
Derek Tan97ebb422014-09-05 16:55:38 -0700446 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
447 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800448 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800449 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700450
Michelecea4cf22018-12-21 15:00:11 -0800451 // String to store multi SIM allowed
452 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
453
Derek Tan740e1672017-06-27 14:56:27 -0700454 // The AID of ISD-R.
455 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
456
yinxub1bed742017-04-17 11:45:04 -0700457 private NetworkScanRequestTracker mNetworkScanRequestTracker;
458
David Kelly5e06a7f2018-03-12 14:10:59 +0000459 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
460 private static final int MANUFACTURER_CODE_LENGTH = 8;
461
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800462 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800463 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800464
Sarah Chin2ec39f62022-08-31 17:03:26 -0700465 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
466 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
467
Derek Tan89e89d42014-07-08 17:00:10 -0700468 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700469 * Experiment flag to enable erase modem config on reset network, default value is false
470 */
471 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
472 "reset_network_erase_modem_config_enabled";
473
Nathan Harolddc3bcec2024-05-16 14:06:40 -0700474 private static final int BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800475
Gary Jian76280a42022-12-07 16:18:33 +0800476 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
477
sandeepjsb6c87872021-09-27 15:34:44 +0000478 /**
479 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
480 * one ICCID active at the same time.
481 * Apps should use below API signatures if targeting SDK is T and beyond.
482 *
483 * @hide
484 */
485 @ChangeId
486 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
487 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800488
Naina Nallurid63128d2019-09-17 14:10:30 -0700489 /**
Chen Xu540470b2021-12-14 17:15:47 -0800490 * Apps targeting on Android T and beyond will get exception whenever icc close channel
491 * operation fails.
492 */
493 @ChangeId
494 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
495 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
496
497 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700498 * A request object to use for transmitting data to an ICC.
499 */
500 private static final class IccAPDUArgument {
501 public int channel, cla, command, p1, p2, p3;
502 public String data;
503
504 public IccAPDUArgument(int channel, int cla, int command,
505 int p1, int p2, int p3, String data) {
506 this.channel = channel;
507 this.cla = cla;
508 this.command = command;
509 this.p1 = p1;
510 this.p2 = p2;
511 this.p3 = p3;
512 this.data = data;
513 }
514 }
515
516 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700517 * A request object to use for transmitting data to an ICC.
518 */
519 private static final class ManualNetworkSelectionArgument {
520 public OperatorInfo operatorInfo;
521 public boolean persistSelection;
522
523 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
524 this.operatorInfo = operatorInfo;
525 this.persistSelection = persistSelection;
526 }
527 }
528
Sarah Chin71b3a852022-09-28 15:54:19 -0700529 private static final class PurchasePremiumCapabilityArgument {
530 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700531 public @NonNull IIntegerConsumer callback;
532
533 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800534 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700535 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700536 this.callback = callback;
537 }
538 }
539
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700540 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
542 * request after sending. The main thread will notify the request when it is complete.
543 */
544 private static final class MainThreadRequest {
545 /** The argument to use for the request */
546 public Object argument;
547 /** The result of the request that is run on the main thread */
548 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800549 // The subscriber id that this request applies to. Defaults to
550 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
551 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552
Nathan Harold92bed182018-10-12 18:16:49 -0700553 // In cases where subId is unavailable, the caller needs to specify the phone.
554 public Phone phone;
555
vagdeviaf9a5b92018-08-15 16:01:53 -0700556 public WorkSource workSource;
557
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700558 public MainThreadRequest(Object argument) {
559 this.argument = argument;
560 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800561
Nathan Harold92bed182018-10-12 18:16:49 -0700562 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
563 this.argument = argument;
564 if (phone != null) {
565 this.phone = phone;
566 }
567 this.workSource = workSource;
568 }
569
vagdeviaf9a5b92018-08-15 16:01:53 -0700570 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800571 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800572 if (subId != null) {
573 this.subId = subId;
574 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700575 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700577 }
578
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800579 private static final class IncomingThirdPartyCallArgs {
580 public final ComponentName component;
581 public final String callId;
582 public final String callerDisplayName;
583
584 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
585 String callerDisplayName) {
586 this.component = component;
587 this.callId = callId;
588 this.callerDisplayName = callerDisplayName;
589 }
590 }
591
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700592 /**
593 * A handler that processes messages on the main thread in the phone process. Since many
594 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
595 * inbound binder threads to the main thread in the phone process. The Binder thread
596 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
597 * on, which will be notified when the operation completes and will contain the result of the
598 * request.
599 *
600 * <p>If a MainThreadRequest object is provided in the msg.obj field,
601 * note that request.result must be set to something non-null for the calling thread to
602 * unblock.
603 */
604 private final class MainThreadHandler extends Handler {
605 @Override
606 public void handleMessage(Message msg) {
607 MainThreadRequest request;
608 Message onCompleted;
609 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000610 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800612 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700613
614 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 case CMD_HANDLE_USSD_REQUEST: {
616 request = (MainThreadRequest) msg.obj;
617 final Phone phone = getPhoneFromRequest(request);
618 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800619 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700621
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 if (!isUssdApiAllowed(request.subId)) {
623 // Carrier does not support use of this API, return failure.
624 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
625 UssdResponse response = new UssdResponse(ussdRequest, null);
626 Bundle returnData = new Bundle();
627 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
628 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700629
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 request.result = true;
631 notifyRequester(request);
632 return;
633 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700634
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 try {
636 request.result = phone != null
637 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
638 } catch (CallStateException cse) {
639 request.result = false;
640 }
641 // Wake up the requesting thread
642 notifyRequester(request);
643 break;
pkanwar32d516d2016-10-14 19:37:38 -0700644 }
645
Yorke Lee716f67e2015-06-17 15:39:16 -0700646 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700647 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700648 final Phone phone = getPhoneFromRequest(request);
649 request.result = phone != null ?
650 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
651 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700652 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700654 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700656
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000660 uiccPort = getUiccPortFromRequest(request);
661 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700662 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800663 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700664 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700665 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000668 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800669 iccArgument.channel, iccArgument.cla, iccArgument.command,
670 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
671 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 break;
674
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
678 if (ar.exception == null && ar.result != null) {
679 request.result = ar.result;
680 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800681 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 if (ar.result == null) {
683 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800684 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800686 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 } else {
688 loge("iccTransmitApduLogicalChannel: Unknown exception");
689 }
690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 break;
693
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700694 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
695 request = (MainThreadRequest) msg.obj;
696 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000697 uiccPort = getUiccPortFromRequest(request);
698 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800700 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700701 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700702 } else {
703 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800704 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000705 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800706 iccArgument.cla, iccArgument.command, iccArgument.p1,
707 iccArgument.p2,
708 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 }
710 break;
711
712 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
713 ar = (AsyncResult) msg.obj;
714 request = (MainThreadRequest) ar.userObj;
715 if (ar.exception == null && ar.result != null) {
716 request.result = ar.result;
717 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800718 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700719 if (ar.result == null) {
720 loge("iccTransmitApduBasicChannel: Empty response");
721 } else if (ar.exception instanceof CommandException) {
722 loge("iccTransmitApduBasicChannel: CommandException: " +
723 ar.exception);
724 } else {
725 loge("iccTransmitApduBasicChannel: Unknown exception");
726 }
727 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700729 break;
730
731 case CMD_EXCHANGE_SIM_IO:
732 request = (MainThreadRequest) msg.obj;
733 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000734 uiccPort = getUiccPortFromRequest(request);
735 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700736 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800737 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700738 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 } else {
740 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
741 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000742 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
744 iccArgument.data, onCompleted);
745 }
746 break;
747
748 case EVENT_EXCHANGE_SIM_IO_DONE:
749 ar = (AsyncResult) msg.obj;
750 request = (MainThreadRequest) ar.userObj;
751 if (ar.exception == null && ar.result != null) {
752 request.result = ar.result;
753 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800754 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700755 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700756 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700757 break;
758
Derek Tan4d5e5c12014-02-04 11:54:58 -0800759 case CMD_SEND_ENVELOPE:
760 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000761 uiccPort = getUiccPortFromRequest(request);
762 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700763 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800764 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700765 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700766 } else {
767 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800768 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700769 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800770 break;
771
772 case EVENT_SEND_ENVELOPE_DONE:
773 ar = (AsyncResult) msg.obj;
774 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700775 if (ar.exception == null && ar.result != null) {
776 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800777 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800778 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700779 if (ar.result == null) {
780 loge("sendEnvelopeWithStatus: Empty response");
781 } else if (ar.exception instanceof CommandException) {
782 loge("sendEnvelopeWithStatus: CommandException: " +
783 ar.exception);
784 } else {
785 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
786 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800787 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700788 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800789 break;
790
Shishir Agrawal566b7612013-10-28 14:41:00 -0700791 case CMD_OPEN_CHANNEL:
792 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000793 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800794 IccLogicalChannelRequest openChannelRequest =
795 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000796 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700797 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800798 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800799 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700800 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700801 } else {
802 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800803 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
804 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700805 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700806 break;
807
808 case EVENT_OPEN_CHANNEL_DONE:
809 ar = (AsyncResult) msg.obj;
810 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700811 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700813 int[] result = (int[]) ar.result;
814 int channelId = result[0];
815 byte[] selectResponse = null;
816 if (result.length > 1) {
817 selectResponse = new byte[result.length - 1];
818 for (int i = 1; i < result.length; ++i) {
819 selectResponse[i - 1] = (byte) result[i];
820 }
821 }
822 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800823 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800824
825 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700826 if (uiccPort == null) {
827 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
828 } else {
829 IccLogicalChannelRequest channelRequest =
830 (IccLogicalChannelRequest) request.argument;
831 channelRequest.channel = channelId;
832 uiccPort.onLogicalChannelOpened(channelRequest);
833 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700834 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 if (ar.result == null) {
836 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700837 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700838 if (ar.exception != null) {
839 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
840 }
841
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700842 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700843 if (ar.exception instanceof CommandException) {
844 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800845 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700846 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700847 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700848 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700849 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700850 }
851 }
852 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800853 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700854 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700855 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700856 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700857 break;
858
859 case CMD_CLOSE_CHANNEL:
860 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000861 uiccPort = getUiccPortFromRequest(request);
862 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700863 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800864 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800865 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800866 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700867 } else {
868 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000869 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700870 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700871 break;
872
873 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800874 ar = (AsyncResult) msg.obj;
875 request = (MainThreadRequest) ar.userObj;
876 if (ar.exception == null) {
877 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800878 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700879 if (uiccPort == null) {
880 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
881 } else {
882 final int channelId = (Integer) request.argument;
883 uiccPort.onLogicalChannelClosed(channelId);
884 }
Chen Xu540470b2021-12-14 17:15:47 -0800885 } else {
886 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800887 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800888 if (ar.exception instanceof CommandException) {
889 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
890 CommandException.Error error =
891 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800892 if (error == CommandException.Error.INVALID_ARGUMENTS) {
893 // should only throw exceptions from the binder threads.
894 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800895 "iccCloseLogicalChannel: invalid argument ");
896 }
897 } else {
898 loge("iccCloseLogicalChannel: Unknown exception");
899 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800900 request.result = (exception != null) ? exception :
901 new IllegalStateException(
902 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800903 }
904 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800905 break;
906
907 case CMD_NV_READ_ITEM:
908 request = (MainThreadRequest) msg.obj;
909 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800910 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
911 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800912 break;
913
914 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700915 ar = (AsyncResult) msg.obj;
916 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800917 if (ar.exception == null && ar.result != null) {
918 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700919 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800920 request.result = "";
921 if (ar.result == null) {
922 loge("nvReadItem: Empty response");
923 } else if (ar.exception instanceof CommandException) {
924 loge("nvReadItem: CommandException: " +
925 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700926 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800927 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700928 }
929 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700930 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700931 break;
932
Jake Hambye994d462014-02-03 13:10:13 -0800933 case CMD_NV_WRITE_ITEM:
934 request = (MainThreadRequest) msg.obj;
935 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
936 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800937 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700938 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800939 break;
940
941 case EVENT_NV_WRITE_ITEM_DONE:
942 handleNullReturnEvent(msg, "nvWriteItem");
943 break;
944
945 case CMD_NV_WRITE_CDMA_PRL:
946 request = (MainThreadRequest) msg.obj;
947 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800948 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800949 break;
950
951 case EVENT_NV_WRITE_CDMA_PRL_DONE:
952 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
953 break;
954
chen xu6dac5ab2018-10-26 17:39:23 -0700955 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800956 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700957 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800958 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800959 break;
960
chen xu6dac5ab2018-10-26 17:39:23 -0700961 case EVENT_RESET_MODEM_CONFIG_DONE:
962 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800963 break;
964
Sooraj Sasindran37444802020-08-11 10:40:43 -0700965 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
968 request);
969 Phone phone = getPhoneFromRequest(request);
970 if (phone != null) {
971 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
972 } else {
973 loge("isNRDualConnectivityEnabled: No phone object");
974 request.result = false;
975 notifyRequester(request);
976 }
977 break;
978 }
979
980 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 if (ar.exception == null && ar.result != null) {
984 request.result = ar.result;
985 } else {
986 // request.result must be set to something non-null
987 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700988 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700989 request.result = ar.result;
990 } else {
991 request.result = false;
992 }
993 if (ar.result == null) {
994 loge("isNRDualConnectivityEnabled: Empty response");
995 } else if (ar.exception instanceof CommandException) {
996 loge("isNRDualConnectivityEnabled: CommandException: "
997 + ar.exception);
998 } else {
999 loge("isNRDualConnectivityEnabled: Unknown exception");
1000 }
1001 }
1002 notifyRequester(request);
1003 break;
1004
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001005 case CMD_IS_VONR_ENABLED: {
1006 request = (MainThreadRequest) msg.obj;
1007 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1008 request);
1009 Phone phone = getPhoneFromRequest(request);
1010 if (phone != null) {
1011 phone.isVoNrEnabled(onCompleted, request.workSource);
1012 } else {
1013 loge("isVoNrEnabled: No phone object");
1014 request.result = false;
1015 notifyRequester(request);
1016 }
1017 break;
1018 }
1019
1020 case EVENT_IS_VONR_ENABLED_DONE:
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 if (ar.exception == null && ar.result != null) {
1024 request.result = ar.result;
1025 } else {
1026 // request.result must be set to something non-null
1027 // for the calling thread to unblock
1028 if (ar.result != null) {
1029 request.result = ar.result;
1030 } else {
1031 request.result = false;
1032 }
1033 if (ar.result == null) {
1034 loge("isVoNrEnabled: Empty response");
1035 } else if (ar.exception instanceof CommandException) {
1036 loge("isVoNrEnabled: CommandException: "
1037 + ar.exception);
1038 } else {
1039 loge("isVoNrEnabled: Unknown exception");
1040 }
1041 }
1042 notifyRequester(request);
1043 break;
1044
Sooraj Sasindran37444802020-08-11 10:40:43 -07001045 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1046 request = (MainThreadRequest) msg.obj;
1047 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1048 Phone phone = getPhoneFromRequest(request);
1049 if (phone != null) {
1050 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1051 request.workSource);
1052 } else {
1053 loge("enableNrDualConnectivity: No phone object");
1054 request.result =
1055 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1056 notifyRequester(request);
1057 }
1058 break;
1059 }
1060
1061 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1062 ar = (AsyncResult) msg.obj;
1063 request = (MainThreadRequest) ar.userObj;
1064 if (ar.exception == null) {
1065 request.result =
1066 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1067 } else {
1068 request.result =
1069 TelephonyManager
1070 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1071 if (ar.exception instanceof CommandException) {
1072 CommandException.Error error =
1073 ((CommandException) (ar.exception)).getCommandError();
1074 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1075 request.result =
1076 TelephonyManager
1077 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001078 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1079 request.result =
1080 TelephonyManager
1081 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001082 }
1083 loge("enableNrDualConnectivity" + ": CommandException: "
1084 + ar.exception);
1085 } else {
1086 loge("enableNrDualConnectivity" + ": Unknown exception");
1087 }
1088 }
1089 notifyRequester(request);
1090 break;
1091 }
1092
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001093 case CMD_ENABLE_VONR: {
1094 request = (MainThreadRequest) msg.obj;
1095 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1096 Phone phone = getPhoneFromRequest(request);
1097 if (phone != null) {
1098 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1099 request.workSource);
1100 } else {
1101 loge("setVoNrEnabled: No phone object");
1102 request.result =
1103 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1104 notifyRequester(request);
1105 }
1106 break;
1107 }
1108
1109 case EVENT_ENABLE_VONR_DONE: {
1110 ar = (AsyncResult) msg.obj;
1111 request = (MainThreadRequest) ar.userObj;
1112 if (ar.exception == null) {
1113 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1114 } else {
1115 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1116 if (ar.exception instanceof CommandException) {
1117 CommandException.Error error =
1118 ((CommandException) (ar.exception)).getCommandError();
1119 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1120 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1121 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1122 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1123 } else {
1124 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1125 }
1126 loge("setVoNrEnabled" + ": CommandException: "
1127 + ar.exception);
1128 } else {
1129 loge("setVoNrEnabled" + ": Unknown exception");
1130 }
1131 }
1132 notifyRequester(request);
1133 break;
1134 }
1135
SongFerngWang3ef3e072020-12-21 16:41:52 +08001136 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001137 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001138 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1139 request);
1140 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 break;
1142
SongFerngWang3ef3e072020-12-21 16:41:52 +08001143 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001144 ar = (AsyncResult) msg.obj;
1145 request = (MainThreadRequest) ar.userObj;
1146 if (ar.exception == null && ar.result != null) {
1147 request.result = ar.result; // Integer
1148 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301149 // request.result must be set to something non-null
1150 // for the calling thread to unblock
1151 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001152 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001153 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001154 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001155 loge("getAllowedNetworkTypesBitmask: CommandException: "
1156 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001157 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001158 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001159 }
1160 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001161 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001162 break;
1163
SongFerngWang3ef3e072020-12-21 16:41:52 +08001164 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001165 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001166 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1167 request);
1168 Pair<Integer, Long> reasonWithNetworkTypes =
1169 (Pair<Integer, Long>) request.argument;
1170 getPhoneFromRequest(request).setAllowedNetworkTypes(
1171 reasonWithNetworkTypes.first,
1172 reasonWithNetworkTypes.second,
1173 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001174 break;
1175
SongFerngWang3ef3e072020-12-21 16:41:52 +08001176 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1177 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001178 break;
1179
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001180 case CMD_SET_VOICEMAIL_NUMBER:
1181 request = (MainThreadRequest) msg.obj;
1182 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1183 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001184 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1185 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001186 break;
1187
1188 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1189 handleNullReturnEvent(msg, "setVoicemailNumber");
1190 break;
1191
Stuart Scott54788802015-03-30 13:18:01 -07001192 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1193 request = (MainThreadRequest) msg.obj;
1194 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1195 request);
1196 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1197 break;
1198
1199 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1200 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1201 break;
1202
Shishir Agrawal302c8692015-06-19 13:49:39 -07001203 case CMD_PERFORM_NETWORK_SCAN:
1204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1206 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1207 break;
1208
Hall Liu27d24262020-09-18 19:04:59 -07001209 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001210 request = (MainThreadRequest) msg.obj;
1211 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001212 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1213 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1214 request.argument;
1215 int callForwardingReason = args.first;
1216 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001217 break;
Hall Liu27d24262020-09-18 19:04:59 -07001218 }
1219 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001220 ar = (AsyncResult) msg.obj;
1221 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001222 TelephonyManager.CallForwardingInfoCallback callback =
1223 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1224 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001225 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001226 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1228 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1229 // Service Class is a bit mask per 3gpp 27.007. Search for
1230 // any service for voice call.
1231 if ((callForwardInfo.serviceClass
1232 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001233 callForwardingInfo = new CallForwardingInfo(
1234 callForwardInfo.status
1235 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001236 callForwardInfo.reason,
1237 callForwardInfo.number,
1238 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001239 break;
1240 }
1241 }
1242 // Didn't find a call forward info for voice call.
1243 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001244 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1245 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001246 }
Hall Liu27d24262020-09-18 19:04:59 -07001247 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001248 } else {
1249 if (ar.result == null) {
1250 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1251 }
1252 if (ar.exception != null) {
1253 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1254 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001255 int errorCode = TelephonyManager
1256 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001257 if (ar.exception instanceof CommandException) {
1258 CommandException.Error error =
1259 ((CommandException) (ar.exception)).getCommandError();
1260 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001261 errorCode = TelephonyManager
1262 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001263 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001264 errorCode = TelephonyManager
1265 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001266 }
1267 }
Hall Liu27d24262020-09-18 19:04:59 -07001268 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001269 }
Shuo Qian4a594052020-01-23 11:59:30 -08001270 break;
Hall Liu27d24262020-09-18 19:04:59 -07001271 }
Shuo Qian4a594052020-01-23 11:59:30 -08001272
Hall Liu27d24262020-09-18 19:04:59 -07001273 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001274 request = (MainThreadRequest) msg.obj;
1275 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001276 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001277 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001278 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1279 request.argument).first;
1280 request.phone.setCallForwardingOption(
1281 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001282 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001283 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001284 callForwardingInfoToSet.getReason(),
1285 callForwardingInfoToSet.getNumber(),
1286 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1287 break;
Hall Liu27d24262020-09-18 19:04:59 -07001288 }
Shuo Qian4a594052020-01-23 11:59:30 -08001289
Hall Liu27d24262020-09-18 19:04:59 -07001290 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001291 ar = (AsyncResult) msg.obj;
1292 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001293 Consumer<Integer> callback =
1294 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1295 request.argument).second;
1296 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001297 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001298 int errorCode = TelephonyManager.CallForwardingInfoCallback
1299 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001300 if (ar.exception instanceof CommandException) {
1301 CommandException.Error error =
1302 ((CommandException) (ar.exception)).getCommandError();
1303 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001304 errorCode = TelephonyManager.CallForwardingInfoCallback
1305 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001306 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001307 errorCode = TelephonyManager.CallForwardingInfoCallback
1308 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001309 }
1310 }
1311 callback.accept(errorCode);
1312 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001313 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001314 }
Shuo Qian4a594052020-01-23 11:59:30 -08001315 break;
Hall Liu27d24262020-09-18 19:04:59 -07001316 }
Shuo Qian4a594052020-01-23 11:59:30 -08001317
Hall Liu27d24262020-09-18 19:04:59 -07001318 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001319 request = (MainThreadRequest) msg.obj;
1320 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1321 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1322 break;
Hall Liu27d24262020-09-18 19:04:59 -07001323 }
Shuo Qian4a594052020-01-23 11:59:30 -08001324
Hall Liu27d24262020-09-18 19:04:59 -07001325 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001326 ar = (AsyncResult) msg.obj;
1327 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001328 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001329 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001330 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001331 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001332 // Service Class is a bit mask per 3gpp 27.007.
1333 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001334 if (callForwardResults.length > 1
1335 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001336 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001337 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001338 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1339 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001340 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001341 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001342 }
1343 } else {
1344 if (ar.result == null) {
1345 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1346 }
1347 if (ar.exception != null) {
1348 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1349 }
1350 if (ar.exception instanceof CommandException) {
1351 CommandException.Error error =
1352 ((CommandException) (ar.exception)).getCommandError();
1353 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001354 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001355 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001356 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1357 callWaitingStatus =
1358 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001359 }
1360 }
1361 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001362 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001363 break;
Hall Liu27d24262020-09-18 19:04:59 -07001364 }
Shuo Qian4a594052020-01-23 11:59:30 -08001365
Hall Liu27d24262020-09-18 19:04:59 -07001366 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001367 request = (MainThreadRequest) msg.obj;
1368 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001369 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1370 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001371 break;
Hall Liu27d24262020-09-18 19:04:59 -07001372 }
Shuo Qian4a594052020-01-23 11:59:30 -08001373
Hall Liu27d24262020-09-18 19:04:59 -07001374 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001375 ar = (AsyncResult) msg.obj;
1376 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001377 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1378 Consumer<Integer> callback =
1379 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1380 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001381 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001382 if (ar.exception instanceof CommandException) {
1383 CommandException.Error error =
1384 ((CommandException) (ar.exception)).getCommandError();
1385 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1386 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001387 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1388 callback.accept(
1389 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001390 } else {
1391 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1392 }
1393 } else {
1394 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1395 }
1396 } else {
1397 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1398 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001399 }
Shuo Qian4a594052020-01-23 11:59:30 -08001400 break;
Hall Liu27d24262020-09-18 19:04:59 -07001401 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001402 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1403 ar = (AsyncResult) msg.obj;
1404 request = (MainThreadRequest) ar.userObj;
1405 CellNetworkScanResult cellScanResult;
1406 if (ar.exception == null && ar.result != null) {
1407 cellScanResult = new CellNetworkScanResult(
1408 CellNetworkScanResult.STATUS_SUCCESS,
1409 (List<OperatorInfo>) ar.result);
1410 } else {
1411 if (ar.result == null) {
1412 loge("getCellNetworkScanResults: Empty response");
1413 }
1414 if (ar.exception != null) {
1415 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1416 }
1417 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1418 if (ar.exception instanceof CommandException) {
1419 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001420 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001421 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1422 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1423 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1424 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1425 }
1426 }
1427 cellScanResult = new CellNetworkScanResult(errorCode, null);
1428 }
1429 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001430 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001431 break;
1432
1433 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1434 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001435 ManualNetworkSelectionArgument selArg =
1436 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001437 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1438 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001439 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1440 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001441 break;
1442
1443 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001444 ar = (AsyncResult) msg.obj;
1445 request = (MainThreadRequest) ar.userObj;
1446 if (ar.exception == null) {
1447 request.result = true;
1448 } else {
1449 request.result = false;
1450 loge("setNetworkSelectionModeManual " + ar.exception);
1451 }
1452 notifyRequester(request);
1453 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001454 break;
1455
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001456 case CMD_GET_MODEM_ACTIVITY_INFO:
1457 request = (MainThreadRequest) msg.obj;
1458 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001459 if (defaultPhone != null) {
1460 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001461 } else {
1462 ResultReceiver result = (ResultReceiver) request.argument;
1463 Bundle bundle = new Bundle();
1464 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001465 new ModemActivityInfo(0, 0, 0,
1466 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001467 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001468 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001469 break;
1470
Hall Liud0f208c2020-10-14 16:54:44 -07001471 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001472 ar = (AsyncResult) msg.obj;
1473 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001474 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001475 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001476 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001477 if (mLastModemActivityInfo == null) {
1478 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1479 mLastModemActivitySpecificInfo[0] =
1480 new ActivityStatsTechSpecificInfo(
1481 0,
1482 0,
1483 new int[ModemActivityInfo.getNumTxPowerLevels()],
1484 0);
1485 mLastModemActivityInfo =
1486 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1487 }
1488
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001489 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001490 // Update the last modem activity info and the result of the request.
1491 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1492 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001493 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001494 } else {
1495 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001496 }
Kai Shi917fdc62022-11-28 14:01:02 -08001497 // This is needed to decouple ret from mLastModemActivityInfo
1498 // We don't want to return mLastModemActivityInfo which is updated
1499 // inside mergeModemActivityInfo()
1500 ret = new ModemActivityInfo(
1501 mLastModemActivityInfo.getTimestampMillis(),
1502 mLastModemActivityInfo.getSleepTimeMillis(),
1503 mLastModemActivityInfo.getIdleTimeMillis(),
1504 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001505
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001506 } else {
1507 if (ar.result == null) {
1508 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001509 error = TelephonyManager.ModemActivityInfoException
1510 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001511 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001512 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001513 error = TelephonyManager.ModemActivityInfoException
1514 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001515 } else {
1516 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001517 error = TelephonyManager.ModemActivityInfoException
1518 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001519 }
1520 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001521 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001522 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001523 bundle.putParcelable(
1524 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001525 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001526 } else {
1527 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1528 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001529 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001530 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001531 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001532 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001533
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001534 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001535 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001536 CarrierRestrictionRules argument =
1537 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001538 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001539 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001540 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001541 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001542
1543 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1544 ar = (AsyncResult) msg.obj;
1545 request = (MainThreadRequest) ar.userObj;
1546 if (ar.exception == null && ar.result != null) {
1547 request.result = ar.result;
1548 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001549 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1550 if (ar.exception instanceof CommandException) {
1551 loge("setAllowedCarriers: CommandException: " + ar.exception);
1552 CommandException.Error error =
1553 ((CommandException) (ar.exception)).getCommandError();
1554 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1555 request.result =
1556 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1557 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001558 } else {
1559 loge("setAllowedCarriers: Unknown exception");
1560 }
1561 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001562 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001563 break;
1564
1565 case CMD_GET_ALLOWED_CARRIERS:
1566 request = (MainThreadRequest) msg.obj;
1567 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001568 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001569 break;
1570
1571 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1572 ar = (AsyncResult) msg.obj;
1573 request = (MainThreadRequest) ar.userObj;
1574 if (ar.exception == null && ar.result != null) {
1575 request.result = ar.result;
1576 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001577 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001578 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001579 if (ar.result == null) {
1580 loge("getAllowedCarriers: Empty response");
1581 } else if (ar.exception instanceof CommandException) {
1582 loge("getAllowedCarriers: CommandException: " +
1583 ar.exception);
1584 } else {
1585 loge("getAllowedCarriers: Unknown exception");
1586 }
1587 }
arunvoddud7401012022-12-15 16:08:12 +00001588 if (request.argument != null) {
1589 // This is for the implementation of carrierRestrictionStatus.
1590 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1591 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001592 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001593 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1594 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1595 CarrierRestrictionRules carrierRestrictionRules =
1596 (CarrierRestrictionRules) ar.result;
1597 int carrierId = -1;
1598 try {
1599 CarrierIdentifier carrierIdentifier =
1600 carrierRestrictionRules.getAllowedCarriers().get(0);
1601 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1602 carrierIdentifier);
1603 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1604 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1605 }
1606 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001607 int restrictedStatus =
1608 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1609 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1610 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001611 lockStatus = TelephonyManager
1612 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001613 }
1614 } else {
1615 Rlog.e(LOG_TAG,
1616 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1617 }
1618 callback.accept(lockStatus);
1619 } else {
1620 // This is for the implementation of getAllowedCarriers.
1621 notifyRequester(request);
1622 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001623 break;
1624
Nathan Haroldb3014052017-01-25 15:57:32 -08001625 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1626 ar = (AsyncResult) msg.obj;
1627 request = (MainThreadRequest) ar.userObj;
1628 if (ar.exception == null && ar.result != null) {
1629 request.result = ar.result;
1630 } else {
1631 request.result = new IllegalArgumentException(
1632 "Failed to retrieve Forbidden Plmns");
1633 if (ar.result == null) {
1634 loge("getForbiddenPlmns: Empty response");
1635 } else {
1636 loge("getForbiddenPlmns: Unknown exception");
1637 }
1638 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001639 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001640 break;
1641
1642 case CMD_GET_FORBIDDEN_PLMNS:
1643 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001644 uiccPort = getUiccPortFromRequest(request);
1645 if (uiccPort == null) {
1646 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001647 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001648 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001649 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001650 break;
1651 }
1652 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001653 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001654 if (uiccApp == null) {
1655 loge("getForbiddenPlmns() no app with specified type -- "
1656 + appType);
1657 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001658 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001659 break;
1660 } else {
1661 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1662 + " specified type -- " + appType);
1663 }
1664 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1665 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001666 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001667 break;
1668
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001669 case CMD_SWITCH_SLOTS:
1670 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001671 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001672 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001673 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001674 break;
1675
1676 case EVENT_SWITCH_SLOTS_DONE:
1677 ar = (AsyncResult) msg.obj;
1678 request = (MainThreadRequest) ar.userObj;
1679 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001680 notifyRequester(request);
1681 break;
1682 case CMD_GET_NETWORK_SELECTION_MODE:
1683 request = (MainThreadRequest) msg.obj;
1684 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1685 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1686 break;
1687
1688 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1689 ar = (AsyncResult) msg.obj;
1690 request = (MainThreadRequest) ar.userObj;
1691 if (ar.exception != null) {
1692 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1693 } else {
1694 int mode = ((int[]) ar.result)[0];
1695 if (mode == 0) {
1696 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1697 } else {
1698 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1699 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001700 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001701 notifyRequester(request);
1702 break;
1703 case CMD_GET_CDMA_ROAMING_MODE:
1704 request = (MainThreadRequest) msg.obj;
1705 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1706 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1707 break;
1708 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1709 ar = (AsyncResult) msg.obj;
1710 request = (MainThreadRequest) ar.userObj;
1711 if (ar.exception != null) {
1712 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1713 } else {
1714 request.result = ((int[]) ar.result)[0];
1715 }
1716 notifyRequester(request);
1717 break;
1718 case CMD_SET_CDMA_ROAMING_MODE:
1719 request = (MainThreadRequest) msg.obj;
1720 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1721 int mode = (int) request.argument;
1722 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1723 break;
1724 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1725 ar = (AsyncResult) msg.obj;
1726 request = (MainThreadRequest) ar.userObj;
1727 request.result = ar.exception == null;
1728 notifyRequester(request);
1729 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001730 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1731 request = (MainThreadRequest) msg.obj;
1732 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1733 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1734 break;
1735 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1736 ar = (AsyncResult) msg.obj;
1737 request = (MainThreadRequest) ar.userObj;
1738 if (ar.exception != null) {
1739 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1740 } else {
1741 request.result = ((int[]) ar.result)[0];
1742 }
1743 notifyRequester(request);
1744 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001745 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1748 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001749 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1750 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001751 break;
1752 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1753 ar = (AsyncResult) msg.obj;
1754 request = (MainThreadRequest) ar.userObj;
1755 request.result = ar.exception == null;
1756 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001757 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001758 case CMD_GET_ALL_CELL_INFO:
1759 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001760 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001761 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001762 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001763 case EVENT_GET_ALL_CELL_INFO_DONE:
1764 ar = (AsyncResult) msg.obj;
1765 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001766 // If a timeout occurs, the response will be null
1767 request.result = (ar.exception == null && ar.result != null)
1768 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001769 synchronized (request) {
1770 request.notifyAll();
1771 }
1772 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001773 case CMD_REQUEST_CELL_INFO_UPDATE:
1774 request = (MainThreadRequest) msg.obj;
1775 request.phone.requestCellInfoUpdate(request.workSource,
1776 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1777 break;
1778 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1779 ar = (AsyncResult) msg.obj;
1780 request = (MainThreadRequest) ar.userObj;
1781 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1782 try {
1783 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001784 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001785 cb.onError(
1786 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1787 ar.exception.getClass().getName(),
1788 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001789 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001790 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001791 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001792 } else {
1793 // use the result as returned
1794 cb.onCellInfo((List<CellInfo>) ar.result);
1795 }
1796 } catch (RemoteException re) {
1797 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1798 }
1799 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001800 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001801 request = (MainThreadRequest) msg.obj;
1802 WorkSource ws = (WorkSource) request.argument;
1803 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001804 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001806 }
1807 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001808 ar = (AsyncResult) msg.obj;
1809 request = (MainThreadRequest) ar.userObj;
1810 if (ar.exception == null) {
1811 request.result = ar.result;
1812 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001813 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001814 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001815 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001816 }
1817
1818 synchronized (request) {
1819 request.notifyAll();
1820 }
1821 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001822 }
chen xu6dac5ab2018-10-26 17:39:23 -07001823 case CMD_MODEM_REBOOT:
1824 request = (MainThreadRequest) msg.obj;
1825 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001826 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001827 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001828 case EVENT_CMD_MODEM_REBOOT_DONE:
1829 handleNullReturnEvent(msg, "rebootModem");
1830 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001831 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001832 request = (MainThreadRequest) msg.obj;
1833 boolean enable = (boolean) request.argument;
1834 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001835 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001836 PhoneConfigurationManager.getInstance()
1837 .enablePhone(request.phone, enable, onCompleted);
1838 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001839 }
Michele Berionne5e411512020-11-13 02:36:59 +00001840 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001841 ar = (AsyncResult) msg.obj;
1842 request = (MainThreadRequest) ar.userObj;
1843 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001844 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001845 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001846 if ((boolean) request.result) {
1847 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1848 updateModemStateMetrics();
1849 } else {
1850 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1851 + ar.exception);
1852 }
1853 notifyRequester(request);
1854 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001855 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001856 case CMD_GET_MODEM_STATUS:
1857 request = (MainThreadRequest) msg.obj;
1858 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1859 PhoneConfigurationManager.getInstance()
1860 .getPhoneStatusFromModem(request.phone, onCompleted);
1861 break;
1862 case EVENT_GET_MODEM_STATUS_DONE:
1863 ar = (AsyncResult) msg.obj;
1864 request = (MainThreadRequest) ar.userObj;
1865 int id = request.phone.getPhoneId();
1866 if (ar.exception == null && ar.result != null) {
1867 request.result = ar.result;
1868 //update the cache as modem status has changed
1869 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1870 (boolean) request.result);
1871 } else {
1872 // Return true if modem status cannot be retrieved. For most cases,
1873 // modem status is on. And for older version modems, GET_MODEM_STATUS
1874 // and disable modem are not supported. Modem is always on.
1875 // TODO: this should be fixed in R to support a third
1876 // status UNKNOWN b/131631629
1877 request.result = true;
1878 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1879 + ar.exception);
1880 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001881 notifyRequester(request);
1882 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001883 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1884 request = (MainThreadRequest) msg.obj;
1885 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1886 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1887 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1888 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1889 break;
1890 }
1891 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1892 ar = (AsyncResult) msg.obj;
1893 request = (MainThreadRequest) ar.userObj;
1894 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1895 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1896 args.second.accept(ar.exception == null);
1897 notifyRequester(request);
1898 break;
1899 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001900 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1901 request = (MainThreadRequest) msg.obj;
1902 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1903 Phone phone = getPhoneFromRequest(request);
1904 if (phone != null) {
1905 phone.getSystemSelectionChannels(onCompleted);
1906 } else {
1907 loge("getSystemSelectionChannels: No phone object");
1908 request.result = new ArrayList<RadioAccessSpecifier>();
1909 notifyRequester(request);
1910 }
1911 break;
1912 }
1913 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1914 ar = (AsyncResult) msg.obj;
1915 request = (MainThreadRequest) ar.userObj;
1916 if (ar.exception == null && ar.result != null) {
1917 request.result = ar.result;
1918 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001919 request.result = new IllegalStateException(
1920 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001921 if (ar.result == null) {
1922 loge("getSystemSelectionChannels: Empty response");
1923 } else {
1924 loge("getSystemSelectionChannels: Unknown exception");
1925 }
1926 }
1927 notifyRequester(request);
1928 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001929 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1930 ar = (AsyncResult) msg.obj;
1931 request = (MainThreadRequest) ar.userObj;
1932 if (ar.exception == null && ar.result != null) {
1933 request.result = ar.result;
1934 } else {
1935 request.result = -1;
1936 loge("Failed to set Forbidden Plmns");
1937 if (ar.result == null) {
1938 loge("setForbidenPlmns: Empty response");
1939 } else if (ar.exception != null) {
1940 loge("setForbiddenPlmns: Exception: " + ar.exception);
1941 request.result = -1;
1942 } else {
1943 loge("setForbiddenPlmns: Unknown exception");
1944 }
1945 }
1946 notifyRequester(request);
1947 break;
1948 case CMD_SET_FORBIDDEN_PLMNS:
1949 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001950 uiccPort = getUiccPortFromRequest(request);
1951 if (uiccPort == null) {
1952 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001953 request.result = -1;
1954 notifyRequester(request);
1955 break;
1956 }
1957 Pair<Integer, List<String>> setFplmnsArgs =
1958 (Pair<Integer, List<String>>) request.argument;
1959 appType = setFplmnsArgs.first;
1960 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001961 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001962 if (uiccApp == null) {
1963 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1964 request.result = -1;
1965 loge("Failed to get UICC App");
1966 notifyRequester(request);
1967 } else {
1968 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1969 ((SIMRecords) uiccApp.getIccRecords())
1970 .setForbiddenPlmns(onCompleted, fplmns);
1971 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001972 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001973 case CMD_ERASE_MODEM_CONFIG:
1974 request = (MainThreadRequest) msg.obj;
1975 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1976 defaultPhone.eraseModemConfig(onCompleted);
1977 break;
1978 case EVENT_ERASE_MODEM_CONFIG_DONE:
1979 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001980 break;
zoey chene02881a2019-12-30 16:11:23 +08001981
Kai Shif70f46f2021-03-03 13:59:46 -08001982 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1983 request = (MainThreadRequest) msg.obj;
1984 request.result = defaultPhone.eraseDataInSharedPreferences();
1985 notifyRequester(request);
1986 break;
1987
zoey chene02881a2019-12-30 16:11:23 +08001988 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1989 request = (MainThreadRequest) msg.obj;
1990 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1991 Pair<String, String> changed = (Pair<String, String>) request.argument;
1992 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1993 changed.first, changed.second, onCompleted);
1994 break;
1995 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1996 ar = (AsyncResult) msg.obj;
1997 request = (MainThreadRequest) ar.userObj;
1998 if (ar.exception == null) {
1999 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002000 // If the operation is successful, update the PIN storage
2001 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2002 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002003 UiccController.getInstance().getPinStorage()
2004 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002005 } else {
2006 request.result = msg.arg1;
2007 }
2008 notifyRequester(request);
2009 break;
2010
Michele Berionne5e411512020-11-13 02:36:59 +00002011 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002012 request = (MainThreadRequest) msg.obj;
2013 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2014 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2015 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2016 enabled.first, enabled.second, onCompleted);
2017 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002018 }
zoey chene02881a2019-12-30 16:11:23 +08002019 case EVENT_SET_ICC_LOCK_ENABLED_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<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2026 int phoneId = getPhoneFromRequest(request).getPhoneId();
2027 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002028 UiccController.getInstance().getPinStorage()
2029 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002030 } else {
2031 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2032 }
zoey chene02881a2019-12-30 16:11:23 +08002033 } else {
2034 request.result = msg.arg1;
2035 }
Michele Berionne5e411512020-11-13 02:36:59 +00002036
2037
zoey chene02881a2019-12-30 16:11:23 +08002038 notifyRequester(request);
2039 break;
2040
Peter Wangdafb9ac2020-01-15 14:13:38 -08002041 case MSG_NOTIFY_USER_ACTIVITY:
2042 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002043 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002044 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2045 getDefaultPhone().getContext().sendBroadcastAsUser(
2046 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2047 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002048
2049 case CMD_SET_DATA_THROTTLING: {
2050 request = (MainThreadRequest) msg.obj;
2051 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2052 DataThrottlingRequest dataThrottlingRequest =
2053 (DataThrottlingRequest) request.argument;
2054 Phone phone = getPhoneFromRequest(request);
2055 if (phone != null) {
2056 phone.setDataThrottling(onCompleted,
2057 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2058 dataThrottlingRequest.getCompletionDurationMillis());
2059 } else {
2060 loge("setDataThrottling: No phone object");
2061 request.result =
2062 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2063 notifyRequester(request);
2064 }
2065
2066 break;
2067 }
2068 case EVENT_SET_DATA_THROTTLING_DONE:
2069 ar = (AsyncResult) msg.obj;
2070 request = (MainThreadRequest) ar.userObj;
2071
2072 if (ar.exception == null) {
2073 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2074 } else if (ar.exception instanceof CommandException) {
2075 loge("setDataThrottling: CommandException: " + ar.exception);
2076 CommandException.Error error =
2077 ((CommandException) (ar.exception)).getCommandError();
2078
2079 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2080 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002081 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002082 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2083 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002084 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2085 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002086 } else {
2087 request.result =
2088 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2089 }
2090 } else {
2091 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2092 }
2093 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2094 notifyRequester(request);
2095 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002096
2097 case CMD_SET_SIM_POWER: {
2098 request = (MainThreadRequest) msg.obj;
2099 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2100 request = (MainThreadRequest) msg.obj;
2101 int stateToSet =
2102 ((Pair<Integer, IIntegerConsumer>)
2103 request.argument).first;
2104 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2105 break;
2106 }
2107 case EVENT_SET_SIM_POWER_DONE: {
2108 ar = (AsyncResult) msg.obj;
2109 request = (MainThreadRequest) ar.userObj;
2110 IIntegerConsumer callback =
2111 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2112 if (ar.exception != null) {
2113 loge("setSimPower exception: " + ar.exception);
2114 int errorCode = TelephonyManager.CallForwardingInfoCallback
2115 .RESULT_ERROR_UNKNOWN;
2116 if (ar.exception instanceof CommandException) {
2117 CommandException.Error error =
2118 ((CommandException) (ar.exception)).getCommandError();
2119 if (error == CommandException.Error.SIM_ERR) {
2120 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2121 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2122 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2123 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2124 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2125 } else {
2126 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2127 }
2128 }
2129 try {
2130 callback.accept(errorCode);
2131 } catch (RemoteException e) {
2132 // Ignore if the remote process is no longer available to call back.
2133 Log.w(LOG_TAG, "setSimPower: callback not available.");
2134 }
2135 } else {
2136 try {
2137 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2138 } catch (RemoteException e) {
2139 // Ignore if the remote process is no longer available to call back.
2140 Log.w(LOG_TAG, "setSimPower: callback not available.");
2141 }
2142 }
2143 break;
2144 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002145 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2146 request = (MainThreadRequest) msg.obj;
2147
2148 final Phone phone = getPhoneFromRequest(request);
2149 if (phone == null || phone.getServiceStateTracker() == null) {
2150 request.result = new IllegalStateException("Phone or SST is null");
2151 notifyRequester(request);
2152 break;
2153 }
2154
2155 Pair<Integer, SignalStrengthUpdateRequest> pair =
2156 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2157 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2158 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002159 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002160 request.subId, pair.first /*callingUid*/,
2161 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002162 break;
2163 }
2164 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2165 ar = (AsyncResult) msg.obj;
2166 request = (MainThreadRequest) ar.userObj;
2167 // request.result will be the exception of ar if present, true otherwise.
2168 // Be cautious not to leave result null which will wait() forever
2169 request.result = ar.exception != null ? ar.exception : true;
2170 notifyRequester(request);
2171 break;
2172 }
2173 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2174 request = (MainThreadRequest) msg.obj;
2175
2176 Phone phone = getPhoneFromRequest(request);
2177 if (phone == null || phone.getServiceStateTracker() == null) {
2178 request.result = new IllegalStateException("Phone or SST is null");
2179 notifyRequester(request);
2180 break;
2181 }
2182
2183 Pair<Integer, SignalStrengthUpdateRequest> pair =
2184 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2185 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2186 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002187 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002188 request.subId, pair.first /*callingUid*/,
2189 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002190 break;
2191 }
2192 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2193 ar = (AsyncResult) msg.obj;
2194 request = (MainThreadRequest) ar.userObj;
2195 request.result = ar.exception != null ? ar.exception : true;
2196 notifyRequester(request);
2197 break;
2198 }
Jordan Liu109698e2020-11-24 14:50:34 -08002199
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002200 case CMD_GET_SLICING_CONFIG: {
2201 request = (MainThreadRequest) msg.obj;
2202 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2203 request.phone.getSlicingConfig(onCompleted);
2204 break;
2205 }
2206 case EVENT_GET_SLICING_CONFIG_DONE: {
2207 ar = (AsyncResult) msg.obj;
2208 request = (MainThreadRequest) ar.userObj;
2209 ResultReceiver result = (ResultReceiver) request.argument;
2210
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002211 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002212 Bundle bundle = new Bundle();
2213 int resultCode = 0;
2214 if (ar.exception != null) {
2215 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2216 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002217 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002218 } else if (ar.result == null) {
2219 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002220 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002221 } else {
2222 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002223 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2224 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002225 }
2226
2227 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002228 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002229 }
2230 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2231 result.send(resultCode, bundle);
2232 notifyRequester(request);
2233 break;
2234 }
2235
Sarah Chin71b3a852022-09-28 15:54:19 -07002236 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002237 request = (MainThreadRequest) msg.obj;
2238 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002239 PurchasePremiumCapabilityArgument arg =
2240 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002241 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2242 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002243 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002244 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002245
Sarah Chin71b3a852022-09-28 15:54:19 -07002246 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002247 ar = (AsyncResult) msg.obj;
2248 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002249 PurchasePremiumCapabilityArgument arg =
2250 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251 try {
2252 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002253 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002254 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002255 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002256 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002257 + TelephonyManager.convertPurchaseResultToString(result));
2258 } catch (RemoteException e) {
2259 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002260 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002261 + " failed: " + e;
2262 if (DBG) log(logStr);
2263 AnomalyReporter.reportAnomaly(
2264 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2265 }
2266 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002267 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002268
Michele Berionne5e411512020-11-13 02:36:59 +00002269 case CMD_PREPARE_UNATTENDED_REBOOT:
2270 request = (MainThreadRequest) msg.obj;
2271 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002272 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002273 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002274 notifyRequester(request);
2275 break;
2276
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 default:
2278 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2279 break;
2280 }
2281 }
Jake Hambye994d462014-02-03 13:10:13 -08002282
Pengquan Menga1bb6272018-09-06 09:59:22 -07002283 private void notifyRequester(MainThreadRequest request) {
2284 synchronized (request) {
2285 request.notifyAll();
2286 }
2287 }
2288
Jake Hambye994d462014-02-03 13:10:13 -08002289 private void handleNullReturnEvent(Message msg, String command) {
2290 AsyncResult ar = (AsyncResult) msg.obj;
2291 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2292 if (ar.exception == null) {
2293 request.result = true;
2294 } else {
2295 request.result = false;
2296 if (ar.exception instanceof CommandException) {
2297 loge(command + ": CommandException: " + ar.exception);
2298 } else {
2299 loge(command + ": Unknown exception");
2300 }
2301 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002302 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 }
2305
2306 /**
2307 * Posts the specified command to be executed on the main thread,
2308 * waits for the request to complete, and returns the result.
2309 * @see #sendRequestAsync
2310 */
2311 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002312 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2313 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002314 }
2315
2316 /**
2317 * Posts the specified command to be executed on the main thread,
2318 * waits for the request to complete, and returns the result.
2319 * @see #sendRequestAsync
2320 */
2321 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2322 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002323 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002324 }
2325
2326 /**
2327 * Posts the specified command to be executed on the main thread,
2328 * waits for the request to complete, and returns the result.
2329 * @see #sendRequestAsync
2330 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002331 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002332 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2333 }
2334
2335 /**
2336 * Posts the specified command to be executed on the main thread,
2337 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2338 * if not timeout or null otherwise.
2339 * @see #sendRequestAsync
2340 */
2341 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2342 long timeoutInMs) {
2343 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002344 }
2345
2346 /**
2347 * Posts the specified command to be executed on the main thread,
2348 * waits for the request to complete, and returns the result.
2349 * @see #sendRequestAsync
2350 */
Nathan Harold92bed182018-10-12 18:16:49 -07002351 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002352 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002353 }
2354
2355 /**
2356 * Posts the specified command to be executed on the main thread,
2357 * waits for the request to complete, and returns the result.
2358 * @see #sendRequestAsync
2359 */
2360 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002361 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2362 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002363 }
2364
2365 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002366 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2367 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2368 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002369 * @see #sendRequestAsync
2370 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002371 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2372 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2374 throw new RuntimeException("This method will deadlock if called from the main thread.");
2375 }
2376
Nathan Harold92bed182018-10-12 18:16:49 -07002377 MainThreadRequest request = null;
2378 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2379 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2380 } else if (phone != null) {
2381 request = new MainThreadRequest(argument, phone, workSource);
2382 } else {
2383 request = new MainThreadRequest(argument, subId, workSource);
2384 }
2385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 Message msg = mMainThreadHandler.obtainMessage(command, request);
2387 msg.sendToTarget();
2388
Rambo Wang0f050d82021-02-12 11:43:36 -08002389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002391 if (timeoutInMs >= 0) {
2392 // Wait for at least timeoutInMs before returning null request result
2393 long now = SystemClock.elapsedRealtime();
2394 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002395 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002396 try {
2397 request.wait(deadline - now);
2398 } catch (InterruptedException e) {
2399 // Do nothing, go back and check if request is completed or timeout
2400 } finally {
2401 now = SystemClock.elapsedRealtime();
2402 }
2403 }
2404 } else {
2405 // Wait for the request to complete
2406 while (request.result == null) {
2407 try {
2408 request.wait();
2409 } catch (InterruptedException e) {
2410 // Do nothing, go back and wait until the request is complete
2411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 }
2413 }
2414 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002415 if (request.result == null) {
2416 Log.wtf(LOG_TAG,
2417 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 return request.result;
2420 }
2421
2422 /**
2423 * Asynchronous ("fire and forget") version of sendRequest():
2424 * Posts the specified command to be executed on the main thread, and
2425 * returns immediately.
2426 * @see #sendRequest
2427 */
2428 private void sendRequestAsync(int command) {
2429 mMainThreadHandler.sendEmptyMessage(command);
2430 }
2431
2432 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002433 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002434 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002435 */
2436 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002437 sendRequestAsync(command, argument, null, null);
2438 }
2439
2440 /**
2441 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2442 * @see {@link #sendRequest(int,Object)}
2443 */
2444 private void sendRequestAsync(
2445 int command, Object argument, Phone phone, WorkSource workSource) {
2446 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002447 Message msg = mMainThreadHandler.obtainMessage(command, request);
2448 msg.sendToTarget();
2449 }
2450
2451 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 * Initialize the singleton PhoneInterfaceManager instance.
2453 * This is only done once, at startup, from PhoneApp.onCreate().
2454 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002455 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 synchronized (PhoneInterfaceManager.class) {
2457 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002458 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 } else {
2460 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2461 }
2462 return sInstance;
2463 }
2464 }
2465
2466 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002467 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002469 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002470 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002472 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002473 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002474 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2476 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002477 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002478 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002479 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002480 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002481 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002482 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002483 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2484 getDefaultPhone().getContext(), featureFlags);
Tyler Gunn64144d92022-03-17 14:16:41 -07002485 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 publish();
arunvoddud7401012022-12-15 16:08:12 +00002487 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002488
2489 // Create the SatelliteEntitlementController singleton, for using the get the
2490 // entitlementStatus for satellite service.
2491 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 }
2493
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002494 @VisibleForTesting
2495 public SharedPreferences getSharedPreferences() {
2496 return mTelephonySharedPreferences;
2497 }
2498
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002499 /**
2500 * Get the default phone for this device.
2501 */
2502 @VisibleForTesting
2503 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002504 Phone thePhone = getPhone(getDefaultSubscription());
2505 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2506 }
2507
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 private void publish() {
2509 if (DBG) log("publish: " + this);
2510
Peter Wangc035ce42020-01-08 21:00:22 -08002511 TelephonyFrameworkInitializer
2512 .getTelephonyServiceManager()
2513 .getTelephonyServiceRegisterer()
2514 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
Stuart Scott584921c2015-01-15 17:10:34 -08002517 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002518 if (request.phone != null) {
2519 return request.phone;
2520 } else {
2521 return getPhoneFromSubId(request.subId);
2522 }
2523 }
2524
2525 private Phone getPhoneFromSubId(int subId) {
2526 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2527 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002528 }
2529
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002530 /**
2531 * Get phone object associated with a subscription.
2532 * Return default phone if phone object associated with subscription is null
2533 * @param subId - subscriptionId
2534 * @return phone object associated with a subscription or default phone if null.
2535 */
Ling Mac28f0212023-03-24 16:07:15 -07002536 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002537 Phone phone = getPhoneFromSubId(subId);
2538 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002539 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002540 phone = getDefaultPhone();
2541 }
2542 return phone;
2543 }
2544
Rambo Wange53e07d2022-05-10 13:01:13 -07002545 @Nullable
2546 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002547 Phone phone = getPhoneFromRequest(request);
2548 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002549 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002550 }
2551
Ling Mac28f0212023-03-24 16:07:15 -07002552 /**
2553 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2554 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2555 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2556 * @return The Phone associated the sub Id
2557 */
2558 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002559 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561
Kai Shif70f46f2021-03-03 13:59:46 -08002562 private void sendEraseModemConfig(@NonNull Phone phone) {
2563 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2564 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2565 }
2566
2567 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2568 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2569 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002570 }
2571
Peter Wang44b186e2020-01-13 23:33:09 -08002572 private boolean isImsAvailableOnDevice() {
2573 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2574 if (pm == null) {
2575 // For some reason package manger is not available.. This will fail internally anyway,
2576 // so do not throw error and allow.
2577 return true;
2578 }
2579 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2580 }
2581
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002583 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2584 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2585
Wink Savilleadd7cc52014-09-08 14:23:09 -07002586 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
Wink Savilleb564aae2014-10-23 10:18:09 -07002589 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590 if (DBG) log("dial: " + number);
2591 // No permission check needed here: This is just a wrapper around the
2592 // ACTION_DIAL intent, which is available to any app since it puts up
2593 // the UI before it does anything.
2594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 String url = createTelUrl(number);
2598 if (url == null) {
2599 return;
2600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 // PENDING: should we just silently fail if phone is offhook or ringing?
2603 PhoneConstants.State state = mCM.getState(subId);
2604 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2605 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2606 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2607 mApp.startActivity(intent);
2608 }
2609 } finally {
2610 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 }
2612 }
2613
2614 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002615 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002616 }
2617
Wink Savilleb564aae2014-10-23 10:18:09 -07002618 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 if (DBG) log("call: " + number);
2620
2621 // This is just a wrapper around the ACTION_CALL intent, but we still
2622 // need to do a permission check since we're calling startActivity()
2623 // from the context of the phone app.
2624 enforceCallPermission();
2625
Jordan Liu1617b712019-07-10 15:06:26 -07002626 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 != AppOpsManager.MODE_ALLOWED) {
2628 return;
2629 }
2630
joonhunshin4ac60942023-11-15 15:23:39 +00002631 enforceTelephonyFeatureWithException(callingPackage,
2632 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 String url = createTelUrl(number);
2637 if (url == null) {
2638 return;
2639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 boolean isValid = false;
2642 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2643 if (slist != null) {
2644 for (SubscriptionInfo subInfoRecord : slist) {
2645 if (subInfoRecord.getSubscriptionId() == subId) {
2646 isValid = true;
2647 break;
2648 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002649 }
Wink Saville08874612014-08-31 19:19:58 -07002650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 if (!isValid) {
2652 return;
2653 }
Wink Saville08874612014-08-31 19:19:58 -07002654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2656 intent.putExtra(SUBSCRIPTION_KEY, subId);
2657 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2658 mApp.startActivity(intent);
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 }
2663
Wink Savilleb564aae2014-10-23 10:18:09 -07002664 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002665 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002666 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2667 }
2668
Wink Savilleb564aae2014-10-23 10:18:09 -07002669 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002670 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002671 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2672 }
2673
Wink Savilleb564aae2014-10-23 10:18:09 -07002674 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676
joonhunshin4ac60942023-11-15 15:23:39 +00002677 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2678 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2679 "supplyPinReportResultForSubscriber");
2680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 final long identity = Binder.clearCallingIdentity();
2682 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002683 Phone phone = getPhone(subId);
2684 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 checkSimPin.start();
2686 return checkSimPin.unlockSim(null, pin);
2687 } finally {
2688 Binder.restoreCallingIdentity(identity);
2689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 }
2691
Wink Savilleb564aae2014-10-23 10:18:09 -07002692 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694
joonhunshin4ac60942023-11-15 15:23:39 +00002695 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2696 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 final long identity = Binder.clearCallingIdentity();
2699 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002700 Phone phone = getPhone(subId);
2701 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702 checkSimPuk.start();
2703 return checkSimPuk.unlockSim(puk, pin);
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
2706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 }
2708
2709 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002710 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002711 * a synchronous one.
2712 */
2713 private static class UnlockSim extends Thread {
2714
2715 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002716 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717
2718 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002719 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2720 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721
2722 // For replies from SimCard interface
2723 private Handler mHandler;
2724
2725 // For async handler to identify request type
2726 private static final int SUPPLY_PIN_COMPLETE = 100;
2727
Michele Berionne5e411512020-11-13 02:36:59 +00002728 UnlockSim(int phoneId, IccCard simCard) {
2729 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 mSimCard = simCard;
2731 }
2732
2733 @Override
2734 public void run() {
2735 Looper.prepare();
2736 synchronized (UnlockSim.this) {
2737 mHandler = new Handler() {
2738 @Override
2739 public void handleMessage(Message msg) {
2740 AsyncResult ar = (AsyncResult) msg.obj;
2741 switch (msg.what) {
2742 case SUPPLY_PIN_COMPLETE:
2743 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2744 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002745 mRetryCount = msg.arg1;
2746 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002747 CommandException.Error error = null;
2748 if (ar.exception instanceof CommandException) {
2749 error = ((CommandException) (ar.exception))
2750 .getCommandError();
2751 }
2752 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002753 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002754 } else if (error == CommandException.Error.ABORTED) {
2755 /* When UiccCardApp dispose, handle message and return
2756 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002757 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002758 } else {
2759 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2760 }
2761 } else {
2762 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002764 mDone = true;
2765 UnlockSim.this.notifyAll();
2766 }
2767 break;
2768 }
2769 }
2770 };
2771 UnlockSim.this.notifyAll();
2772 }
2773 Looper.loop();
2774 }
2775
2776 /*
2777 * Use PIN or PUK to unlock SIM card
2778 *
2779 * If PUK is null, unlock SIM card with PIN
2780 *
2781 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302782 *
2783 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2784 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002785 */
Wink Saville9de0f752013-10-22 19:04:03 -07002786 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787
2788 while (mHandler == null) {
2789 try {
2790 wait();
2791 } catch (InterruptedException e) {
2792 Thread.currentThread().interrupt();
2793 }
2794 }
2795 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2796
2797 if (puk == null) {
2798 mSimCard.supplyPin(pin, callback);
2799 } else {
2800 mSimCard.supplyPuk(puk, pin, callback);
2801 }
2802
2803 while (!mDone) {
2804 try {
2805 Log.d(LOG_TAG, "wait for done");
2806 wait();
2807 } catch (InterruptedException e) {
2808 // Restore the interrupted status
2809 Thread.currentThread().interrupt();
2810 }
2811 }
2812 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002813 int[] resultArray = new int[2];
2814 resultArray[0] = mResult;
2815 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002816
2817 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002818 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002819 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302820 // This instance is no longer reused, so quit its thread's looper.
2821 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002822
Wink Saville9de0f752013-10-22 19:04:03 -07002823 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 }
2825 }
2826
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002827 /**
2828 * This method has been removed due to privacy and stability concerns.
2829 */
2830 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002832 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2833 return;
Wink Saville36469e72014-06-11 15:17:00 -07002834 }
2835
Nathan Harold1f889d82020-06-04 17:05:26 -07002836 @Override
2837 public void updateServiceLocationWithPackageName(String callingPackage) {
2838 mApp.getSystemService(AppOpsManager.class)
2839 .checkPackage(Binder.getCallingUid(), callingPackage);
2840
Nathan Haroldf096d982020-11-18 17:18:06 -08002841 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002842 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2843 // Callers targeting S have no business invoking this method.
2844 return;
2845 }
2846
2847 LocationAccessPolicy.LocationPermissionResult locationResult =
2848 LocationAccessPolicy.checkLocationPermission(mApp,
2849 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2850 .setCallingPackage(callingPackage)
2851 .setCallingFeatureId(null)
2852 .setCallingPid(Binder.getCallingPid())
2853 .setCallingUid(Binder.getCallingUid())
2854 .setMethod("updateServiceLocation")
2855 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2856 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2857 .build());
2858 // Apps that lack location permission have no business calling this method;
2859 // however, because no permission was declared in the public API, denials must
2860 // all be "soft".
2861 switch (locationResult) {
2862 case DENIED_HARD: /* fall through */
2863 case DENIED_SOFT:
2864 return;
2865 }
2866
2867 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 final long identity = Binder.clearCallingIdentity();
2869 try {
Ling Mac28f0212023-03-24 16:07:15 -07002870 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871 } finally {
2872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002874 }
2875
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002876 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002877 @Override
2878 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002879 return isRadioOnWithFeature(callingPackage, null);
2880 }
2881
2882
2883 @Override
2884 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2885 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2886 callingFeatureId);
2887 }
2888
2889 @Deprecated
2890 @Override
2891 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2892 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002893 }
2894
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002895 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002896 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2897 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002899 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002900 return false;
2901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902
joonhunshin4ac60942023-11-15 15:23:39 +00002903 enforceTelephonyFeatureWithException(callingPackage,
2904 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 return isRadioOnForSubscriber(subId);
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
2911 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002912 }
2913
2914 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002915 final long identity = Binder.clearCallingIdentity();
2916 try {
2917 final Phone phone = getPhone(subId);
2918 if (phone != null) {
2919 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2920 } else {
2921 return false;
2922 }
2923 } finally {
2924 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002925 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 }
2927
2928 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002929 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
Wink Saville36469e72014-06-11 15:17:00 -07002931
Wink Savilleb564aae2014-10-23 10:18:09 -07002932 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934
joonhunshin4ac60942023-11-15 15:23:39 +00002935 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2936 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 final Phone phone = getPhone(subId);
2941 if (phone != null) {
2942 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002946 }
Wink Saville36469e72014-06-11 15:17:00 -07002947 }
2948
2949 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002950 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002951 }
2952
Wink Savilleb564aae2014-10-23 10:18:09 -07002953 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002954 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955
2956 final long identity = Binder.clearCallingIdentity();
2957 try {
2958 final Phone phone = getPhone(subId);
2959 if (phone == null) {
2960 return false;
2961 }
2962 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2963 toggleRadioOnOffForSubscriber(subId);
2964 }
2965 return true;
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002969 }
Wink Saville36469e72014-06-11 15:17:00 -07002970
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002971 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002972 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002973
2974 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2975 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2976
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002977 /*
2978 * If any of the Radios are available, it will need to be
2979 * shutdown. So return true if any Radio is available.
2980 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2984 Phone phone = PhoneFactory.getPhone(i);
2985 if (phone != null && phone.isRadioAvailable()) return true;
2986 }
2987 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2988 return false;
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002991 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002992 }
2993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002995 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996 enforceModifyPermission();
2997
joonhunshin4ac60942023-11-15 15:23:39 +00002998 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2999 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3004 logv("Shutting down Phone " + i);
3005 shutdownRadioUsingPhoneId(i);
3006 }
3007 } finally {
3008 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003009 }
3010 }
3011
3012 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003013 Phone phone = PhoneFactory.getPhone(phoneId);
3014 if (phone != null && phone.isRadioAvailable()) {
3015 phone.shutdownRadio();
3016 }
3017 }
3018
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003019 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021
Ling Ma83dc5ea2023-01-12 15:06:04 -08003022 if (!turnOn) {
3023 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3024 }
3025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 final long identity = Binder.clearCallingIdentity();
3027 try {
3028 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3029 if (defaultPhone != null) {
3030 defaultPhone.setRadioPower(turnOn);
3031 return true;
3032 } else {
3033 loge("There's no default phone.");
3034 return false;
3035 }
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003038 }
Wink Saville36469e72014-06-11 15:17:00 -07003039 }
3040
Wink Savilleb564aae2014-10-23 10:18:09 -07003041 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043
Ling Ma83dc5ea2023-01-12 15:06:04 -08003044 if (!turnOn) {
3045 log("setRadioPowerForSubscriber off: subId=" + subId
3046 + ",callingPackage=" + getCurrentPackageName());
3047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 final Phone phone = getPhone(subId);
3051 if (phone != null) {
3052 phone.setRadioPower(turnOn);
3053 return true;
3054 } else {
3055 return false;
3056 }
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003060 }
3061
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003062 /**
3063 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3064 * no reason to power it off. When any of the voters want to power it off, it will be turned
3065 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3066 * powering it off, and these radio off votes will be cleared.
3067 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3068 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3069 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3070 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3071 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3072 * check its vote.
3073 *
3074 * @param subId The subscription ID.
3075 * @param reason The reason for powering off radio.
3076 * @return true on success and false on failure.
3077 */
3078 public boolean requestRadioPowerOffForReason(int subId,
3079 @TelephonyManager.RadioPowerReason int reason) {
3080 enforceModifyPermission();
3081
joonhunshin4ac60942023-11-15 15:23:39 +00003082 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3083 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3084
Ling Ma83dc5ea2023-01-12 15:06:04 -08003085 log("requestRadioPowerOffForReason: subId=" + subId
3086 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003087 final long identity = Binder.clearCallingIdentity();
3088 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003089 boolean result = false;
3090 for (Phone phone : PhoneFactory.getPhones()) {
3091 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003092 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003093 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003094 if (!result) {
3095 loge("requestRadioPowerOffForReason: no phone exists");
3096 }
3097 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
3101 }
3102
3103 /**
3104 * Remove the vote on powering off the radio for a reason, as requested by
3105 * {@link requestRadioPowerOffForReason}.
3106 *
3107 * @param subId The subscription ID.
3108 * @param reason The reason for powering off radio.
3109 * @return true on success and false on failure.
3110 */
3111 public boolean clearRadioPowerOffForReason(int subId,
3112 @TelephonyManager.RadioPowerReason int reason) {
3113 enforceModifyPermission();
3114
joonhunshin4ac60942023-11-15 15:23:39 +00003115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3116 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3117
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003118 final long identity = Binder.clearCallingIdentity();
3119 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003120 boolean result = false;
3121 for (Phone phone : PhoneFactory.getPhones()) {
3122 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003123 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003124 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003125 if (!result) {
3126 loge("clearRadioPowerOffForReason: no phone exists");
3127 }
3128 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
3132 }
3133
3134 /**
3135 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3136 *
3137 * @param subId The subscription ID.
3138 * @param callingPackage The package making the call.
3139 * @param callingFeatureId The feature in the package.
3140 * @return List of reasons for powering off radio.
3141 */
3142 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3143 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3144
joonhunshin4ac60942023-11-15 15:23:39 +00003145 enforceTelephonyFeatureWithException(callingPackage,
3146 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3147
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003148 final long identity = Binder.clearCallingIdentity();
3149 List result = new ArrayList();
3150 try {
3151 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3152 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3153 return result;
3154 }
3155
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003156 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003157 if (phone != null) {
3158 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003159 } else {
3160 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003161 }
3162 } finally {
3163 Binder.restoreCallingIdentity(identity);
3164 }
3165 return result;
3166 }
3167
Wink Saville36469e72014-06-11 15:17:00 -07003168 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003169 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003170 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003171 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172
joonhunshin4ac60942023-11-15 15:23:39 +00003173 enforceTelephonyFeatureWithException(callingPackage,
3174 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176 final long identity = Binder.clearCallingIdentity();
3177 try {
Jack Yu285100e2022-12-02 22:48:35 -08003178 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179 final Phone phone = getPhone(subId);
3180 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003181 phone.getDataSettingsManager().setDataEnabled(
3182 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003183 return true;
3184 } else {
3185 return false;
3186 }
3187 } finally {
3188 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 }
3191
Wink Saville36469e72014-06-11 15:17:00 -07003192 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003193 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003194 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196
joonhunshin4ac60942023-11-15 15:23:39 +00003197 enforceTelephonyFeatureWithException(callingPackage,
3198 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final long identity = Binder.clearCallingIdentity();
3201 try {
Jack Yu285100e2022-12-02 22:48:35 -08003202 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 final Phone phone = getPhone(subId);
3204 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003205 phone.getDataSettingsManager().setDataEnabled(
3206 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 return true;
3208 } else {
3209 return false;
3210 }
3211 } finally {
3212 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003213 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 }
3215
Sanket Padawe356d7632015-06-22 14:03:32 -07003216 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003217 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003218 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3219 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 final Phone phone = getPhone(subId);
3224 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003225 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 } else {
3227 return false;
3228 }
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 }
3233
3234 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003235 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003236 }
3237
pkanwarae03a6b2016-11-06 20:37:09 -08003238 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003239 enforceCallPermission();
3240
joonhunshin4ac60942023-11-15 15:23:39 +00003241 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3242 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3247 return;
3248 }
3249 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3250 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3251 } finally {
3252 Binder.restoreCallingIdentity(identity);
3253 }
pkanwar32d516d2016-10-14 19:37:38 -07003254 };
3255
Wink Savilleb564aae2014-10-23 10:18:09 -07003256 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003258
joonhunshin4ac60942023-11-15 15:23:39 +00003259 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3260 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3265 return false;
3266 }
3267 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3268 } finally {
3269 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003271 }
3272
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003273 /**
3274 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3275 * tag on getCallState Binder call.
3276 */
3277 @Deprecated
3278 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003279 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003280 if (CompatChanges.isChangeEnabled(
3281 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3282 Binder.getCallingUid())) {
3283 // Do not allow this API to be called on API version 31+, it should only be
3284 // called on old apps using this Binder call directly.
3285 throw new SecurityException("This method can only be used for applications "
3286 + "targeting API version 30 or less.");
3287 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288 final long identity = Binder.clearCallingIdentity();
3289 try {
Ling Mac28f0212023-03-24 16:07:15 -07003290 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3291 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003292 } finally {
3293 Binder.restoreCallingIdentity(identity);
3294 }
3295 }
3296
3297 @Override
3298 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3299 if (CompatChanges.isChangeEnabled(
3300 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3301 Binder.getCallingUid())) {
3302 // Check READ_PHONE_STATE for API version 31+
3303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3304 featureId, "getCallStateForSubscription")) {
3305 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3306 + "targeting API level 31+.");
3307 }
3308 }
joonhunshin4ac60942023-11-15 15:23:39 +00003309
3310 enforceTelephonyFeatureWithException(callingPackage,
3311 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3312
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3317 PhoneConstantConversions.convertCallState(phone.getState());
3318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003321 }
3322
Sanket Padawe356d7632015-06-22 14:03:32 -07003323 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003324 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003325 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003326 }
3327
3328 @Override
3329 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003330 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3331 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333 final long identity = Binder.clearCallingIdentity();
3334 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003335 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003337 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 } else {
3339 return PhoneConstantConversions.convertDataState(
3340 PhoneConstants.DataState.DISCONNECTED);
3341 }
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003345 }
3346
Sanket Padawe356d7632015-06-22 14:03:32 -07003347 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003348 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003349 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003350 }
3351
3352 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003353 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003354 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3355 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 final long identity = Binder.clearCallingIdentity();
3358 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003359 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003360 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003361 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362 } else {
3363 return TelephonyManager.DATA_ACTIVITY_NONE;
3364 }
3365 } finally {
3366 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003368 }
3369
3370 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003371 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003372 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003373 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003374
3375 LocationAccessPolicy.LocationPermissionResult locationResult =
3376 LocationAccessPolicy.checkLocationPermission(mApp,
3377 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3378 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003379 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003380 .setCallingPid(Binder.getCallingPid())
3381 .setCallingUid(Binder.getCallingUid())
3382 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003383 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003384 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3385 .build());
3386 switch (locationResult) {
3387 case DENIED_HARD:
3388 throw new SecurityException("Not allowed to access cell location");
3389 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003390 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3391 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003392 }
3393
joonhunshin4ac60942023-11-15 15:23:39 +00003394 enforceTelephonyFeatureWithException(callingPackage,
3395 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3396
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003397 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003398 final long identity = Binder.clearCallingIdentity();
3399 try {
3400 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003401 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003402 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 } finally {
3404 Binder.restoreCallingIdentity(identity);
3405 }
Svetoslav64fad262015-04-14 14:35:21 -07003406 }
3407
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003408 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003409 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003410 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3411 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3412
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003413 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3414 // registered cell info, so return a NULL country instead.
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003417 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3418 // Get default phone in this case.
3419 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3420 }
Jack Yu285100e2022-12-02 22:48:35 -08003421 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003422 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003423 if (phone == null) return "";
3424 ServiceStateTracker sst = phone.getServiceStateTracker();
3425 if (sst == null) return "";
3426 LocaleTracker lt = sst.getLocaleTracker();
3427 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003428 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003432 }
3433
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003434 /**
3435 * This method was removed due to potential issues caused by performing partial
3436 * updates of service state, and lack of a credible use case.
3437 *
3438 * This has the ability to break the telephony implementation by disabling notification of
3439 * changes in device connectivity. DO NOT USE THIS!
3440 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003441 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003442 public void enableLocationUpdates() {
3443 mApp.enforceCallingOrSelfPermission(
3444 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 }
3446
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003447 /**
3448 * This method was removed due to potential issues caused by performing partial
3449 * updates of service state, and lack of a credible use case.
3450 *
3451 * This has the ability to break the telephony implementation by disabling notification of
3452 * changes in device connectivity. DO NOT USE THIS!
3453 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003454 @Override
3455 public void disableLocationUpdates() {
3456 mApp.enforceCallingOrSelfPermission(
3457 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003458 }
3459
3460 @Override
3461 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003462 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3463 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003464 try {
3465 mApp.getSystemService(AppOpsManager.class)
3466 .checkPackage(Binder.getCallingUid(), callingPackage);
3467 } catch (SecurityException e) {
3468 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3469 throw e;
3470 }
3471
Nathan Haroldf096d982020-11-18 17:18:06 -08003472 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003473 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3474 throw new SecurityException(
3475 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3476 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003477
Jordan Liu1617b712019-07-10 15:06:26 -07003478 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003479 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3480 return null;
3481 }
Svetoslav64fad262015-04-14 14:35:21 -07003482
joonhunshin4ac60942023-11-15 15:23:39 +00003483 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3484 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3485
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003486 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003487
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003488 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003489 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003490
Nathan Haroldf180aac2018-06-01 18:43:55 -07003491 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3492 for (CellInfo ci : info) {
3493 if (ci instanceof CellInfoGsm) {
3494 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3495 } else if (ci instanceof CellInfoWcdma) {
3496 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003498 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003499 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003500 }
3501
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003502 private List<CellInfo> getCachedCellInfo() {
3503 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3504 for (Phone phone : PhoneFactory.getPhones()) {
3505 List<CellInfo> info = phone.getAllCellInfo();
3506 if (info != null) cellInfos.addAll(info);
3507 }
3508 return cellInfos;
3509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003510
3511 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003512 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003513 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003514 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003515
3516 LocationAccessPolicy.LocationPermissionResult locationResult =
3517 LocationAccessPolicy.checkLocationPermission(mApp,
3518 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3519 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003520 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003521 .setCallingPid(Binder.getCallingPid())
3522 .setCallingUid(Binder.getCallingUid())
3523 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003524 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003525 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3526 .build());
3527 switch (locationResult) {
3528 case DENIED_HARD:
3529 throw new SecurityException("Not allowed to access cell info");
3530 case DENIED_SOFT:
3531 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532 }
3533
Nathan Haroldf096d982020-11-18 17:18:06 -08003534 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003535 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3536 return getCachedCellInfo();
3537 }
3538
joonhunshin4ac60942023-11-15 15:23:39 +00003539 enforceTelephonyFeatureWithException(callingPackage,
3540 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3541
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003542 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003543 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3547 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003548 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003549 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003550 if (info != null) cellInfos.addAll(info);
3551 }
3552 return cellInfos;
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003555 }
3556 }
3557
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003558 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003559 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3560 String callingFeatureId) {
3561 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3562 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003563 }
3564
3565 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003566 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3567 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003568 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003569 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003570 }
3571
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003572 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3573 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003574 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003575 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003576
3577 LocationAccessPolicy.LocationPermissionResult locationResult =
3578 LocationAccessPolicy.checkLocationPermission(mApp,
3579 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3580 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003581 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003582 .setCallingPid(Binder.getCallingPid())
3583 .setCallingUid(Binder.getCallingUid())
3584 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003585 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3586 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003587 .build());
3588 switch (locationResult) {
3589 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003590 if (TelephonyPermissions
3591 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003592 // Safetynet logging for b/154934934
3593 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3594 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003595 throw new SecurityException("Not allowed to access cell info");
3596 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003597 if (TelephonyPermissions
3598 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003599 // Safetynet logging for b/154934934
3600 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3601 }
Nathan Harold5320c422019-05-09 10:26:08 -07003602 try {
3603 cb.onCellInfo(new ArrayList<CellInfo>());
3604 } catch (RemoteException re) {
3605 // Drop without consequences
3606 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003607 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003608 }
3609
joonhunshin4ac60942023-11-15 15:23:39 +00003610 enforceTelephonyFeatureWithException(callingPackage,
3611 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003612
3613 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003614 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3615
3616 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3617 }
3618
3619 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003620 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003621 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003622 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623
3624 final long identity = Binder.clearCallingIdentity();
3625 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003626 Phone phone = getPhone(subId);
3627 if (phone == null) {
3628 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3629 } else {
3630 phone.setCellInfoListRate(rateInMillis, workSource);
3631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632 } finally {
3633 Binder.restoreCallingIdentity(identity);
3634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003635 }
3636
Shishir Agrawala9f32182016-04-12 12:00:16 -07003637 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003638 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003639 Phone phone = PhoneFactory.getPhone(slotIndex);
3640 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003641 return null;
3642 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003643 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003644 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003645 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003646 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003647 return null;
3648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649
joonhunshin4ac60942023-11-15 15:23:39 +00003650 enforceTelephonyFeatureWithException(callingPackage,
3651 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 return phone.getImei();
3656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003659 }
3660
3661 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003662 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3663 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3664 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3665 callingFeatureId, "getPrimaryImei")) {
3666 throw new SecurityException("Caller does not have permission");
3667 }
joonhunshin4ac60942023-11-15 15:23:39 +00003668
3669 enforceTelephonyFeatureWithException(callingPackage,
3670 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3671
arunvoddud5c6ce02022-12-11 06:03:12 +00003672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 for (Phone phone : PhoneFactory.getPhones()) {
3675 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3676 return phone.getImei();
3677 }
3678 }
3679 throw new UnsupportedOperationException("Operation not supported");
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 }
3684
3685 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003686 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003687 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3688 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3689
David Kelly5e06a7f2018-03-12 14:10:59 +00003690 Phone phone = PhoneFactory.getPhone(slotIndex);
3691 String tac = null;
3692 if (phone != null) {
3693 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003694 try {
3695 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3696 } catch (IndexOutOfBoundsException e) {
3697 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3698 return null;
3699 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003700 }
3701 return tac;
3702 }
3703
3704 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003705 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003706 try {
3707 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3708 } catch (SecurityException se) {
3709 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3710 throw new SecurityException("Package " + callingPackage + " does not belong to "
3711 + Binder.getCallingUid());
3712 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003713 Phone phone = PhoneFactory.getPhone(slotIndex);
3714 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003715 return null;
3716 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003717
Jeff Davidson913390f2018-02-23 17:11:49 -08003718 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003719 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003720 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003721 return null;
3722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723
joonhunshin4ac60942023-11-15 15:23:39 +00003724 enforceTelephonyFeatureWithException(callingPackage,
3725 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 return phone.getMeid();
3730 } finally {
3731 Binder.restoreCallingIdentity(identity);
3732 }
Jack Yu2af8d712017-03-15 17:14:14 -07003733 }
3734
3735 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003736 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003737 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3738 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3739
David Kelly5e06a7f2018-03-12 14:10:59 +00003740 Phone phone = PhoneFactory.getPhone(slotIndex);
3741 String manufacturerCode = null;
3742 if (phone != null) {
3743 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003744 try {
3745 manufacturerCode =
3746 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3747 } catch (IndexOutOfBoundsException e) {
3748 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3749 return null;
3750 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003751 }
3752 return manufacturerCode;
3753 }
3754
3755 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003756 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3757 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003758 Phone phone = PhoneFactory.getPhone(slotIndex);
3759 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003760 return null;
3761 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003762 int subId = phone.getSubId();
3763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003764 mApp, subId, callingPackage, callingFeatureId,
3765 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003766 return null;
3767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768
joonhunshin4ac60942023-11-15 15:23:39 +00003769 enforceTelephonyFeatureWithException(callingPackage,
3770 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772 final long identity = Binder.clearCallingIdentity();
3773 try {
3774 return phone.getDeviceSvn();
3775 } finally {
3776 Binder.restoreCallingIdentity(identity);
3777 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003778 }
3779
fionaxu43304da2017-11-27 22:51:16 -08003780 @Override
3781 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003782 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3783 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 final Phone phone = getPhone(subId);
3788 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
3791 }
fionaxu43304da2017-11-27 22:51:16 -08003792 }
3793
3794 @Override
3795 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003796 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3797 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 final Phone phone = getPhone(subId);
3802 return phone == null ? null : phone.getCarrierName();
3803 } finally {
3804 Binder.restoreCallingIdentity(identity);
3805 }
fionaxu43304da2017-11-27 22:51:16 -08003806 }
3807
calvinpanffe225e2018-11-01 19:43:06 +08003808 @Override
chen xu0026ca62019-03-06 15:28:50 -08003809 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003810 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3811 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3812
chen xu25637222018-11-04 17:17:00 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 final Phone phone = getPhone(subId);
3816 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003817 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
3821 }
3822
3823 @Override
chen xu0026ca62019-03-06 15:28:50 -08003824 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003825 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3826 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3827 "getSubscriptionSpecificCarrierName");
3828
chen xu25637222018-11-04 17:17:00 -08003829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003832 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003833 } finally {
3834 Binder.restoreCallingIdentity(identity);
3835 }
3836 }
3837
chen xu651eec72018-11-11 19:03:44 -08003838 @Override
chen xu864e11c2018-12-06 22:10:03 -08003839 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3840 if (!isSubscriptionMccMnc) {
3841 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3842 }
chen xu651eec72018-11-11 19:03:44 -08003843 final Phone phone = PhoneFactory.getPhone(slotIndex);
3844 if (phone == null) {
3845 return TelephonyManager.UNKNOWN_CARRIER_ID;
3846 }
joonhunshin4ac60942023-11-15 15:23:39 +00003847
3848 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3849 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3850
chen xu651eec72018-11-11 19:03:44 -08003851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3854 } finally {
3855 Binder.restoreCallingIdentity(identity);
3856 }
3857 }
3858
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003859 //
3860 // Internal helper methods.
3861 //
3862
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003863 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003864 * Make sure the caller is the calling package itself
3865 *
3866 * @throws SecurityException if the caller is not the calling package
3867 */
3868 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3869 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003870 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3871 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003872 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003873 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003874 } catch (PackageManager.NameNotFoundException e) {
3875 // packageUid is -1
3876 }
3877 if (packageUid != callingUid) {
3878 throw new SecurityException(message + ": Package " + callingPackage
3879 + " does not belong to " + callingUid);
3880 }
3881 }
3882
3883 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003884 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3885 *
3886 * @throws SecurityException if the caller does not have the required permission
3887 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003888 @VisibleForTesting
3889 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003890 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3891 }
3892
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003893 /**
arunvoddud7401012022-12-15 16:08:12 +00003894 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003895 *
3896 * @throws SecurityException if the caller does not have the required permission
3897 */
3898 @VisibleForTesting
3899 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003900 enforceReadPermission(null);
3901 }
3902
3903 /**
3904 * Make sure the caller has the READ_PHONE_STATE permissions.
3905 *
3906 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3907 */
3908 @VisibleForTesting
3909 public void enforceReadPermission(String msg) {
3910 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003911 }
3912
Shuo Qian3b6ee772019-11-13 17:43:31 -08003913 private void enforceActiveEmergencySessionPermission() {
3914 mApp.enforceCallingOrSelfPermission(
3915 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3916 }
3917
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003918 /**
3919 * Make sure the caller has the CALL_PHONE permission.
3920 *
3921 * @throws SecurityException if the caller does not have the required permission
3922 */
3923 private void enforceCallPermission() {
3924 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3925 }
3926
paulhu5a773602019-08-23 19:17:33 +08003927 private void enforceSettingsPermission() {
3928 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003929 }
3930
Michele Berionne5e411512020-11-13 02:36:59 +00003931 private void enforceRebootPermission() {
3932 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3933 }
3934
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003935 /**
3936 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3937 * @param message - log message to print.
3938 * @throws SecurityException if the caller does not have the required permission
3939 */
3940 private void enforceSatelliteCommunicationPermission(String message) {
3941 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3942 }
3943
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003944 private String createTelUrl(String number) {
3945 if (TextUtils.isEmpty(number)) {
3946 return null;
3947 }
3948
Jake Hambye994d462014-02-03 13:10:13 -08003949 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003950 }
3951
Ihab Awadf9e92732013-12-05 18:02:52 -08003952 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003953 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003954 }
3955
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003956 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003957 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003958 }
3959
Ihab Awadf9e92732013-12-05 18:02:52 -08003960 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003961 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003962 }
3963
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003964 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003965 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003966 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003967 }
3968
Sanket Padawe356d7632015-06-22 14:03:32 -07003969 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003970 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003971 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3972 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 final Phone phone = PhoneFactory.getPhone(slotIndex);
3977 if (phone == null) {
3978 return PhoneConstants.PHONE_TYPE_NONE;
3979 } else {
3980 return phone.getPhoneType();
3981 }
3982 } finally {
3983 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003984 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003985 }
3986
3987 /**
3988 * Returns the CDMA ERI icon index to display
3989 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003990 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003991 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3992 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3993 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003994 }
3995
Sanket Padawe356d7632015-06-22 14:03:32 -07003996 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003997 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3998 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004000 mApp, subId, callingPackage, callingFeatureId,
4001 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004002 return -1;
4003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004
joonhunshin4ac60942023-11-15 15:23:39 +00004005 enforceTelephonyFeatureWithException(callingPackage,
4006 PackageManager.FEATURE_TELEPHONY_CDMA,
4007 "getCdmaEriIconIndexForSubscriber");
4008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 final Phone phone = getPhone(subId);
4012 if (phone != null) {
4013 return phone.getCdmaEriIconIndex();
4014 } else {
4015 return -1;
4016 }
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004020 }
4021
4022 /**
4023 * Returns the CDMA ERI icon mode,
4024 * 0 - ON
4025 * 1 - FLASHING
4026 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004027 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004028 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4029 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4030 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004031 }
4032
Sanket Padawe356d7632015-06-22 14:03:32 -07004033 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004034 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4035 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004037 mApp, subId, callingPackage, callingFeatureId,
4038 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004039 return -1;
4040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004041
4042 final long identity = Binder.clearCallingIdentity();
4043 try {
4044 final Phone phone = getPhone(subId);
4045 if (phone != null) {
4046 return phone.getCdmaEriIconMode();
4047 } else {
4048 return -1;
4049 }
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004053 }
4054
4055 /**
4056 * Returns the CDMA ERI text,
4057 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004059 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4060 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4061 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004062 }
4063
Sanket Padawe356d7632015-06-22 14:03:32 -07004064 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004065 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4066 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004068 mApp, subId, callingPackage, callingFeatureId,
4069 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004070 return null;
4071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004072
4073 final long identity = Binder.clearCallingIdentity();
4074 try {
4075 final Phone phone = getPhone(subId);
4076 if (phone != null) {
4077 return phone.getCdmaEriText();
4078 } else {
4079 return null;
4080 }
4081 } finally {
4082 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004084 }
4085
4086 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004087 * Returns the CDMA MDN.
4088 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004089 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004090 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4092 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093
joonhunshin4ac60942023-11-15 15:23:39 +00004094 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4095 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004100 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 return phone.getLine1Number();
4102 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004103 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 return null;
4105 }
4106 } finally {
4107 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004108 }
4109 }
4110
4111 /**
4112 * Returns the CDMA MIN.
4113 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004114 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004115 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4117 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004118
joonhunshin4ac60942023-11-15 15:23:39 +00004119 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4120 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4121
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004122 final long identity = Binder.clearCallingIdentity();
4123 try {
4124 final Phone phone = getPhone(subId);
4125 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4126 return phone.getCdmaMin();
4127 } else {
4128 return null;
4129 }
4130 } finally {
4131 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004132 }
4133 }
4134
Hall Liud892bec2018-11-30 14:51:45 -08004135 @Override
4136 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4137 INumberVerificationCallback callback, String callingPackage) {
4138 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4139 != PERMISSION_GRANTED) {
4140 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4141 }
4142 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4143
4144 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4145 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004146 throw new SecurityException("Calling package must be configured in the device config: "
4147 + "calling package: " + callingPackage
4148 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004149 }
4150
joonhunshin4ac60942023-11-15 15:23:39 +00004151 enforceTelephonyFeatureWithException(callingPackage,
4152 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4153
Hall Liud892bec2018-11-30 14:51:45 -08004154 if (range == null) {
4155 throw new NullPointerException("Range must be non-null");
4156 }
4157
4158 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004159 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004160
4161 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4162 }
4163
Junda Liuca05d5d2014-08-14 22:36:34 -07004164 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004165 * Returns true if CDMA provisioning needs to run.
4166 */
4167 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004168 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4169 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004171 final long identity = Binder.clearCallingIdentity();
4172 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004173 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004174 } finally {
4175 Binder.restoreCallingIdentity(identity);
4176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004177 }
4178
4179 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004180 * Sets the voice mail number of a given subId.
4181 */
4182 @Override
4183 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004184 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4185 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186
joonhunshin4ac60942023-11-15 15:23:39 +00004187 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4188 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190 final long identity = Binder.clearCallingIdentity();
4191 try {
Nathan Harolddc3bcec2024-05-16 14:06:40 -07004192 Boolean success = (Boolean) sendRequest(
4193 CMD_SET_VOICEMAIL_NUMBER,
4194 new Pair<String, String>(alphaTag, number),
4195 new Integer(subId),
4196 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
4197 if (success == null) return false; // most likely due to a timeout
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198 return success;
4199 } finally {
4200 Binder.restoreCallingIdentity(identity);
4201 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004202 }
4203
Ta-wei Yen87c49842016-05-13 21:19:52 -07004204 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004205 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4206 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004207 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4208 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004209 if (!TextUtils.equals(callingPackage, systemDialer)) {
4210 throw new SecurityException("caller must be system dialer");
4211 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212
joonhunshin4ac60942023-11-15 15:23:39 +00004213 enforceTelephonyFeatureWithException(callingPackage,
4214 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004216 final long identity = Binder.clearCallingIdentity();
4217 try {
4218 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4219 if (phoneAccountHandle == null) {
4220 return null;
4221 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004222 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004223 } finally {
4224 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004225 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004226 }
4227
4228 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004229 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4230 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004231 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004233 mApp, subId, callingPackage, callingFeatureId,
4234 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004235 return null;
4236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004237
joonhunshin4ac60942023-11-15 15:23:39 +00004238 enforceTelephonyFeatureWithException(callingPackage,
4239 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4240
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004241 final long identity = Binder.clearCallingIdentity();
4242 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004243 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004247 }
4248
4249 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004250 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4251 VisualVoicemailSmsFilterSettings settings) {
4252 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253
joonhunshin4ac60942023-11-15 15:23:39 +00004254 enforceTelephonyFeatureWithException(callingPackage,
4255 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 final long identity = Binder.clearCallingIdentity();
4258 try {
4259 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004260 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 } finally {
4262 Binder.restoreCallingIdentity(identity);
4263 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004264 }
4265
4266 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004267 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4268 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004269
joonhunshin4ac60942023-11-15 15:23:39 +00004270 enforceTelephonyFeatureWithException(callingPackage,
4271 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 final long identity = Binder.clearCallingIdentity();
4274 try {
4275 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004276 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277 } finally {
4278 Binder.restoreCallingIdentity(identity);
4279 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004280 }
4281
4282 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004283 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4284 String callingPackage, int subId) {
4285 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286
4287 final long identity = Binder.clearCallingIdentity();
4288 try {
4289 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004290 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004294 }
4295
4296 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004297 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299
4300 final long identity = Binder.clearCallingIdentity();
4301 try {
4302 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004303 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004307 }
4308
4309 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004310 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4311 String callingAttributionTag, int subId, String number, int port, String text,
4312 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004313 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004314 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004315 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004316
4317 enforceTelephonyFeatureWithException(callingPackage,
4318 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4319
Amit Mahajandccb3f12019-05-13 13:48:32 -07004320 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004321 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4322 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004323 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004324
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004325 /**
fionaxu0152e512016-11-14 13:36:14 -08004326 * Sets the voice activation state of a given subId.
4327 */
4328 @Override
4329 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4331 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332
joonhunshin4ac60942023-11-15 15:23:39 +00004333 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4334 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004336 final long identity = Binder.clearCallingIdentity();
4337 try {
4338 final Phone phone = getPhone(subId);
4339 if (phone != null) {
4340 phone.setVoiceActivationState(activationState);
4341 } else {
4342 loge("setVoiceActivationState fails with invalid subId: " + subId);
4343 }
4344 } finally {
4345 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004346 }
4347 }
4348
4349 /**
4350 * Sets the data activation state of a given subId.
4351 */
4352 @Override
4353 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4355 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356
joonhunshin4ac60942023-11-15 15:23:39 +00004357 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4358 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004360 final long identity = Binder.clearCallingIdentity();
4361 try {
4362 final Phone phone = getPhone(subId);
4363 if (phone != null) {
4364 phone.setDataActivationState(activationState);
4365 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004366 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367 }
4368 } finally {
4369 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004370 }
4371 }
4372
4373 /**
4374 * Returns the voice activation state of a given subId.
4375 */
4376 @Override
4377 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004379
joonhunshin4ac60942023-11-15 15:23:39 +00004380 enforceTelephonyFeatureWithException(callingPackage,
4381 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4382
fionaxu0152e512016-11-14 13:36:14 -08004383 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384 final long identity = Binder.clearCallingIdentity();
4385 try {
4386 if (phone != null) {
4387 return phone.getVoiceActivationState();
4388 } else {
4389 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4390 }
4391 } finally {
4392 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004393 }
4394 }
4395
4396 /**
4397 * Returns the data activation state of a given subId.
4398 */
4399 @Override
4400 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004401 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402
joonhunshin4ac60942023-11-15 15:23:39 +00004403 enforceTelephonyFeatureWithException(callingPackage,
4404 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4405
fionaxu0152e512016-11-14 13:36:14 -08004406 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 final long identity = Binder.clearCallingIdentity();
4408 try {
4409 if (phone != null) {
4410 return phone.getDataActivationState();
4411 } else {
4412 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4413 }
4414 } finally {
4415 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004416 }
4417 }
4418
4419 /**
Wink Saville36469e72014-06-11 15:17:00 -07004420 * Returns the unread count of voicemails for a subId
4421 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004422 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004423 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4424 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004425 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004426 mApp, subId, callingPackage, callingFeatureId,
4427 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004428 return 0;
4429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004430 final long identity = Binder.clearCallingIdentity();
4431 try {
4432 final Phone phone = getPhone(subId);
4433 if (phone != null) {
4434 return phone.getVoiceMessageCount();
4435 } else {
4436 return 0;
4437 }
4438 } finally {
4439 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004441 }
4442
4443 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004444 * returns true, if the device is in a state where both voice and data
4445 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004446 */
4447 @Override
4448 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004449 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4450 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452 final long identity = Binder.clearCallingIdentity();
4453 try {
Ling Mac28f0212023-03-24 16:07:15 -07004454 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004458 }
4459
4460 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004461 * Send the dialer code if called from the current default dialer or the caller has
4462 * carrier privilege.
4463 * @param inputCode The dialer code to send
4464 */
4465 @Override
4466 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004467 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004469 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4470 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004471 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004472 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004473 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475
joonhunshin4ac60942023-11-15 15:23:39 +00004476 enforceTelephonyFeatureWithException(callingPackage,
4477 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479 final long identity = Binder.clearCallingIdentity();
4480 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004481 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
fionaxu235cc5e2017-03-06 22:25:57 -08004485 }
4486
Pengquan Menga1bb6272018-09-06 09:59:22 -07004487 @Override
4488 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004489 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004490 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4491 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004492
4493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4494 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4495
shilufc958392020-01-20 11:36:01 -08004496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 if (!isActiveSubscription(subId)) {
4499 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4500 }
4501 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4502 } finally {
4503 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004504 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004505 }
4506
Brad Ebinger35c841c2018-10-01 10:40:55 -07004507 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004508 public boolean isInEmergencySmsMode() {
4509 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004510
4511 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4512 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4513
Brad Ebingerb2b65522019-03-15 13:48:47 -07004514 final long identity = Binder.clearCallingIdentity();
4515 try {
4516 for (Phone phone : PhoneFactory.getPhones()) {
4517 if (phone.isInEmergencySmsMode()) {
4518 return true;
4519 }
4520 }
4521 } finally {
4522 Binder.restoreCallingIdentity(identity);
4523 }
4524 return false;
4525 }
4526
shilu366312e2019-12-17 09:28:10 -08004527 /**
4528 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4529 * @param subId The subscription to use to check the configuration.
4530 * @param c The callback that will be used to send the result.
4531 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004532 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004533 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4534 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004535 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004536 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004537
4538 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4539 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4540 "IMS not available on device.");
4541 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004542 final long token = Binder.clearCallingIdentity();
4543 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004544 int slotId = getSlotIndexOrException(subId);
4545 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004546
4547 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4548 if (controller != null) {
4549 ImsManager imsManager = controller.getImsManager(subId);
4550 if (imsManager != null) {
4551 imsManager.addRegistrationCallbackForSubscription(c, subId);
4552 } else {
4553 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4554 }
4555 } else {
4556 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4557 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004558 } catch (ImsException e) {
4559 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004560 } finally {
4561 Binder.restoreCallingIdentity(token);
4562 }
4563 }
4564
shilu366312e2019-12-17 09:28:10 -08004565 /**
4566 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4567 * @param subId The subscription to use to check the configuration.
4568 * @param c The callback that will be used to send the result.
4569 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004570 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004571 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004572 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004573 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004574 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4575 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4576 }
Meng Wangafbc5852019-09-19 17:37:13 -07004577 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004578
Meng Wangafbc5852019-09-19 17:37:13 -07004579 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004580 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4581 if (controller != null) {
4582 ImsManager imsManager = controller.getImsManager(subId);
4583 if (imsManager != null) {
4584 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4585 } else {
4586 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4587 + "is inactive, ignoring unregister.");
4588 // If the ImsManager is not valid, just return, since the callback
4589 // will already have been removed internally.
4590 }
4591 }
Meng Wangafbc5852019-09-19 17:37:13 -07004592 } finally {
4593 Binder.restoreCallingIdentity(token);
4594 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004595 }
4596
Brad Ebingera34a6c22019-10-22 17:36:18 -07004597 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004598 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4599 * @param subId The subscription to use to check the configuration.
4600 * @param c The callback that will be used to send the result.
4601 */
4602 @Override
4603 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4604 throws RemoteException {
4605 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4606 mApp, subId, "registerImsEmergencyRegistrationCallback");
4607
4608 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4609 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4610 "IMS not available on device.");
4611 }
4612 final long token = Binder.clearCallingIdentity();
4613 try {
4614 int slotId = getSlotIndexOrException(subId);
4615 verifyImsMmTelConfiguredOrThrow(slotId);
4616
4617 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4618 if (controller != null) {
4619 ImsManager imsManager = controller.getImsManager(subId);
4620 if (imsManager != null) {
4621 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4622 } else {
4623 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4624 }
4625 } else {
4626 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4627 }
4628 } catch (ImsException e) {
4629 throw new ServiceSpecificException(e.getCode());
4630 } finally {
4631 Binder.restoreCallingIdentity(token);
4632 }
4633 }
4634
4635 /**
4636 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4637 * @param subId The subscription to use to check the configuration.
4638 * @param c The callback that will be used to send the result.
4639 */
4640 @Override
4641 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4642 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4643 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4644 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4645 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4646 }
4647 final long token = Binder.clearCallingIdentity();
4648
4649 try {
4650 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4651 if (controller != null) {
4652 ImsManager imsManager = controller.getImsManager(subId);
4653 if (imsManager != null) {
4654 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4655 } else {
4656 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4657 + "is inactive, ignoring unregister.");
4658 // If the ImsManager is not valid, just return, since the callback
4659 // will already have been removed internally.
4660 }
4661 }
4662 } finally {
4663 Binder.restoreCallingIdentity(token);
4664 }
4665 }
4666
4667 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004668 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4669 */
4670 @Override
4671 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4672 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4673 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4674 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4675 "IMS not available on device.");
4676 }
4677 final long token = Binder.clearCallingIdentity();
4678 try {
4679 Phone phone = getPhone(subId);
4680 if (phone == null) {
4681 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4682 + subId + "'");
4683 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4684 }
4685 phone.getImsRegistrationState(regState -> {
4686 try {
4687 consumer.accept((regState == null)
4688 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4689 } catch (RemoteException e) {
4690 // Ignore if the remote process is no longer available to call back.
4691 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4692 }
4693 });
4694 } finally {
4695 Binder.restoreCallingIdentity(token);
4696 }
4697 }
4698
4699 /**
4700 * Get the transport type for the IMS service registration state.
4701 */
4702 @Override
4703 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004704 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004705 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004706 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4707 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4708 "IMS not available on device.");
4709 }
4710 final long token = Binder.clearCallingIdentity();
4711 try {
4712 Phone phone = getPhone(subId);
4713 if (phone == null) {
4714 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4715 + subId + "'");
4716 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4717 }
4718 phone.getImsRegistrationTech(regTech -> {
4719 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4720 int regTechConverted = (regTech == null)
4721 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4722 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4723 regTechConverted);
4724 try {
4725 consumer.accept(regTechConverted);
4726 } catch (RemoteException e) {
4727 // Ignore if the remote process is no longer available to call back.
4728 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4729 }
4730 });
4731 } finally {
4732 Binder.restoreCallingIdentity(token);
4733 }
4734 }
4735
shilu366312e2019-12-17 09:28:10 -08004736 /**
4737 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4738 * @param subId The subscription to use to check the configuration.
4739 * @param c The callback that will be used to send the result.
4740 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004741 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004742 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4743 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004744 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004745 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004746 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4747 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4748 "IMS not available on device.");
4749 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004750 final long token = Binder.clearCallingIdentity();
4751 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004752 int slotId = getSlotIndexOrException(subId);
4753 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004754
4755 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4756 if (controller != null) {
4757 ImsManager imsManager = controller.getImsManager(subId);
4758 if (imsManager != null) {
4759 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4760 } else {
4761 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4762 }
4763 } else {
4764 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4765 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004766 } catch (ImsException e) {
4767 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004768 } finally {
4769 Binder.restoreCallingIdentity(token);
4770 }
4771 }
4772
shilu366312e2019-12-17 09:28:10 -08004773 /**
4774 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4775 * @param subId The subscription to use to check the configuration.
4776 * @param c The callback that will be used to send the result.
4777 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004778 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004779 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004780 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004781 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004782 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4783 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4784 }
Meng Wangafbc5852019-09-19 17:37:13 -07004785
4786 final long token = Binder.clearCallingIdentity();
4787 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004788 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4789 if (controller != null) {
4790 ImsManager imsManager = controller.getImsManager(subId);
4791 if (imsManager != null) {
4792 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4793 } else {
4794 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4795 + " is inactive, ignoring unregister.");
4796 // If the ImsManager is not valid, just return, since the callback
4797 // will already have been removed internally.
4798 }
4799 }
Meng Wangafbc5852019-09-19 17:37:13 -07004800 } finally {
4801 Binder.restoreCallingIdentity(token);
4802 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004803 }
4804
4805 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004806 public boolean isCapable(int subId, int capability, int regTech) {
4807 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004808
4809 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4810 FEATURE_TELEPHONY_IMS, "isCapable");
4811
Brad Ebinger35c841c2018-10-01 10:40:55 -07004812 final long token = Binder.clearCallingIdentity();
4813 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004814 int slotId = getSlotIndexOrException(subId);
4815 verifyImsMmTelConfiguredOrThrow(slotId);
4816 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4817 } catch (com.android.ims.ImsException e) {
4818 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4819 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004820 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004821 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4822 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004823 } finally {
4824 Binder.restoreCallingIdentity(token);
4825 }
4826 }
4827
4828 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004829 public boolean isAvailable(int subId, int capability, int regTech) {
4830 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004831
4832 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4833 FEATURE_TELEPHONY_IMS, "isAvailable");
4834
Brad Ebinger35c841c2018-10-01 10:40:55 -07004835 final long token = Binder.clearCallingIdentity();
4836 try {
4837 Phone phone = getPhone(subId);
4838 if (phone == null) return false;
4839 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004840 } catch (com.android.ims.ImsException e) {
4841 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4842 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004843 } finally {
4844 Binder.restoreCallingIdentity(token);
4845 }
4846 }
4847
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004848 /**
4849 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4850 * subscription.
4851 * @param subId The subscription to use to check the configuration.
4852 * @param callback The callback that will be used to send the result.
4853 * @param capability The MmTelFeature capability that will be used to send the result.
4854 * @param transportType The transport type of the MmTelFeature capability.
4855 */
4856 @Override
4857 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4858 int transportType) {
4859 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004860 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4861 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4862 "IMS not available on device.");
4863 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004864 final long token = Binder.clearCallingIdentity();
4865 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004866 int slotId = getSlotIndex(subId);
4867 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4868 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4869 + subId + "'");
4870 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4871 }
4872 verifyImsMmTelConfiguredOrThrow(slotId);
4873 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4874 transportType, aBoolean -> {
4875 try {
4876 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4877 } catch (RemoteException e) {
4878 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4879 + "running. Ignore");
4880 }
4881 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004882 } catch (ImsException e) {
4883 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004884 } finally {
4885 Binder.restoreCallingIdentity(token);
4886 }
4887 }
4888
shilu366312e2019-12-17 09:28:10 -08004889 /**
4890 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4891 * @param subId The subscription to use to check the configuration.
4892 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004893 @Override
4894 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004895 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004896 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004897
joonhunshin4ac60942023-11-15 15:23:39 +00004898 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4899 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4900
Brad Ebinger35c841c2018-10-01 10:40:55 -07004901 final long token = Binder.clearCallingIdentity();
4902 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004903 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004904 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004905 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004906 } catch (ImsException e) {
4907 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004908 } finally {
4909 Binder.restoreCallingIdentity(token);
4910 }
4911 }
4912
4913 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004914 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004916 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004917
4918 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4919 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4920
Brad Ebinger35c841c2018-10-01 10:40:55 -07004921 final long identity = Binder.clearCallingIdentity();
4922 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004923 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004924 // This setting doesn't require an active ImsService connection, so do not verify. The
4925 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004926 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004927 } catch (ImsException e) {
4928 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004929 } finally {
4930 Binder.restoreCallingIdentity(identity);
4931 }
4932 }
4933
shilu366312e2019-12-17 09:28:10 -08004934 /**
4935 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4936 * @param subId The subscription to use to check the configuration.
4937 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004938 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004939 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004940 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004941 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004942
4943 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4944 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4945
Brad Ebinger35c841c2018-10-01 10:40:55 -07004946 final long identity = Binder.clearCallingIdentity();
4947 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004948 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004949 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004950 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004951 } catch (ImsException e) {
4952 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004953 } finally {
4954 Binder.restoreCallingIdentity(identity);
4955 }
4956 }
4957
4958 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004959 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004961 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004962
4963 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4964 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4965
Brad Ebinger35c841c2018-10-01 10:40:55 -07004966 final long identity = Binder.clearCallingIdentity();
4967 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004968 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004969 // This setting doesn't require an active ImsService connection, so do not verify. The
4970 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004971 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004972 } catch (ImsException e) {
4973 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004974 } finally {
4975 Binder.restoreCallingIdentity(identity);
4976 }
4977 }
4978
shilu366312e2019-12-17 09:28:10 -08004979 /**
4980 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4981 * @param subId The subscription to use to check the configuration.
4982 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004983 @Override
4984 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004985 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004986 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004987
4988 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4989 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4990
Brad Ebinger35c841c2018-10-01 10:40:55 -07004991 final long identity = Binder.clearCallingIdentity();
4992 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004993 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004994 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004995 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004996 } catch (ImsException e) {
4997 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004998 } finally {
4999 Binder.restoreCallingIdentity(identity);
5000 }
5001 }
5002
5003 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005004 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005006 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005007
5008 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5009 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5010
Brad Ebinger35c841c2018-10-01 10:40:55 -07005011 final long identity = Binder.clearCallingIdentity();
5012 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005013 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005014 // This setting doesn't require an active ImsService connection, so do not verify. The
5015 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005016 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005017 } catch (ImsException e) {
5018 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005019 } finally {
5020 Binder.restoreCallingIdentity(identity);
5021 }
5022 }
5023
shilu366312e2019-12-17 09:28:10 -08005024 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005025 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5026 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5027 * @param subId The subscription to use to check the configuration.
5028 */
5029 @Override
5030 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005031 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005032 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005033
5034 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5035 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5036
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005037 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.
Brad Ebinger919631e2021-06-02 17:46:35 -07005041 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005042 } catch (ImsException e) {
5043 throw new ServiceSpecificException(e.getCode());
5044 } finally {
5045 Binder.restoreCallingIdentity(identity);
5046 }
5047 }
5048
5049 /**
5050 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5051 * Requires MODIFY_PHONE_STATE permission.
5052 * @param subId The subscription to use to check the configuration.
5053 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5054 * false otherwise
5055 */
5056 @Override
5057 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5059 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005060
5061 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5062 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5063
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005064 final long identity = Binder.clearCallingIdentity();
5065 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005066 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005067 // This setting doesn't require an active ImsService connection, so do not verify. The
5068 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005069 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005070 } catch (ImsException e) {
5071 throw new ServiceSpecificException(e.getCode());
5072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
5075 }
5076
5077 /**
shilu366312e2019-12-17 09:28:10 -08005078 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5079 * @param subId The subscription to use to check the configuration.
5080 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005081 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005082
Brad Ebinger35c841c2018-10-01 10:40:55 -07005083 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005084 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005085 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005086
5087 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5088 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5089
Brad Ebinger35c841c2018-10-01 10:40:55 -07005090 final long identity = Binder.clearCallingIdentity();
5091 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005092 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005093 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005094 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005095 } catch (ImsException e) {
5096 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005097 } finally {
5098 Binder.restoreCallingIdentity(identity);
5099 }
5100 }
5101
5102 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005103 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005105 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005106
5107 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5108 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5109
Brad Ebinger35c841c2018-10-01 10:40:55 -07005110 final long identity = Binder.clearCallingIdentity();
5111 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005112 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005113 // This setting doesn't require an active ImsService connection, so do not verify. The
5114 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005115 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005116 } catch (ImsException e) {
5117 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005118 } finally {
5119 Binder.restoreCallingIdentity(identity);
5120 }
5121 }
5122
5123 @Override
5124 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5126 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005127
5128 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5129 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5130
Brad Ebinger35c841c2018-10-01 10:40:55 -07005131 final long identity = Binder.clearCallingIdentity();
5132 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005133 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005134 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005135 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005136 } catch (ImsException e) {
5137 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005138 } finally {
5139 Binder.restoreCallingIdentity(identity);
5140 }
5141 }
5142
shilu366312e2019-12-17 09:28:10 -08005143 /**
5144 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5145 * @param subId The subscription to use to check the configuration.
5146 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005147 @Override
5148 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005149 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005150 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005151
5152 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5153 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5154
Brad Ebinger35c841c2018-10-01 10:40:55 -07005155 final long identity = Binder.clearCallingIdentity();
5156 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005157 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005158 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005159 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005160 } catch (ImsException e) {
5161 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005162 } finally {
5163 Binder.restoreCallingIdentity(identity);
5164 }
5165 }
5166
5167 @Override
5168 public void setVoWiFiModeSetting(int subId, int mode) {
5169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5170 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005171
5172 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5173 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5174
Brad Ebinger35c841c2018-10-01 10:40:55 -07005175 final long identity = Binder.clearCallingIdentity();
5176 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005177 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005178 // This setting doesn't require an active ImsService connection, so do not verify. The
5179 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005180 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005181 } catch (ImsException e) {
5182 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005183 } finally {
5184 Binder.restoreCallingIdentity(identity);
5185 }
5186 }
5187
5188 @Override
5189 public int getVoWiFiRoamingModeSetting(int subId) {
5190 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005191
5192 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5193 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5194
Brad Ebinger35c841c2018-10-01 10:40:55 -07005195 final long identity = Binder.clearCallingIdentity();
5196 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005197 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005198 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005199 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005200 } catch (ImsException e) {
5201 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005202 } finally {
5203 Binder.restoreCallingIdentity(identity);
5204 }
5205 }
5206
5207 @Override
5208 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5210 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005211
5212 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5213 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5214
Brad Ebinger35c841c2018-10-01 10:40:55 -07005215 final long identity = Binder.clearCallingIdentity();
5216 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005217 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005218 // This setting doesn't require an active ImsService connection, so do not verify. The
5219 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005220 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005221 } catch (ImsException e) {
5222 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005223 } finally {
5224 Binder.restoreCallingIdentity(identity);
5225 }
5226 }
5227
5228 @Override
5229 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5231 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005232
5233 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5234 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5235
Brad Ebinger35c841c2018-10-01 10:40:55 -07005236 final long identity = Binder.clearCallingIdentity();
5237 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005238 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005239 // This setting doesn't require an active ImsService connection, so do not verify. The
5240 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005241 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005242 } catch (ImsException e) {
5243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
5247 }
5248
shilu366312e2019-12-17 09:28:10 -08005249 /**
5250 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5251 * @param subId The subscription to use to check the configuration.
5252 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005253 @Override
5254 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005255 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005256 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005257
5258 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5259 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5260
Brad Ebinger35c841c2018-10-01 10:40:55 -07005261 final long identity = Binder.clearCallingIdentity();
5262 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005263 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005264 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005265 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005266 } catch (ImsException e) {
5267 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005268 } finally {
5269 Binder.restoreCallingIdentity(identity);
5270 }
5271 }
5272
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005273 @Override
5274 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5275 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005276
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005277 final long identity = Binder.clearCallingIdentity();
5278 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005279 if (!isImsAvailableOnDevice()) {
5280 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5281 "IMS not available on device.");
5282 }
5283 int slotId = getSlotIndexOrException(subId);
5284 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005285
5286 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5287 if (controller != null) {
5288 ImsManager imsManager = controller.getImsManager(subId);
5289 if (imsManager != null) {
5290 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5291 } else {
5292 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5293 }
5294 } else {
5295 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5296 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005297 } catch (ImsException e) {
5298 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
5302 }
5303
5304 @Override
5305 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5306 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005307
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005308 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005309 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5310 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5311 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005312 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005313 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5314 if (controller != null) {
5315 ImsManager imsManager = controller.getImsManager(subId);
5316 if (imsManager != null) {
5317 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5318 } else {
5319 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5320 + " is inactive, ignoring unregister.");
5321 // If the ImsManager is not valid, just return, since the callback will already
5322 // have been removed internally.
5323 }
5324 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
5328 }
5329
joonhunshincffb7fc2021-11-28 07:32:01 +00005330 @Override
5331 public void registerFeatureProvisioningChangedCallback(int subId,
5332 IFeatureProvisioningCallback callback) {
5333 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5334 mApp, subId, "registerFeatureProvisioningChangedCallback");
5335
5336 final long identity = Binder.clearCallingIdentity();
5337 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5338 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5339 }
5340
joonhunshin91bc1952022-04-29 08:47:15 +00005341 try {
5342 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5343 if (controller == null) {
5344 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5345 "Device does not support IMS");
5346 }
5347 controller.addFeatureProvisioningChangedCallback(subId, callback);
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
5350 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005351 }
5352
5353 @Override
5354 public void unregisterFeatureProvisioningChangedCallback(int subId,
5355 IFeatureProvisioningCallback callback) {
5356 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5357 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5358
5359 final long identity = Binder.clearCallingIdentity();
5360 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5361 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5362 }
5363
joonhunshin91bc1952022-04-29 08:47:15 +00005364 try {
5365 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5366 if (controller == null) {
5367 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5368 return;
5369 }
5370 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5371 } finally {
5372 Binder.restoreCallingIdentity(identity);
5373 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005374 }
allenwtsu99c623b2020-01-03 18:24:23 +08005375
5376 private void checkModifyPhoneStatePermission(int subId, String message) {
5377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5378 message);
5379 }
5380
allenwtsu99c623b2020-01-03 18:24:23 +08005381 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005382 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005383 boolean isProvisioned) {
5384 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5385
joonhunshin4ac60942023-11-15 15:23:39 +00005386 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5387 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5388
allenwtsu99c623b2020-01-03 18:24:23 +08005389 final long identity = Binder.clearCallingIdentity();
5390 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005391 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5392 if (controller == null) {
5393 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5394 return;
5395 }
5396 controller.setRcsProvisioningStatusForCapability(
5397 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005398 } finally {
5399 Binder.restoreCallingIdentity(identity);
5400 }
allenwtsu99c623b2020-01-03 18:24:23 +08005401 }
5402
5403
5404 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005405 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5406 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5407 mApp, subId, "getRcsProvisioningStatusForCapability");
5408
joonhunshin4ac60942023-11-15 15:23:39 +00005409 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5410 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5411
allenwtsu99c623b2020-01-03 18:24:23 +08005412 final long identity = Binder.clearCallingIdentity();
5413 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005414 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5415 if (controller == null) {
5416 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5417
5418 // device does not support IMS, this method will return true always.
5419 return true;
5420 }
5421 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
5425 }
5426
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005427 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005428 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5429 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005430 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005431
joonhunshin4ac60942023-11-15 15:23:39 +00005432 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5433 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5434
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005435 final long identity = Binder.clearCallingIdentity();
5436 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005437 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5438 if (controller == null) {
5439 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5440 return;
5441 }
5442 controller.setImsProvisioningStatusForCapability(
5443 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005444 } finally {
5445 Binder.restoreCallingIdentity(identity);
5446 }
5447 }
5448
5449 @Override
5450 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005451 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5452 mApp, subId, "getProvisioningStatusForCapability");
5453
joonhunshin4ac60942023-11-15 15:23:39 +00005454 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5455 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5456
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005457 final long identity = Binder.clearCallingIdentity();
5458 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005459 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5460 if (controller == null) {
5461 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005462
joonhunshin91bc1952022-04-29 08:47:15 +00005463 // device does not support IMS, this method will return true always.
5464 return true;
5465 }
5466 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005467 } finally {
5468 Binder.restoreCallingIdentity(identity);
5469 }
5470 }
5471
5472 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005473 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5474 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5475 mApp, subId, "isProvisioningRequiredForCapability");
5476
joonhunshin4ac60942023-11-15 15:23:39 +00005477 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5478 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5479
joonhunshincffb7fc2021-11-28 07:32:01 +00005480 final long identity = Binder.clearCallingIdentity();
5481 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005482 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5483 if (controller == null) {
5484 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5485
5486 // device does not support IMS, this method will return false
5487 return false;
5488 }
5489 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005490 } finally {
5491 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005492 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005493 }
5494
5495 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005496 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5497 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5498 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005499
joonhunshin4ac60942023-11-15 15:23:39 +00005500 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5501 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5502
joonhunshincffb7fc2021-11-28 07:32:01 +00005503 final long identity = Binder.clearCallingIdentity();
5504 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005505 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5506 if (controller == null) {
5507 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5508
5509 // device does not support IMS, this method will return false
5510 return false;
5511 }
5512 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005513 } finally {
5514 Binder.restoreCallingIdentity(identity);
5515 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005516 }
5517
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005518 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005519 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005520 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5521 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5522 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005523 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5524 mApp, subId, "getImsProvisioningInt");
5525
joonhunshin4ac60942023-11-15 15:23:39 +00005526 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5527 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5528
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005529 final long identity = Binder.clearCallingIdentity();
5530 try {
5531 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005532 int slotId = getSlotIndex(subId);
5533 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5534 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5535 + subId + "' for key:" + key);
5536 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5537 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005538
joonhunshin91bc1952022-04-29 08:47:15 +00005539 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5540 if (controller == null) {
5541 loge("getImsProvisioningInt: Device does not support IMS");
5542
5543 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5544 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5545 }
5546 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005547 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5548 return retVal;
5549 }
5550
calvinpanb5a34062021-02-08 19:59:36 +08005551 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005552 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005553 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5554 + subId + "' for key:" + key);
5555 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005556 } finally {
5557 Binder.restoreCallingIdentity(identity);
5558 }
5559 }
5560
5561 @Override
5562 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005563 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5564 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5565 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005566 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5567 mApp, subId, "getImsProvisioningString");
5568
joonhunshin4ac60942023-11-15 15:23:39 +00005569 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5570 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5571
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005572 final long identity = Binder.clearCallingIdentity();
5573 try {
5574 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005575 int slotId = getSlotIndex(subId);
5576 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5577 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5578 + subId + "' for key:" + key);
5579 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5580 }
calvinpanb5a34062021-02-08 19:59:36 +08005581 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005582 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005583 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5584 + subId + "' for key:" + key);
5585 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005586 } finally {
5587 Binder.restoreCallingIdentity(identity);
5588 }
5589 }
5590
5591 @Override
5592 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005593 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5594 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5595 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5597 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005598
joonhunshin4ac60942023-11-15 15:23:39 +00005599 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5600 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5601
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005602 final long identity = Binder.clearCallingIdentity();
5603 try {
5604 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005605 int slotId = getSlotIndex(subId);
5606 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5607 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5608 + subId + "' for key:" + key);
5609 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5610 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005611
joonhunshin91bc1952022-04-29 08:47:15 +00005612 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5613 if (controller == null) {
5614 loge("setImsProvisioningInt: Device does not support IMS");
5615
5616 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5617 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5618 }
5619 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005620 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5621 return retVal;
5622 }
5623
calvinpanb5a34062021-02-08 19:59:36 +08005624 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5625 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005626 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005627 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005628 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005629 } finally {
5630 Binder.restoreCallingIdentity(identity);
5631 }
5632 }
5633
5634 @Override
5635 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005636 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5637 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5638 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5640 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005641
5642 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5643 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5644
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005645 final long identity = Binder.clearCallingIdentity();
5646 try {
5647 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005648 int slotId = getSlotIndex(subId);
5649 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5650 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5651 + subId + "' for key:" + key);
5652 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5653 }
calvinpanb5a34062021-02-08 19:59:36 +08005654 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5655 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005656 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005657 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005658 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
5662 }
5663
Brad Ebinger919631e2021-06-02 17:46:35 -07005664 /**
5665 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5666 * for the given slot ID or no ImsResolver instance has been created.
5667 * @param slotId The slot ID that the IMS service is created for.
5668 * @throws ImsException If there is no ImsService configured for this slot.
5669 */
5670 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5671 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5672 ImsFeature.FEATURE_MMTEL)) {
5673 throw new ImsException("This subscription does not support MMTEL over IMS",
5674 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5675 }
5676 }
5677
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005678 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005679 int slotId = SubscriptionManager.getSlotIndex(subId);
5680 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005681 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5682 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005683 }
5684 return slotId;
5685 }
5686
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005687 private int getSlotIndex(int subId) {
5688 int slotId = SubscriptionManager.getSlotIndex(subId);
5689 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5690 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5691 }
5692 return slotId;
5693 }
5694
Wink Saville36469e72014-06-11 15:17:00 -07005695 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005696 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005697 */
5698 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005699 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5700 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005701 try {
5702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5703 } catch (SecurityException se) {
5704 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5705 throw new SecurityException("Package " + callingPackage + " does not belong to "
5706 + Binder.getCallingUid());
5707 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005708 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005709 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005710 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005711 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005712 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005713 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005714 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005715 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5716 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005717
joonhunshin4ac60942023-11-15 15:23:39 +00005718 enforceTelephonyFeatureWithException(callingPackage,
5719 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5720
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721 final long identity = Binder.clearCallingIdentity();
5722 try {
5723 final Phone phone = getPhone(subId);
5724 if (phone != null) {
5725 return phone.getServiceState().getDataNetworkType();
5726 } else {
5727 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5728 }
5729 } finally {
5730 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005731 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005732 }
5733
5734 /**
5735 * Returns the data network type
5736 */
5737 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005738 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005739 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005740 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005741 }
5742
5743 /**
5744 * Returns the data network type for a subId
5745 */
5746 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005747 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5748 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005749 String functionName = "getDataNetworkTypeForSubscriber";
5750 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5751 mApp, functionName)) {
5752 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5753 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5754 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5755 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005756 }
5757
joonhunshin4ac60942023-11-15 15:23:39 +00005758 enforceTelephonyFeatureWithException(callingPackage,
5759 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5760
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 final long identity = Binder.clearCallingIdentity();
5762 try {
5763 final Phone phone = getPhone(subId);
5764 if (phone != null) {
5765 return phone.getServiceState().getDataNetworkType();
5766 } else {
5767 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5768 }
5769 } finally {
5770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005772 }
5773
5774 /**
Wink Saville36469e72014-06-11 15:17:00 -07005775 * Returns the Voice network type for a subId
5776 */
5777 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005778 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5779 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005780 String functionName = "getVoiceNetworkTypeForSubscriber";
5781 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5782 mApp, functionName)) {
5783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5784 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5785 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5786 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005787 }
5788
joonhunshin4ac60942023-11-15 15:23:39 +00005789 enforceTelephonyFeatureWithException(callingPackage,
5790 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 final Phone phone = getPhone(subId);
5795 if (phone != null) {
5796 return phone.getServiceState().getVoiceNetworkType();
5797 } else {
5798 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5799 }
5800 } finally {
5801 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005802 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005803 }
5804
5805 /**
5806 * @return true if a ICC card is present
5807 */
5808 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005809 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005810 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005811 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005812 }
5813
5814 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005815 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005816 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005817 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005818 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005819 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5820 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 final long identity = Binder.clearCallingIdentity();
5823 try {
5824 final Phone phone = PhoneFactory.getPhone(slotIndex);
5825 if (phone != null) {
5826 return phone.getIccCard().hasIccCard();
5827 } else {
5828 return false;
5829 }
5830 } finally {
5831 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005833 }
5834
5835 /**
5836 * Return if the current radio is LTE on CDMA. This
5837 * is a tri-state return value as for a period of time
5838 * the mode may be unknown.
5839 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005840 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005841 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005842 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005843 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005844 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005845 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5846 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5847 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005848 }
5849
Sanket Padawe356d7632015-06-22 14:03:32 -07005850 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005851 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5852 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005853 try {
5854 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5855 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005856 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5857 }
5858
joonhunshin4ac60942023-11-15 15:23:39 +00005859 enforceTelephonyFeatureWithException(callingPackage,
5860 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5861
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005862 final long identity = Binder.clearCallingIdentity();
5863 try {
5864 final Phone phone = getPhone(subId);
5865 if (phone == null) {
5866 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5867 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005868 return TelephonyProperties.lte_on_cdma_device()
5869 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870 }
5871 } finally {
5872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005873 }
Wink Saville36469e72014-06-11 15:17:00 -07005874 }
5875
Wink Saville36469e72014-06-11 15:17:00 -07005876 /**
5877 * {@hide}
5878 * Returns Default subId, 0 in the case of single standby.
5879 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005880 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005881 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005882 }
5883
Shishir Agrawala9f32182016-04-12 12:00:16 -07005884 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005885 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005886 }
5887
Wink Savilleb564aae2014-10-23 10:18:09 -07005888 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005889 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005890 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005891
Pengquan Menge92a50d2018-09-21 15:54:48 -07005892 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005893 return getSubscriptionManagerService().isActiveSubId(subId,
5894 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005895 }
5896
Ihab Awadf2177b72013-11-25 13:33:23 -08005897 /**
5898 * @see android.telephony.TelephonyManager.WifiCallingChoices
5899 */
5900 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 final long identity = Binder.clearCallingIdentity();
5902 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005903 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5905 getWhenToMakeWifiCallsDefaultPreference());
5906 } finally {
5907 Binder.restoreCallingIdentity(identity);
5908 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005909 }
5910
5911 /**
5912 * @see android.telephony.TelephonyManager.WifiCallingChoices
5913 */
5914 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 final long identity = Binder.clearCallingIdentity();
5916 try {
5917 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005918 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5920 } finally {
5921 Binder.restoreCallingIdentity(identity);
5922 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005923 }
5924
Sailesh Nepald1e68152013-12-12 19:08:02 -08005925 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005926 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005927 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005928 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005929
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005930 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5931 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5932 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005933 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005934 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005935 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005936 }
5937 return PhoneFactory.getPhone(phoneId);
5938 }
5939
Shishir Agrawal566b7612013-10-28 14:41:00 -07005940 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005941 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005942 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005943
Rambo Wanga1782702021-11-10 20:15:19 -08005944 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5945 /*message=*/ "iccOpenLogicalChannel");
5946
5947 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5948 // Verify that the callingPackage in the request belongs to the calling UID
5949 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5950
joonhunshin4ac60942023-11-15 15:23:39 +00005951 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5952 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5953
Rambo Wanga1782702021-11-10 20:15:19 -08005954 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005955 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005956
Rambo Wanga1782702021-11-10 20:15:19 -08005957 private Phone getPhoneFromValidIccLogicalChannelRequest(
5958 @NonNull IccLogicalChannelRequest request, String message) {
5959 Phone phone;
5960 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5962 mApp, request.subId, message);
5963 phone = getPhoneFromSubId(request.subId);
5964 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5965 enforceModifyPermission();
5966 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5967 } else {
5968 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005969 }
Rambo Wanga1782702021-11-10 20:15:19 -08005970 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005971 }
5972
5973 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005974 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 final long identity = Binder.clearCallingIdentity();
5976 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005977 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005979 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5980 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005981 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5982 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983 loge("The calling package is not allowed to access ISD-R.");
5984 throw new SecurityException(
5985 "The calling package is not allowed to access ISD-R.");
5986 }
Derek Tan740e1672017-06-27 14:56:27 -07005987 }
Derek Tan740e1672017-06-27 14:56:27 -07005988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005990 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5991 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 return response;
5993 } finally {
5994 Binder.restoreCallingIdentity(identity);
5995 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005996 }
5997
5998 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005999 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006000 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6001 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6002
Rambo Wanga1782702021-11-10 20:15:19 -08006003 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6004 /*message=*/"iccCloseLogicalChannel");
6005
6006 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6007
6008 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006009 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006010
Rambo Wanga1782702021-11-10 20:15:19 -08006011 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6012 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006013 // before this feature is enabled, this API should only return false if
6014 // the operation fails instead of throwing runtime exception for
6015 // backward-compatibility.
6016 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6017 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 final long identity = Binder.clearCallingIdentity();
6019 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006020 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006021 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 }
Chen Xue9d737e2022-01-01 23:41:31 -08006023 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006024 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006025 Boolean success = false;
6026 if (result instanceof RuntimeException) {
6027 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006028 if (shouldThrowExceptionOnFailure) {
6029 throw (RuntimeException) result;
6030 } else {
6031 return false;
6032 }
Chen Xue9d737e2022-01-01 23:41:31 -08006033 } else if (result instanceof Boolean) {
6034 success = (Boolean) result;
6035 } else {
6036 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6037 }
Rambo Wanga1782702021-11-10 20:15:19 -08006038 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 return success;
6040 } finally {
6041 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006042 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006043 }
6044
6045 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006046 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006047 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6049 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006050
6051 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6052 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6053
Jordan Liu4c733742019-02-28 12:03:40 -08006054 if (DBG) {
6055 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6056 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6057 + p3 + " data=" + data);
6058 }
6059 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6060 command, p1, p2, p3, data);
6061 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006062
Jordan Liu4c733742019-02-28 12:03:40 -08006063 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006064 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006065 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006066 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006067
6068 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6069 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6070 "iccTransmitApduLogicalChannelBySlot");
6071
Jordan Liu4c733742019-02-28 12:03:40 -08006072 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006073 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006074 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6075 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006076 }
6077 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006078 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6079 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006080 }
6081
6082 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6083 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 final long identity = Binder.clearCallingIdentity();
6085 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006086 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 return "";
6088 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006091 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6092 null /* workSource */);
6093 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006095 // Append the returned status code to the end of the response payload.
6096 String s = Integer.toHexString(
6097 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6098 if (response.payload != null) {
6099 s = IccUtils.bytesToHexString(response.payload) + s;
6100 }
6101 return s;
6102 } finally {
6103 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006104 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006105 }
Jake Hambye994d462014-02-03 13:10:13 -08006106
Evan Charltonc66da362014-05-16 14:06:40 -07006107 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006108 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6109 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6111 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006113
6114 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6115 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6116
Jordan Liu4c733742019-02-28 12:03:40 -08006117 if (DBG) {
6118 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6119 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6120 }
6121 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6122 cla, command, p1, p2, p3, data);
6123 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006124
Jordan Liu4c733742019-02-28 12:03:40 -08006125 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006126 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006127 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006128 enforceModifyPermission();
6129 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006130
6131 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6132 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6133
Jordan Liu4c733742019-02-28 12:03:40 -08006134 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006135 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006136 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6137 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006138 }
6139
6140 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006141 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6142 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006143 }
6144
6145 // open APDU basic channel assuming the caller has sufficient permissions
6146 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6147 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 final long identity = Binder.clearCallingIdentity();
6149 try {
6150 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6151 && TextUtils.equals(ISDR_AID, data)) {
6152 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006153 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6154 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155 if (bestComponent == null
6156 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6157 loge("The calling package is not allowed to select ISD-R.");
6158 throw new SecurityException(
6159 "The calling package is not allowed to select ISD-R.");
6160 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006161 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006164 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6165 null /* workSource */);
6166 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 // Append the returned status code to the end of the response payload.
6169 String s = Integer.toHexString(
6170 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6171 if (response.payload != null) {
6172 s = IccUtils.bytesToHexString(response.payload) + s;
6173 }
6174 return s;
6175 } finally {
6176 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006177 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006178 }
6179
6180 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006181 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006182 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6184 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006185
joonhunshin4ac60942023-11-15 15:23:39 +00006186 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6187 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189 final long identity = Binder.clearCallingIdentity();
6190 try {
6191 if (DBG) {
6192 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6193 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6194 }
6195
6196 IccIoResult response =
6197 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6198 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6199 subId);
6200
6201 if (DBG) {
6202 log("Exchange SIM_IO [R]" + response);
6203 }
6204
6205 byte[] result = null;
6206 int length = 2;
6207 if (response.payload != null) {
6208 length = 2 + response.payload.length;
6209 result = new byte[length];
6210 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6211 } else {
6212 result = new byte[length];
6213 }
6214
6215 result[length - 1] = (byte) response.sw2;
6216 result[length - 2] = (byte) response.sw1;
6217 return result;
6218 } finally {
6219 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006220 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006221 }
6222
Nathan Haroldb3014052017-01-25 15:57:32 -08006223 /**
6224 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6225 * on a particular subscription
6226 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006227 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6228 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006230 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006231 return null;
6232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233
joonhunshin4ac60942023-11-15 15:23:39 +00006234 enforceTelephonyFeatureWithException(callingPackage,
6235 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 final long identity = Binder.clearCallingIdentity();
6238 try {
6239 if (appType != TelephonyManager.APPTYPE_USIM
6240 && appType != TelephonyManager.APPTYPE_SIM) {
6241 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6242 return null;
6243 }
6244 Object response = sendRequest(
6245 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6246 if (response instanceof String[]) {
6247 return (String[]) response;
6248 }
yincheng zhao2737e882019-09-06 17:06:54 -07006249 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006251 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006252 } finally {
6253 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006254 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006255 }
6256
yincheng zhao2737e882019-09-06 17:06:54 -07006257 /**
6258 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6259 * subscription.
6260 *
6261 * @param subId the id of the subscription.
6262 * @param appType the uicc app type, must be USIM or SIM.
6263 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6264 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006265 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006266 * @return number of fplmns that is successfully written to the SIM.
6267 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006268 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6269 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6271 mApp, subId, "setForbiddenPlmns");
6272
joonhunshin4ac60942023-11-15 15:23:39 +00006273 enforceTelephonyFeatureWithException(callingPackage,
6274 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6275
yincheng zhao2737e882019-09-06 17:06:54 -07006276 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6277 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6278 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6279 }
6280 if (fplmns == null) {
6281 throw new IllegalArgumentException("Fplmn List provided is null");
6282 }
6283 for (String fplmn : fplmns) {
6284 if (!CellIdentity.isValidPlmn(fplmn)) {
6285 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6286 }
6287 }
6288 final long identity = Binder.clearCallingIdentity();
6289 try {
6290 Object response = sendRequest(
6291 CMD_SET_FORBIDDEN_PLMNS,
6292 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6293 subId);
6294 return (int) response;
6295 } finally {
6296 Binder.restoreCallingIdentity(identity);
6297 }
6298 }
6299
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006300 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006301 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6303 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006304
joonhunshin4ac60942023-11-15 15:23:39 +00006305 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6306 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308 final long identity = Binder.clearCallingIdentity();
6309 try {
6310 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6311 if (response.payload == null) {
6312 return "";
6313 }
Evan Charltonc66da362014-05-16 14:06:40 -07006314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 // Append the returned status code to the end of the response payload.
6316 String s = Integer.toHexString(
6317 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6318 s = IccUtils.bytesToHexString(response.payload) + s;
6319 return s;
6320 } finally {
6321 Binder.restoreCallingIdentity(identity);
6322 }
Evan Charltonc66da362014-05-16 14:06:40 -07006323 }
6324
Jake Hambye994d462014-02-03 13:10:13 -08006325 /**
6326 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6327 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6328 *
6329 * @param itemID the ID of the item to read
6330 * @return the NV item as a String, or null on error.
6331 */
6332 @Override
6333 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006334 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6336 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337
6338 final long identity = Binder.clearCallingIdentity();
6339 try {
6340 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006341 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6343 return value;
6344 } finally {
6345 Binder.restoreCallingIdentity(identity);
6346 }
Jake Hambye994d462014-02-03 13:10:13 -08006347 }
6348
6349 /**
6350 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6351 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6352 *
6353 * @param itemID the ID of the item to read
6354 * @param itemValue the value to write, as a String
6355 * @return true on success; false on any failure
6356 */
6357 @Override
6358 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006359 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6361 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362
6363 final long identity = Binder.clearCallingIdentity();
6364 try {
6365 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6366 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006367 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6369 return success;
6370 } finally {
6371 Binder.restoreCallingIdentity(identity);
6372 }
Jake Hambye994d462014-02-03 13:10:13 -08006373 }
6374
6375 /**
6376 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6377 * Used for device configuration by some CDMA operators.
6378 *
6379 * @param preferredRoamingList byte array containing the new PRL
6380 * @return true on success; false on any failure
6381 */
6382 @Override
6383 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6385 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386
6387 final long identity = Binder.clearCallingIdentity();
6388 try {
6389 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6390 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6391 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6392 return success;
6393 } finally {
6394 Binder.restoreCallingIdentity(identity);
6395 }
Jake Hambye994d462014-02-03 13:10:13 -08006396 }
6397
6398 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006399 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006400 * Used for device configuration by some CDMA operators.
6401 *
chen xu6dac5ab2018-10-26 17:39:23 -07006402 * @param slotIndex - device slot.
6403 *
Jake Hambye994d462014-02-03 13:10:13 -08006404 * @return true on success; false on any failure
6405 */
6406 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006407 public boolean resetModemConfig(int slotIndex) {
6408 Phone phone = PhoneFactory.getPhone(slotIndex);
6409 if (phone != null) {
6410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6411 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412
joonhunshin4ac60942023-11-15 15:23:39 +00006413 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6414 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6415
chen xu6dac5ab2018-10-26 17:39:23 -07006416 final long identity = Binder.clearCallingIdentity();
6417 try {
6418 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6419 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6420 return success;
6421 } finally {
6422 Binder.restoreCallingIdentity(identity);
6423 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424 }
chen xu6dac5ab2018-10-26 17:39:23 -07006425 return false;
6426 }
6427
6428 /**
6429 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6430 *
6431 * @param slotIndex - device slot.
6432 *
6433 * @return true on success; false on any failure
6434 */
6435 @Override
6436 public boolean rebootModem(int slotIndex) {
6437 Phone phone = PhoneFactory.getPhone(slotIndex);
6438 if (phone != null) {
6439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6440 mApp, phone.getSubId(), "rebootModem");
6441
joonhunshin4ac60942023-11-15 15:23:39 +00006442 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6443 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6444
chen xu6dac5ab2018-10-26 17:39:23 -07006445 final long identity = Binder.clearCallingIdentity();
6446 try {
6447 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6448 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6449 return success;
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
6453 }
6454 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006455 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006456
Brad Ebinger51f743a2017-01-23 13:50:20 -08006457 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006458 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6459 * {@link #disableIms(int)}.
6460 * @param slotIndex device slot.
6461 */
6462 public void resetIms(int slotIndex) {
6463 enforceModifyPermission();
6464
joonhunshin4ac60942023-11-15 15:23:39 +00006465 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6466 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6467
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006468 final long identity = Binder.clearCallingIdentity();
6469 try {
6470 if (mImsResolver == null) {
6471 // may happen if the does not support IMS.
6472 return;
6473 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006474 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006475 } finally {
6476 Binder.restoreCallingIdentity(identity);
6477 }
6478 }
6479
6480 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006481 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6482 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006483 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006484 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006485 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006486
6487 final long identity = Binder.clearCallingIdentity();
6488 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006489 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006490 // may happen if the device does not support IMS.
6491 return;
6492 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006493 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006494 } finally {
6495 Binder.restoreCallingIdentity(identity);
6496 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006497 }
6498
6499 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006500 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6501 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006502 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006503 public void disableIms(int slotId) {
6504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006505
6506 final long identity = Binder.clearCallingIdentity();
6507 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006508 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006509 // may happen if the device does not support IMS.
6510 return;
6511 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006512 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513 } finally {
6514 Binder.restoreCallingIdentity(identity);
6515 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006516 }
6517
6518 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006519 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6520 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006521 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006522 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006523 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006525
6526 final long identity = Binder.clearCallingIdentity();
6527 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006528 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006529 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6530 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006531 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006532 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006533 } finally {
6534 Binder.restoreCallingIdentity(identity);
6535 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006536 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006537 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006538 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6539 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006540 @Override
6541 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006542 enforceModifyPermission();
6543
6544 final long identity = Binder.clearCallingIdentity();
6545 try {
6546 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006547 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006548 } finally {
6549 Binder.restoreCallingIdentity(identity);
6550 }
6551 }
6552
6553 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006554 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006555 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006556 */
6557 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6558 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559
6560 final long identity = Binder.clearCallingIdentity();
6561 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006562 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006563 // may happen if the device does not support IMS.
6564 return null;
6565 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006566 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006567 } finally {
6568 Binder.restoreCallingIdentity(identity);
6569 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006570 }
6571
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006572 /**
6573 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006574 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006575 */
6576 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6577 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578
6579 final long identity = Binder.clearCallingIdentity();
6580 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006581 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006582 // may happen if the device does not support IMS.
6583 return null;
6584 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006585 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 } finally {
6587 Binder.restoreCallingIdentity(identity);
6588 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006589 }
6590
Brad Ebinger884c07b2018-02-15 16:17:40 -08006591 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006592 * Sets the ImsService Package Name that Telephony will bind to.
6593 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006594 * @param slotIndex the slot ID that the ImsService should bind for.
6595 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006596 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006597 * @param featureTypes An integer array of feature types associated with a packageName.
6598 * @param packageName The name of the package that the current configuration will be replaced
6599 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006600 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006601 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006602 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6603 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006604 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006606 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006608 final long identity = Binder.clearCallingIdentity();
6609 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006610 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006611 // may happen if the device does not support IMS.
6612 return false;
6613 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006614 Map<Integer, String> featureConfig = new HashMap<>();
6615 for (int featureType : featureTypes) {
6616 featureConfig.put(featureType, packageName);
6617 }
6618 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6619 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006620 } finally {
6621 Binder.restoreCallingIdentity(identity);
6622 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006623 }
6624
6625 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006626 * Clears any carrier ImsService overrides for the slot index specified that were previously
6627 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6628 *
6629 * This should only be used for testing.
6630 *
6631 * @param slotIndex the slot ID that the ImsService should bind for.
6632 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6633 */
6634 @Override
6635 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006636 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6637 "clearCarrierImsServiceOverride");
6638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006639 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006640
6641 final long identity = Binder.clearCallingIdentity();
6642 try {
6643 if (mImsResolver == null) {
6644 // may happen if the device does not support IMS.
6645 return false;
6646 }
6647 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6648 } finally {
6649 Binder.restoreCallingIdentity(identity);
6650 }
6651 }
6652
6653 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006654 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006655 *
6656 * @param slotId The slot that the ImsService is associated with.
6657 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6658 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006659 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006660 * @return the package name of the ImsService configuration.
6661 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006662 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6663 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006664 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006665 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6666 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 final long identity = Binder.clearCallingIdentity();
6669 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006670 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006671 // may happen if the device does not support IMS.
6672 return "";
6673 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006674 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006675 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6676 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677 } finally {
6678 Binder.restoreCallingIdentity(identity);
6679 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006680 }
6681
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006682 /**
6683 * Get the MmTelFeature state associated with the requested subscription id.
6684 * @param subId The subscription that the MmTelFeature is associated with.
6685 * @param callback A callback with an integer containing the
6686 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6687 */
6688 @Override
6689 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6690 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006691 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6692 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6693 "IMS not available on device.");
6694 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006695 final long token = Binder.clearCallingIdentity();
6696 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006697 int slotId = getSlotIndex(subId);
6698 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6699 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6700 + subId + "'");
6701 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6702 }
6703 verifyImsMmTelConfiguredOrThrow(slotId);
6704 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6705 try {
6706 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6707 } catch (RemoteException e) {
6708 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6709 + "Ignore");
6710 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006711 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006712 } catch (ImsException e) {
6713 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006714 } finally {
6715 Binder.restoreCallingIdentity(token);
6716 }
6717 }
6718
Daniel Brightbb5840b2021-01-12 15:48:18 -08006719 /**
6720 * Sets the ims registration state on all valid {@link Phone}s.
6721 */
6722 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006723 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724
6725 final long identity = Binder.clearCallingIdentity();
6726 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006727 // NOTE: Before S, this method only set the default phone.
6728 for (final Phone phone : PhoneFactory.getPhones()) {
6729 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6730 phone.setImsRegistrationState(registered);
6731 }
6732 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733 } finally {
6734 Binder.restoreCallingIdentity(identity);
6735 }
Wink Saville36469e72014-06-11 15:17:00 -07006736 }
6737
6738 /**
Stuart Scott54788802015-03-30 13:18:01 -07006739 * Set the network selection mode to automatic.
6740 *
6741 */
6742 @Override
6743 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6745 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746
joonhunshin4ac60942023-11-15 15:23:39 +00006747 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6748 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750 final long identity = Binder.clearCallingIdentity();
6751 try {
shilufc958392020-01-20 11:36:01 -08006752 if (!isActiveSubscription(subId)) {
6753 return;
6754 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006755 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006756 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
Nathan Harolddc3bcec2024-05-16 14:06:40 -07006757 BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 } finally {
6759 Binder.restoreCallingIdentity(identity);
6760 }
Stuart Scott54788802015-03-30 13:18:01 -07006761 }
6762
Jack Yud10cdd42020-09-28 20:28:01 -07006763 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006764 * Ask the radio to connect to the input network and change selection mode to manual.
6765 *
6766 * @param subId the id of the subscription.
6767 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6768 * the operator to attach to.
6769 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6770 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6771 * normal network selection next time.
6772 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006773 */
6774 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006775 public boolean setNetworkSelectionModeManual(
6776 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6778 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006779
joonhunshin4ac60942023-11-15 15:23:39 +00006780 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6781 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6782
Jack Yu285100e2022-12-02 22:48:35 -08006783 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006784 if (!isActiveSubscription(subId)) {
6785 return false;
6786 }
6787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006789 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006791 if (DBG) {
6792 log("setNetworkSelectionModeManual: subId: " + subId
6793 + " operator: " + operatorInfo);
6794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6796 } finally {
6797 Binder.restoreCallingIdentity(identity);
6798 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006799 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006800 /**
shilu84f6e8b2019-12-19 13:58:01 -08006801 * Get the manual network selection
6802 *
6803 * @param subId the id of the subscription.
6804 *
6805 * @return the previously saved user selected PLMN
6806 */
6807 @Override
6808 public String getManualNetworkSelectionPlmn(int subId) {
6809 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006810 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6811 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006812
joonhunshin4ac60942023-11-15 15:23:39 +00006813 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6814 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6815
shilu84f6e8b2019-12-19 13:58:01 -08006816 final long identity = Binder.clearCallingIdentity();
6817 try {
6818 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006819 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006820 }
6821
6822 final Phone phone = getPhone(subId);
6823 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006824 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006825 }
6826 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6827 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006828 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006829 } finally {
6830 Binder.restoreCallingIdentity(identity);
6831 }
6832 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006833
6834 /**
6835 * Scans for available networks.
6836 */
6837 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006838 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6839 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6841 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006842 LocationAccessPolicy.LocationPermissionResult locationResult =
6843 LocationAccessPolicy.checkLocationPermission(mApp,
6844 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6845 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006846 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006847 .setCallingPid(Binder.getCallingPid())
6848 .setCallingUid(Binder.getCallingUid())
6849 .setMethod("getCellNetworkScanResults")
6850 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006851 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6852 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006853 .build());
6854 switch (locationResult) {
6855 case DENIED_HARD:
6856 throw new SecurityException("Not allowed to access scan results -- location");
6857 case DENIED_SOFT:
6858 return null;
6859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860
Pengquan Menga1bb6272018-09-06 09:59:22 -07006861 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862 try {
6863 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006864 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006866 } finally {
6867 Binder.restoreCallingIdentity(identity);
6868 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006869 }
6870
6871 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006872 * Get the call forwarding info, given the call forwarding reason.
6873 */
6874 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006875 public void getCallForwarding(int subId, int callForwardingReason,
6876 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006877 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006878
6879 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6880 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6881
Shuo Qian4a594052020-01-23 11:59:30 -08006882 long identity = Binder.clearCallingIdentity();
6883 try {
6884 if (DBG) {
6885 log("getCallForwarding: subId " + subId
6886 + " callForwardingReason" + callForwardingReason);
6887 }
Hall Liu27d24262020-09-18 19:04:59 -07006888
6889 Phone phone = getPhone(subId);
6890 if (phone == null) {
6891 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006892 callback.onError(
6893 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006894 } catch (RemoteException e) {
6895 // ignore
6896 }
6897 return;
6898 }
6899
6900 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6901 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6902 @Override
6903 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6904 try {
6905 callback.onCallForwardingInfoAvailable(info);
6906 } catch (RemoteException e) {
6907 // ignore
6908 }
6909 }
6910
6911 @Override
6912 public void onError(int error) {
6913 try {
6914 callback.onError(error);
6915 } catch (RemoteException e) {
6916 // ignore
6917 }
6918 }
6919 });
6920 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006921 } finally {
6922 Binder.restoreCallingIdentity(identity);
6923 }
6924 }
6925
6926 /**
6927 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6928 * reason, the number to forward, and the timeout before the forwarding is attempted.
6929 */
6930 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006931 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6932 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006933 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006934
6935 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6936 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6937
Shuo Qian4a594052020-01-23 11:59:30 -08006938 long identity = Binder.clearCallingIdentity();
6939 try {
6940 if (DBG) {
6941 log("setCallForwarding: subId " + subId
6942 + " callForwardingInfo" + callForwardingInfo);
6943 }
Hall Liu27d24262020-09-18 19:04:59 -07006944
6945 Phone phone = getPhone(subId);
6946 if (phone == null) {
6947 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006948 callback.accept(
6949 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006950 } catch (RemoteException e) {
6951 // ignore
6952 }
6953 return;
6954 }
6955
6956 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6957 FunctionalUtils.ignoreRemoteException(callback::accept));
6958
6959 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006960 } finally {
6961 Binder.restoreCallingIdentity(identity);
6962 }
6963 }
6964
6965 /**
Hall Liu27d24262020-09-18 19:04:59 -07006966 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006967 */
6968 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006969 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006970 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006971
6972 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6973 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6974
Shuo Qian4a594052020-01-23 11:59:30 -08006975 long identity = Binder.clearCallingIdentity();
6976 try {
Hall Liu27d24262020-09-18 19:04:59 -07006977 Phone phone = getPhone(subId);
6978 if (phone == null) {
6979 try {
6980 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6981 } catch (RemoteException e) {
6982 // ignore
6983 }
6984 return;
6985 }
SongFerngWang0e767992021-03-31 22:08:45 +08006986 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6987 PersistableBundle c = configManager.getConfigForSubId(subId);
6988 boolean requireUssd = c.getBoolean(
6989 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006990
Shuo Qian4a594052020-01-23 11:59:30 -08006991 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006992 if (requireUssd) {
6993 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6994 getSubscriptionCarrierId(subId));
6995 String newUssdCommand = "";
6996 try {
6997 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006998 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006999 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7000 } catch (NullPointerException e) {
7001 loge("Failed to generate USSD number" + e);
7002 }
7003 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7004 mMainThreadHandler, callback, carrierXmlParser,
7005 CarrierXmlParser.SsEntry.SSAction.QUERY);
7006 final String ussdCommand = newUssdCommand;
7007 Executors.newSingleThreadExecutor().execute(() -> {
7008 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7009 });
7010 } else {
7011 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7012 callback::accept);
7013 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7014 }
Shuo Qian4a594052020-01-23 11:59:30 -08007015 } finally {
7016 Binder.restoreCallingIdentity(identity);
7017 }
7018 }
7019
7020 /**
Hall Liu27d24262020-09-18 19:04:59 -07007021 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007022 */
7023 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007024 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007025 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007026
7027 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7028 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7029
Shuo Qian4a594052020-01-23 11:59:30 -08007030 long identity = Binder.clearCallingIdentity();
7031 try {
Hall Liu27d24262020-09-18 19:04:59 -07007032 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7033
7034 Phone phone = getPhone(subId);
7035 if (phone == null) {
7036 try {
7037 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7038 } catch (RemoteException e) {
7039 // ignore
7040 }
7041 return;
7042 }
7043
SongFerngWang0e767992021-03-31 22:08:45 +08007044 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7045 PersistableBundle c = configManager.getConfigForSubId(subId);
7046 boolean requireUssd = c.getBoolean(
7047 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007048
SongFerngWang0e767992021-03-31 22:08:45 +08007049 if (DBG) log("getCallWaitingStatus: subId " + subId);
7050 if (requireUssd) {
7051 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7052 getSubscriptionCarrierId(subId));
7053 CarrierXmlParser.SsEntry.SSAction ssAction =
7054 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7055 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7056 String newUssdCommand = "";
7057 try {
7058 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007059 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007060 .makeCommand(ssAction, null);
7061 } catch (NullPointerException e) {
7062 loge("Failed to generate USSD number" + e);
7063 }
7064 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7065 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7066 final String ussdCommand = newUssdCommand;
7067 Executors.newSingleThreadExecutor().execute(() -> {
7068 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7069 });
7070 } else {
7071 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7072 FunctionalUtils.ignoreRemoteException(callback::accept));
7073
7074 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7075 }
Shuo Qian4a594052020-01-23 11:59:30 -08007076 } finally {
7077 Binder.restoreCallingIdentity(identity);
7078 }
7079 }
7080
7081 /**
yinxub1bed742017-04-17 11:45:04 -07007082 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007083 *
yinxub1bed742017-04-17 11:45:04 -07007084 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007085 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7086 * location related information which will be sent if the caller already possess
7087 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007088 * @param request contains the radio access networks with bands/channels to scan
7089 * @param messenger callback messenger for scan results or errors
7090 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007091 * @return the id of the requested scan which can be used to stop the scan.
7092 */
7093 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007094 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7095 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007096 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7098 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007099 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007100 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7101 if (!renounceFineLocationAccess) {
7102 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007103 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7104 .setCallingPackage(callingPackage)
7105 .setCallingFeatureId(callingFeatureId)
7106 .setCallingPid(Binder.getCallingPid())
7107 .setCallingUid(Binder.getCallingUid())
7108 .setMethod("requestNetworkScan")
7109 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7110 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7111 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7112 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007113 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007114 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007115 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7116 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007117 if (e != null) {
7118 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7119 throw e;
7120 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007121 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007122 return TelephonyScanManager.INVALID_SCAN_ID;
7123 }
7124 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125 }
joonhunshin4ac60942023-11-15 15:23:39 +00007126
7127 enforceTelephonyFeatureWithException(callingPackage,
7128 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7129
Hall Liu912dfd32019-04-25 14:02:26 -07007130 int callingUid = Binder.getCallingUid();
7131 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007132 final long identity = Binder.clearCallingIdentity();
7133 try {
7134 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007135 renounceFineLocationAccess, request, messenger, binder,
7136 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007137 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007138 } finally {
7139 Binder.restoreCallingIdentity(identity);
7140 }
yinxu504e1392017-04-12 16:03:22 -07007141 }
7142
Hall Liub2ac8ef2019-02-28 15:56:23 -08007143 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007144 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007145 boolean hasCarrierPriv;
7146 final long identity = Binder.clearCallingIdentity();
7147 try {
7148 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7149 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7150 } finally {
7151 Binder.restoreCallingIdentity(identity);
7152 }
Hall Liu558027f2019-05-15 19:14:05 -07007153 boolean hasNetworkScanPermission =
7154 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007155 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007156
7157 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7158 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7159 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007160 }
7161
7162 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7163 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007164 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7165 return new SecurityException("Specific channels must not be"
7166 + " scanned without location access.");
7167 }
7168 }
7169 }
7170
Hall Liub2ac8ef2019-02-28 15:56:23 -08007171 return null;
7172 }
7173
yinxu504e1392017-04-12 16:03:22 -07007174 /**
7175 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007176 *
7177 * @param subId id of the subscription
7178 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007179 */
7180 @Override
7181 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7183 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184
Hall Liu912dfd32019-04-25 14:02:26 -07007185 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007186 final long identity = Binder.clearCallingIdentity();
7187 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007188 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 } finally {
7190 Binder.restoreCallingIdentity(identity);
7191 }
yinxu504e1392017-04-12 16:03:22 -07007192 }
7193
7194 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007195 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007196 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007197 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007198 */
7199 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007200 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007201 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007202 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007203 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204
joonhunshin4ac60942023-11-15 15:23:39 +00007205 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7206 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007208 final long identity = Binder.clearCallingIdentity();
7209 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007210 if (DBG) log("getAllowedNetworkTypesBitmask");
7211 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7212 int networkTypesBitmask = (result != null ? result[0] : -1);
7213 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7214 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007215 } finally {
7216 Binder.restoreCallingIdentity(identity);
7217 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007218 }
7219
7220 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007221 * Get the allowed network types for certain reason.
7222 *
7223 * @param subId the id of the subscription.
7224 * @param reason the reason the allowed network type change is taking place
7225 * @return the allowed network types.
7226 */
7227 @Override
7228 public long getAllowedNetworkTypesForReason(int subId,
7229 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007230 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007231 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007232
7233 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7234 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7235
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007236 final long identity = Binder.clearCallingIdentity();
7237 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007238 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
7242 }
7243
7244 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007245 * Enable/Disable E-UTRA-NR Dual Connectivity
7246 * @param subId subscription id of the sim card
7247 * @param nrDualConnectivityState expected NR dual connectivity state
7248 * This can be passed following states
7249 * <ol>
7250 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7251 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7252 * <li>Disable NR dual connectivity and force secondary cell to be released
7253 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7254 * </ol>
7255 * @return operation result.
7256 */
7257 @Override
7258 public int setNrDualConnectivityState(int subId,
7259 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7261 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007262 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007263 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7264 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7265 }
7266
Sooraj Sasindran37444802020-08-11 10:40:43 -07007267 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7268 final long identity = Binder.clearCallingIdentity();
7269 try {
7270 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7271 nrDualConnectivityState, subId,
7272 workSource);
7273 if (DBG) log("enableNRDualConnectivity result: " + result);
7274 return result;
7275 } finally {
7276 Binder.restoreCallingIdentity(identity);
7277 }
7278 }
7279
7280 /**
7281 * Is E-UTRA-NR Dual Connectivity enabled
7282 * @return true if dual connectivity is enabled else false
7283 */
7284 @Override
7285 public boolean isNrDualConnectivityEnabled(int subId) {
7286 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007287 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007288 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007289 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007290 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7291 return false;
7292 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007293 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7294 final long identity = Binder.clearCallingIdentity();
7295 try {
7296 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7297 null, subId, workSource);
7298 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7299 return isEnabled;
7300 } finally {
7301 Binder.restoreCallingIdentity(identity);
7302 }
7303 }
7304
7305 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007306 * Set the allowed network types of the device and
7307 * provide the reason triggering the allowed network change.
7308 *
7309 * @param subId the id of the subscription.
7310 * @param reason the reason the allowed network type change is taking place
7311 * @param allowedNetworkTypes the allowed network types.
7312 * @return true on success; false on any failure.
7313 */
7314 @Override
7315 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007316 @TelephonyManager.AllowedNetworkTypesReason int reason,
7317 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7319 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007320 // If the caller only has carrier privileges, then they should not be able to override
7321 // any network types which were set for security reasons.
7322 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7323 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007324 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007325 throw new SecurityException(
7326 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007327 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007328 }
joonhunshin4ac60942023-11-15 15:23:39 +00007329
7330 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7331 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7332
SongFerngWang3ef3e072020-12-21 16:41:52 +08007333 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007334 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007335 return false;
7336 }
7337 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7338 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007339 return false;
7340 }
7341
Jack Yu5b494332023-01-23 18:18:04 +00007342 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7343 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007344
Jack Yue37dd262022-12-16 11:53:37 -08007345 Phone phone = getPhone(subId);
7346 if (phone == null) {
7347 return false;
7348 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007349
Jack Yue37dd262022-12-16 11:53:37 -08007350 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007351 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007352 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007353 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007354
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007355 final long identity = Binder.clearCallingIdentity();
7356 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007357 Boolean success = (Boolean) sendRequest(
7358 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7359 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7360
7361 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7362 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007363 } finally {
7364 Binder.restoreCallingIdentity(identity);
7365 }
7366 }
7367
7368 /**
Miaoa84611c2019-03-15 09:21:10 +08007369 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007370 *
Miaoa84611c2019-03-15 09:21:10 +08007371 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007372 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007373 * @hide
7374 */
7375 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007376 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007377 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007378
7379 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7380 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007383 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384 try {
Miaoa84611c2019-03-15 09:21:10 +08007385 if (phone != null) {
7386 return phone.hasMatchedTetherApnSetting();
7387 } else {
7388 return false;
7389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 } finally {
7391 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007392 }
Junda Liu475951f2014-11-07 16:45:03 -08007393 }
7394
7395 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007396 * Get the user enabled state of Mobile Data.
7397 *
7398 * TODO: remove and use isUserDataEnabled.
7399 * This can't be removed now because some vendor codes
7400 * calls through ITelephony directly while they should
7401 * use TelephonyManager.
7402 *
7403 * @return true on enabled
7404 */
7405 @Override
7406 public boolean getDataEnabled(int subId) {
7407 return isUserDataEnabled(subId);
7408 }
7409
7410 /**
7411 * Get whether mobile data is enabled per user setting.
7412 *
7413 * There are other factors deciding whether mobile data is actually enabled, but they are
7414 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007415 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007416 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7417 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007418 *
7419 * @return {@code true} if data is enabled else {@code false}
7420 */
7421 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007422 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007423 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007424 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007425 try {
7426 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7427 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007428 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007429 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7430 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007431 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007433 mApp, subId, functionName);
7434
Robert Greenwalt646120a2014-05-23 11:54:03 -07007435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436
7437 final long identity = Binder.clearCallingIdentity();
7438 try {
Jack Yu285100e2022-12-02 22:48:35 -08007439 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7441 Phone phone = PhoneFactory.getPhone(phoneId);
7442 if (phone != null) {
7443 boolean retVal = phone.isUserDataEnabled();
7444 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7445 return retVal;
7446 } else {
7447 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7448 return false;
7449 }
7450 } finally {
7451 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007452 }
7453 }
7454
7455 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007456 * Checks if the device is capable of mobile data by considering whether whether the
7457 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7458 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007459 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007460 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007461 */
7462 @Override
7463 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007464 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007465 try {
7466 try {
7467 mApp.enforceCallingOrSelfPermission(
7468 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007469 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007470 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007471 try {
7472 mApp.enforceCallingOrSelfPermission(
7473 android.Manifest.permission.READ_PHONE_STATE,
7474 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007475 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007476 mApp.enforceCallingOrSelfPermission(
7477 permission.READ_BASIC_PHONE_STATE, functionName);
7478 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007479 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007480 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007481 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483
joonhunshin4ac60942023-11-15 15:23:39 +00007484 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7485 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 final long identity = Binder.clearCallingIdentity();
7488 try {
Jack Yu285100e2022-12-02 22:48:35 -08007489 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 Phone phone = PhoneFactory.getPhone(phoneId);
7491 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007492 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007493 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 return retVal;
7495 } else {
7496 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7497 return false;
7498 }
7499 } finally {
7500 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007501 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007502 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007503
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007504 /**
7505 * Check if data is enabled for a specific reason
7506 * @param subId Subscription index
7507 * @param reason the reason the data enable change is taking place
7508 * @return {@code true} if the overall data is enabled; {@code false} if not.
7509 */
7510 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007511 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007512 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007513 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007514 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007515 try {
7516 mApp.enforceCallingOrSelfPermission(
7517 android.Manifest.permission.ACCESS_NETWORK_STATE,
7518 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007519 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007520 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7521 functionName);
7522 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007523 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007524 try {
7525 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007526 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007527 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007529 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007530 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007531 }
7532
joonhunshin4ac60942023-11-15 15:23:39 +00007533 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7534 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007535
7536 final long identity = Binder.clearCallingIdentity();
7537 try {
Jack Yu285100e2022-12-02 22:48:35 -08007538 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007539 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007540 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007541 + " reason=" + reason);
7542 }
7543 Phone phone = PhoneFactory.getPhone(phoneId);
7544 if (phone != null) {
7545 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007546 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007547 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007548 return retVal;
7549 } else {
7550 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007551 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007552 + subId + " retVal=false");
7553 }
7554 return false;
7555 }
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
7558 }
7559 }
7560
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007561 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007562 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007563 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7564 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7565
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007566 // No permission needed; this only lets the caller inspect their own status.
7567 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007568 }
Junda Liu29340342014-07-10 15:23:27 -07007569
7570 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007571 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007572 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007573
7574 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7575 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7576
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007577 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7578 }
7579
7580 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7581 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007582 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007583 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007584 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7585 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007586 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7587 if (cpt == null) {
7588 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007589 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7590 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007591 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007592 }
7593
7594 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007595 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007596 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007597
7598 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7599 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7600
chen xuf7e9fe82019-05-09 19:31:02 -07007601 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007602 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007603 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007604 Phone phone = getPhone(subId);
7605 if (phone == null) {
7606 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7607 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7608 }
7609 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7610 if (cpt == null) {
7611 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007612 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7613 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007614 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007615 }
7616
7617 @Override
7618 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007619 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007620
7621 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7622 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7623 "checkCarrierPrivilegesForPackageAnyPhone");
7624
Rambo Wange7209ce2022-02-23 13:41:02 -08007625 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7626 }
7627
7628 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007629 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007630 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007631 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007632 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007633 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7634 Phone phone = PhoneFactory.getPhone(phoneId);
7635 if (phone == null) {
7636 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007637 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007638 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7639 if (cpt == null) {
7640 continue;
7641 }
7642 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007643 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7644 break;
7645 }
7646 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007647 return result;
Junda Liu29340342014-07-10 15:23:27 -07007648 }
Derek Tan89e89d42014-07-08 17:00:10 -07007649
7650 @Override
Junda Liue64de782015-04-16 17:19:16 -07007651 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007652 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007653
7654 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7655 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7656 "getCarrierPackageNamesForIntentAndPhone");
7657
Rambo Wang8a247eb2022-02-08 21:11:18 +00007658 Phone phone = PhoneFactory.getPhone(phoneId);
7659 if (phone == null) {
7660 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007661 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007662 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7663 if (cpt == null) {
7664 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007665 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007666 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007667 }
7668
Amith Yamasani6e118872016-02-19 12:53:51 -08007669 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007670 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007671 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007672 Phone phone = PhoneFactory.getPhone(phoneId);
7673 if (phone == null) {
7674 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007675 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007676 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7677 if (cpt == null) {
7678 return Collections.emptyList();
7679 }
7680 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007681 }
7682
chen xuf7e9fe82019-05-09 19:31:02 -07007683 @Override
7684 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007685 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007686
7687 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7688 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7689 "getPackagesWithCarrierPrivilegesForAllPhones");
7690
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007691 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007692 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007693 try {
7694 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7695 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7696 }
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007699 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007700 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007701 }
7702
Rambo Wang6812ffb2022-03-15 16:54:17 -07007703 @Override
7704 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7705 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7706
joonhunshin4ac60942023-11-15 15:23:39 +00007707 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7708 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7709 "getCarrierServicePackageNameForLogicalSlot");
7710
Rambo Wang6812ffb2022-03-15 16:54:17 -07007711 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7712 if (phone == null) {
7713 return null;
7714 }
7715 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7716 if (cpt == null) {
7717 return null;
7718 }
7719 return cpt.getCarrierServicePackageName();
7720 }
7721
Wink Savilleb564aae2014-10-23 10:18:09 -07007722 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007723 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007724 UiccPort port = phone == null ? null : phone.getUiccPort();
7725 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007726 return null;
7727 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007728 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007729 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007730 return null;
7731 }
7732 return iccId;
7733 }
7734
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007735 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007736 public void setCallComposerStatus(int subId, int status) {
7737 enforceModifyPermission();
7738
joonhunshin4ac60942023-11-15 15:23:39 +00007739 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7740 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7741
Shuo Qiane4e11672020-12-15 22:15:33 -08007742 final long identity = Binder.clearCallingIdentity();
7743 try {
7744 Phone phone = getPhone(subId);
7745 if (phone != null) {
7746 Phone defaultPhone = phone.getImsPhone();
7747 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7748 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7749 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007750 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7751 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007752 }
7753 }
Shuo Qian284ae752020-12-22 19:10:14 -08007754 } catch (ImsException e) {
7755 throw new ServiceSpecificException(e.getCode());
7756 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007757 Binder.restoreCallingIdentity(identity);
7758 }
7759 }
7760
7761 @Override
7762 public int getCallComposerStatus(int subId) {
7763 enforceReadPrivilegedPermission("getCallComposerStatus");
7764
joonhunshin4ac60942023-11-15 15:23:39 +00007765 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7766 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7767
Shuo Qiane4e11672020-12-15 22:15:33 -08007768 final long identity = Binder.clearCallingIdentity();
7769 try {
7770 Phone phone = getPhone(subId);
7771 if (phone != null) {
7772 Phone defaultPhone = phone.getImsPhone();
7773 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7774 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7775 return imsPhone.getCallComposerStatus();
7776 }
7777 }
7778 } finally {
7779 Binder.restoreCallingIdentity(identity);
7780 }
7781 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7782 }
7783
7784 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007785 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7786 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007787 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007788 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007789
joonhunshin4ac60942023-11-15 15:23:39 +00007790 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7791 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7792 "setLine1NumberForDisplayForSubscriber");
7793
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 final long identity = Binder.clearCallingIdentity();
7795 try {
7796 final String iccId = getIccId(subId);
7797 final Phone phone = getPhone(subId);
7798 if (phone == null) {
7799 return false;
7800 }
7801 final String subscriberId = phone.getSubscriberId();
7802
7803 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007804 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805 + subscriberId + " to " + number);
7806 }
7807
7808 if (TextUtils.isEmpty(iccId)) {
7809 return false;
7810 }
7811
7812 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7813
7814 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7815 if (alphaTag == null) {
7816 editor.remove(alphaTagPrefKey);
7817 } else {
7818 editor.putString(alphaTagPrefKey, alphaTag);
7819 }
7820
7821 // Record both the line number and IMSI for this ICCID, since we need to
7822 // track all merged IMSIs based on line number
7823 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7824 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7825 if (number == null) {
7826 editor.remove(numberPrefKey);
7827 editor.remove(subscriberPrefKey);
7828 } else {
7829 editor.putString(numberPrefKey, number);
7830 editor.putString(subscriberPrefKey, subscriberId);
7831 }
7832
7833 editor.commit();
7834 return true;
7835 } finally {
7836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007837 }
Derek Tan7226c842014-07-02 17:42:23 -07007838 }
7839
7840 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007841 public String getLine1NumberForDisplay(int subId, String callingPackage,
7842 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007843 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007845 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007846 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007847 return null;
7848 }
Derek Tan97ebb422014-09-05 16:55:38 -07007849
joonhunshin4ac60942023-11-15 15:23:39 +00007850 enforceTelephonyFeatureWithException(callingPackage,
7851 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 final long identity = Binder.clearCallingIdentity();
7854 try {
7855 String iccId = getIccId(subId);
7856 if (iccId != null) {
7857 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7858 if (DBG_MERGE) {
7859 log("getLine1NumberForDisplay returning "
7860 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7861 }
7862 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007863 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7865 return null;
7866 } finally {
7867 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007868 }
Derek Tan7226c842014-07-02 17:42:23 -07007869 }
7870
7871 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007872 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7873 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007875 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007876 return null;
7877 }
Derek Tan97ebb422014-09-05 16:55:38 -07007878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007879 final long identity = Binder.clearCallingIdentity();
7880 try {
7881 String iccId = getIccId(subId);
7882 if (iccId != null) {
7883 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7884 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7885 }
7886 return null;
7887 } finally {
7888 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007889 }
Derek Tan7226c842014-07-02 17:42:23 -07007890 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007891
7892 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007893 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7894 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007895 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7896 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007898 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007899 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007900 return null;
7901 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007902
Jordan Liub49b04b2019-05-06 14:45:15 -07007903 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7904 // the process, where TelephonyManager was instantiated.
7905 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007906 final long identity = Binder.clearCallingIdentity();
7907 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007908 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007909 final TelephonyManager tele = TelephonyManager.from(context);
7910 final SubscriptionManager sub = SubscriptionManager.from(context);
7911
7912 // Figure out what subscribers are currently active
7913 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914
Jordan Liub49b04b2019-05-06 14:45:15 -07007915 // Only consider subs which match the current subId
7916 // This logic can be simplified. See b/131189269 for progress.
7917 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007918 activeSubscriberIds.add(tele.getSubscriberId(subId));
7919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920
7921 // First pass, find a number override for an active subscriber
7922 String mergeNumber = null;
7923 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7924 for (String key : prefs.keySet()) {
7925 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7926 final String subscriberId = (String) prefs.get(key);
7927 if (activeSubscriberIds.contains(subscriberId)) {
7928 final String iccId = key.substring(
7929 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7930 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7931 mergeNumber = (String) prefs.get(numberKey);
7932 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007933 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007934 + " for active subscriber " + subscriberId);
7935 }
7936 if (!TextUtils.isEmpty(mergeNumber)) {
7937 break;
7938 }
7939 }
7940 }
7941 }
7942
7943 // Shortcut when no active merged subscribers
7944 if (TextUtils.isEmpty(mergeNumber)) {
7945 return null;
7946 }
7947
7948 // Second pass, find all subscribers under that line override
7949 final ArraySet<String> result = new ArraySet<>();
7950 for (String key : prefs.keySet()) {
7951 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7952 final String number = (String) prefs.get(key);
7953 if (mergeNumber.equals(number)) {
7954 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7955 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7956 final String subscriberId = (String) prefs.get(subscriberKey);
7957 if (!TextUtils.isEmpty(subscriberId)) {
7958 result.add(subscriberId);
7959 }
7960 }
7961 }
7962 }
7963
7964 final String[] resultArray = result.toArray(new String[result.size()]);
7965 Arrays.sort(resultArray);
7966 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007967 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7969 }
7970 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007971 } finally {
7972 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007973 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007974 }
7975
7976 @Override
zoey chen38003472019-12-13 17:16:31 +08007977 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7978 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007979
joonhunshin4ac60942023-11-15 15:23:39 +00007980 enforceTelephonyFeatureWithException(callingPackage,
7981 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7982
Malcolm Chen6ca97372019-07-01 16:28:21 -07007983 final long identity = Binder.clearCallingIdentity();
7984 try {
7985 final TelephonyManager telephonyManager = mApp.getSystemService(
7986 TelephonyManager.class);
7987 String subscriberId = telephonyManager.getSubscriberId(subId);
7988 if (subscriberId == null) {
7989 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007990 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007991 + subId);
7992 }
7993 return null;
7994 }
7995
Jack Yu3beaf9d2023-04-14 09:17:27 -07007996 final SubscriptionInfo info = getSubscriptionManagerService()
7997 .getSubscriptionInfo(subId);
7998 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07007999 // If it doesn't belong to any group, return just subscriberId of itself.
8000 if (groupUuid == null) {
8001 return new String[]{subscriberId};
8002 }
8003
8004 // Get all subscriberIds from the group.
8005 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008006 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8007 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8008 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008009 for (SubscriptionInfo subInfo : groupInfos) {
8010 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8011 if (subscriberId != null) {
8012 mergedSubscriberIds.add(subscriberId);
8013 }
8014 }
8015
8016 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8017 } finally {
8018 Binder.restoreCallingIdentity(identity);
8019
8020 }
8021 }
8022
8023 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008024 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008025 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008026 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008027
joonhunshin4ac60942023-11-15 15:23:39 +00008028 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8029 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8030
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008031 final long identity = Binder.clearCallingIdentity();
8032 try {
8033 final Phone phone = getPhone(subId);
8034 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8035 } finally {
8036 Binder.restoreCallingIdentity(identity);
8037 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008038 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008039
8040 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008041 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008042 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8043 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008044 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8045 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008046
8047 final long identity = Binder.clearCallingIdentity();
8048 try {
8049 final Phone phone = getPhone(subId);
8050 if (phone == null) {
8051 return false;
8052 }
8053 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8054 cdmaNonRoamingList);
8055 } finally {
8056 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008057 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008058 }
8059
8060 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008061 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008062 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008063 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008064 if (phone == null) {
8065 return raf;
8066 }
8067
Shuo Qiandee53402020-05-29 14:08:15 -07008068 try {
8069 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008070 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008071 mApp, phone.getSubId(), "getRadioAccessFamily");
8072 } catch (SecurityException e) {
8073 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8074 throw e;
8075 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008076
joonhunshin4ac60942023-11-15 15:23:39 +00008077 enforceTelephonyFeatureWithException(callingPackage,
8078 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008080 final long identity = Binder.clearCallingIdentity();
8081 try {
chen xub97461a2018-10-26 14:17:57 -07008082 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 } finally {
8084 Binder.restoreCallingIdentity(identity);
8085 }
chen xub97461a2018-10-26 14:17:57 -07008086 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008087 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008088
8089 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008090 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008091 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008092 try {
8093 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8094 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008095 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008096 }
8097 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008098 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008099 }
joonhunshin4ac60942023-11-15 15:23:39 +00008100
8101 enforceTelephonyFeatureWithException(callingPackage,
8102 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8103
Hall Liu82694d52020-12-11 18:22:04 -08008104 RoleManager rm = mApp.getSystemService(RoleManager.class);
8105 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8106 if (!dialerRoleHolders.contains(callingPackage)) {
8107 throw new SecurityException("App must be the dialer role holder to"
8108 + " upload a call composer pic");
8109 }
8110
8111 Executors.newSingleThreadExecutor().execute(() -> {
8112 ByteArrayOutputStream output = new ByteArrayOutputStream(
8113 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8114 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8115 boolean readUntilEnd = false;
8116 int totalBytesRead = 0;
8117 byte[] buffer = new byte[16 * 1024];
8118 while (true) {
8119 int numRead;
8120 try {
8121 numRead = input.read(buffer);
8122 } catch (IOException e) {
8123 try {
8124 fd.checkError();
8125 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8126 null);
8127 } catch (IOException e1) {
8128 // This means that the other side closed explicitly with an error. If this
8129 // happens, log and ignore.
8130 loge("Remote end of call composer picture pipe closed: " + e1);
8131 }
8132 break;
8133 }
8134 if (numRead == -1) {
8135 readUntilEnd = true;
8136 break;
8137 }
8138 totalBytesRead += numRead;
8139 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8140 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8141 try {
8142 input.close();
8143 } catch (IOException e) {
8144 // ignore
8145 }
8146 break;
8147 }
8148 output.write(buffer, 0, numRead);
8149 }
8150 // Generally, the remote end will close the file descriptors. The only case where we
8151 // close is above, where the picture size is too big.
8152
8153 try {
8154 fd.checkError();
8155 } catch (IOException e) {
8156 loge("Remote end for call composer closed with an error: " + e);
8157 return;
8158 }
8159
Hall Liuaa4211e2021-01-20 15:43:39 -08008160 if (!readUntilEnd) {
8161 loge("Did not finish reading entire image; aborting");
8162 return;
8163 }
Hall Liu82694d52020-12-11 18:22:04 -08008164
Hall Liuaa4211e2021-01-20 15:43:39 -08008165 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8166 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8167 new CallComposerPictureTransfer.Factory() {},
8168 imageData,
8169 (result) -> {
8170 if (result.first != null) {
8171 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8172 Bundle outputResult = new Bundle();
8173 outputResult.putParcelable(
8174 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8175 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8176 outputResult);
8177 } else {
8178 callback.send(result.second, null);
8179 }
8180 }
8181 );
Hall Liu82694d52020-12-11 18:22:04 -08008182 });
8183 }
8184
8185 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008186 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008187 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008188 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189
joonhunshin4ac60942023-11-15 15:23:39 +00008190 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8191 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008193 final long identity = Binder.clearCallingIdentity();
8194 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008195 ImsManager.getInstance(defaultPhone.getContext(),
8196 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008197 } finally {
8198 Binder.restoreCallingIdentity(identity);
8199 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008200 }
8201
8202 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008203 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008204 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008205 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8206 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008207 return false;
8208 }
Svet Ganovb320e182015-04-16 12:30:10 -07008209
joonhunshin4ac60942023-11-15 15:23:39 +00008210 enforceTelephonyFeatureWithException(callingPackage,
8211 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008213 final long identity = Binder.clearCallingIdentity();
8214 try {
8215 // Check the user preference and the system-level IMS setting. Even if the user has
8216 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8217 // In the long run, we may instead need to check if there exists a connection service
8218 // which can support video calling.
8219 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008220 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 return imsManager.isVtEnabledByPlatform()
8222 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8223 && imsManager.isVtEnabledByUser();
8224 } finally {
8225 Binder.restoreCallingIdentity(identity);
8226 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008227 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008228
Andrew Leea1239f22015-03-02 17:44:07 -08008229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008230 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8231 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008233 mApp, subId, callingPackage, callingFeatureId,
8234 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235 return false;
8236 }
8237
joonhunshin4ac60942023-11-15 15:23:39 +00008238 enforceTelephonyFeatureWithException(callingPackage,
8239 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 final long identity = Binder.clearCallingIdentity();
8242 try {
8243 CarrierConfigManager configManager =
8244 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008245 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008246 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8247 } finally {
8248 Binder.restoreCallingIdentity(identity);
8249 }
Andrew Leea1239f22015-03-02 17:44:07 -08008250 }
8251
8252 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008253 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008255 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256 return false;
8257 }
8258
joonhunshin4ac60942023-11-15 15:23:39 +00008259 enforceTelephonyFeatureWithException(callingPackage,
8260 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008262 final long identity = Binder.clearCallingIdentity();
8263 try {
8264 CarrierConfigManager configManager =
8265 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008266 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008267 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8268 } finally {
8269 Binder.restoreCallingIdentity(identity);
8270 }
Andrew Leea1239f22015-03-02 17:44:07 -08008271 }
8272
Andrew Lee9431b832015-03-09 18:46:45 -07008273 @Override
8274 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008275 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008276 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008277 }
8278
8279 @Override
8280 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008281 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8282 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008284 final long identity = Binder.clearCallingIdentity();
8285 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008286 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287 } finally {
8288 Binder.restoreCallingIdentity(identity);
8289 }
Andrew Lee9431b832015-03-09 18:46:45 -07008290 }
8291
Hall Liuf6668912018-10-31 17:05:23 -07008292 /**
8293 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8294 * support for the feature and device firmware support.
8295 *
8296 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8297 */
8298 @Override
8299 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008300 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8301 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008304 final Phone phone = getPhone(subscriptionId);
8305 if (phone == null) {
8306 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8307 return false;
8308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008310 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008312 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8313 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8314 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315 return isCarrierSupported && isDeviceSupported;
8316 } finally {
8317 Binder.restoreCallingIdentity(identity);
8318 }
Hall Liu98187582018-01-22 19:15:32 -08008319 }
8320
Hall Liuf6668912018-10-31 17:05:23 -07008321 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008322 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8323 * RTT setting, will return true if the device and carrier both support RTT.
8324 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008325 */
8326 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327 final long identity = Binder.clearCallingIdentity();
8328 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008329 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8330 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8331 return false;
8332 }
8333 }
8334
Hall Liu5bab75c2019-12-11 23:58:20 +00008335 boolean isRttSupported = isRttSupported(subscriptionId);
8336 boolean isUserRttSettingOn = Settings.Secure.getInt(
8337 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8338 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8339 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8340 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 } finally {
8342 Binder.restoreCallingIdentity(identity);
8343 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008344 }
8345
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008346 @Deprecated
8347 @Override
8348 public String getDeviceId(String callingPackage) {
8349 return getDeviceIdWithFeature(callingPackage, null);
8350 }
8351
Sanket Padawe7310cc72015-01-14 09:53:20 -08008352 /**
8353 * Returns the unique device ID of phone, for example, the IMEI for
8354 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8355 *
8356 * <p>Requires Permission:
8357 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8358 */
8359 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008360 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008361 try {
8362 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8363 } catch (SecurityException se) {
8364 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8365 throw new SecurityException("Package " + callingPackage + " does not belong to "
8366 + Binder.getCallingUid());
8367 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008368 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008369 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008370 return null;
8371 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008372 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008373 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008374 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008375 return null;
8376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008377
8378 final long identity = Binder.clearCallingIdentity();
8379 try {
8380 return phone.getDeviceId();
8381 } finally {
8382 Binder.restoreCallingIdentity(identity);
8383 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008384 }
8385
Ping Sunc67b7c22016-03-02 19:16:45 +08008386 /**
8387 * {@hide}
8388 * Returns the IMS Registration Status on a particular subid
8389 *
8390 * @param subId
8391 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008392 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008393 Phone phone = getPhone(subId);
8394 if (phone != null) {
8395 return phone.isImsRegistered();
8396 } else {
8397 return false;
8398 }
8399 }
8400
Santos Cordon7a1885b2015-02-03 11:15:19 -08008401 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008402 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008403 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008405 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008406 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8407 }
8408 final long identity = Binder.clearCallingIdentity();
8409 try {
8410 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8411 } finally {
8412 Binder.restoreCallingIdentity(identity);
8413 }
8414 }
8415
8416 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008417 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008418 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008419 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008420 mApp,
8421 subscriptionId,
8422 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8423 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008424
8425 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8426 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8427
Tyler Gunnf70ed162019-04-03 15:28:53 -07008428 final long identity = Binder.clearCallingIdentity();
8429 try {
8430 Phone phone = getPhone(subscriptionId);
8431 if (phone == null) {
8432 return null;
8433 }
8434 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8435 } finally {
8436 Binder.restoreCallingIdentity(identity);
8437 }
8438 }
8439
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008440 /**
8441 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008442 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008443 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008444 final long identity = Binder.clearCallingIdentity();
8445 try {
8446 Phone phone = getPhone(subId);
8447 if (phone != null) {
8448 return phone.isWifiCallingEnabled();
8449 } else {
8450 return false;
8451 }
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008454 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008455 }
8456
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008457 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008458 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008459 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008460 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461 final long identity = Binder.clearCallingIdentity();
8462 try {
8463 Phone phone = getPhone(subId);
8464 if (phone != null) {
8465 return phone.isVideoEnabled();
8466 } else {
8467 return false;
8468 }
8469 } finally {
8470 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008471 }
8472 }
8473
8474 /**
8475 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8476 * defined in {@link ImsRegistrationImplBase}.
8477 */
8478 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008479 final long identity = Binder.clearCallingIdentity();
8480 try {
8481 Phone phone = getPhone(subId);
8482 if (phone != null) {
8483 return phone.getImsRegistrationTech();
8484 } else {
8485 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8486 }
8487 } finally {
8488 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008489 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008490 }
8491
Stuart Scott8eef64f2015-04-08 15:13:54 -07008492 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008493 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008494 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008495
8496 enforceTelephonyFeatureWithException(callingPackage,
8497 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8498
Stuart Scott981d8582015-04-21 14:09:50 -07008499 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8500 return;
8501 }
Kai Shif70f46f2021-03-03 13:59:46 -08008502 Phone defaultPhone = getDefaultPhone();
8503 if (defaultPhone != null) {
8504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8505 mApp, getDefaultPhone().getSubId(), "factoryReset");
8506 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008507 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008508
Svet Ganovcc087f82015-05-12 20:35:54 -07008509 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008510 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8511 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008512 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008513 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008514 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008515 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008516 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008517 setDataRoamingEnabled(subId, phone == null ? false
8518 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008519 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008520 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008521 // There has been issues when Sms raw table somehow stores orphan
8522 // fragments. They lead to garbled message when new fragments come
8523 // in and combined with those stale ones. In case this happens again,
8524 // user can reset all network settings which will clean up this table.
8525 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008526 // Clean up IMS settings as well here.
8527 int slotId = getSlotIndex(subId);
8528 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8529 ImsManager.getInstance(mApp, slotId).factoryReset();
8530 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008531
Kai Shif70f46f2021-03-03 13:59:46 -08008532 if (defaultPhone == null) {
8533 return;
8534 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008535 // Erase modem config if erase modem on network setting is enabled.
8536 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8537 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8538 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008539 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008540 }
Kai Shif70f46f2021-03-03 13:59:46 -08008541
8542 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008543 } finally {
8544 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008545 }
8546 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008547
SongFerngWangfd89b102021-05-27 22:44:54 +08008548 @VisibleForTesting
8549 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8550 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8551 return;
8552 }
8553 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8554 RILConstants.PREFERRED_NETWORK_MODE);
8555 SubscriptionManager.setSubscriptionProperty(subId,
8556 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8557 "user=" + defaultNetworkType);
8558 phone.loadAllowedNetworksFromSubscriptionDatabase();
8559 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8560 defaultNetworkType, null);
8561 }
8562
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008563 private void cleanUpSmsRawTable(Context context) {
8564 ContentResolver resolver = context.getContentResolver();
8565 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8566 resolver.delete(uri, null, null);
8567 }
8568
Narayan Kamath1c496c22015-04-16 14:40:19 +01008569 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008570 public String getSimLocaleForSubscriber(int subId) {
8571 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008572
8573 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8574 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8575
chen xu5d3637b2019-01-21 23:31:38 -08008576 final Phone phone = getPhone(subId);
8577 if (phone == null) {
8578 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008579 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008580 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008581 final long identity = Binder.clearCallingIdentity();
8582 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008583 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8584 phone.getContext().getOpPackageName(),
8585 phone.getContext().getAttributionTag());
8586 if (info == null) {
8587 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8588 return null;
chen xu6291c472019-02-04 12:55:53 -08008589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008590 // Try and fetch the locale from the carrier properties or from the SIM language
8591 // preferences (EF-PL and EF-LI)...
8592 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008594 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8595 if (localeFromDefaultSim != null) {
8596 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8597 if (DBG) log("Using locale from subId: " + subId + " locale: "
8598 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008599 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008600 } else {
8601 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008602 }
8603 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008605 // The SIM language preferences only store a language (e.g. fr = French), not an
8606 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8607 // the SIM and carrier preferences does not include a country we add the country
8608 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008609 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008610 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008611 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008612 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008613 }
8614
8615 if (DBG) log("No locale found - returning null");
8616 return null;
8617 } finally {
8618 Binder.restoreCallingIdentity(identity);
8619 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008620 }
8621
tom hsu0b59d292022-09-29 23:49:21 +08008622 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008623 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008624 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008625 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008626 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008627 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8628 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008629 Locale.forLanguageTag(localeTag).getCountry())) {
8630 return localeTag;
8631 }
8632 }
8633 return inputLocale.toLanguageTag();
8634 }
8635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008636 /**
8637 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8638 */
8639 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008640 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008641 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008642 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008643
Gary Jian3aa9a762022-01-24 16:41:19 +08008644 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8645 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008646
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008647 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008648 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8649 * representing the state of the modem.
8650 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008651 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8652 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008653 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008654 */
8655 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008656 public void requestModemActivityInfo(ResultReceiver result) {
8657 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008658
8659 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8660 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8661
vagdeviaf9a5b92018-08-15 16:01:53 -07008662 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008663
8664 final long identity = Binder.clearCallingIdentity();
8665 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008666 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008667 } finally {
8668 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008669 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008670 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008671
Gary Jian76280a42022-12-07 16:18:33 +08008672 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008673 // less than total activity duration.
8674 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8675 if (info == null) {
8676 return false;
8677 }
8678 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008679 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008680 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8681
Hall Liu49656c02020-10-09 19:00:11 -07008682 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8683
Siddharth Rayb8114062018-06-17 15:02:38 -07008684 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008685 && (info.getSleepTimeMillis() <= activityDurationMs)
8686 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008687 }
8688
Gary Jian3aa9a762022-01-24 16:41:19 +08008689 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8690 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8691 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8692 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8693
8694 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8695 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8696 }
8697
8698 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8699 mLastModemActivityInfo.setReceiveTimeMillis(
8700 rat,
8701 freq,
8702 info.getReceiveTimeMillis(rat, freq)
8703 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8704 }
8705
8706 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8707 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8708 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8709 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8710
8711 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8712 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8713 }
8714 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8715 mLastModemActivityInfo.setReceiveTimeMillis(
8716 rat,
8717 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8718 }
8719
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008720 /**
8721 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8722 * @param info recent ModemActivityInfo
8723 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008724 private void mergeModemActivityInfo(ModemActivityInfo info) {
8725 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008726 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008727 boolean matched;
8728 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8729 matched = false;
8730 int rat = info.getSpecificInfoRat(i);
8731 int freq = info.getSpecificInfoFrequencyRange(i);
8732 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8733 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8734 //if it already exists
8735 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8736 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8737 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8738 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8739 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8740 updateLastModemActivityInfo(info, rat, freq);
8741 matched = true;
8742 }
8743 } else {
8744 updateLastModemActivityInfo(info, rat);
8745 matched = true;
8746 }
8747 }
8748 }
8749
8750 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008751 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008752 new ActivityStatsTechSpecificInfo(
8753 rat,
8754 freq,
8755 info.getTransmitTimeMillis(rat, freq),
8756 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008757 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008758 }
8759 }
8760 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8761 mLastModemActivitySpecificInfo =
8762 new ActivityStatsTechSpecificInfo[merged.size()];
8763 merged.toArray(mLastModemActivitySpecificInfo);
8764
8765 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8766 mLastModemActivityInfo.setSleepTimeMillis(
8767 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008768 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008769 mLastModemActivityInfo.setIdleTimeMillis(
8770 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008771 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008772
8773 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008774 new ModemActivityInfo(
8775 mLastModemActivityInfo.getTimestampMillis(),
8776 mLastModemActivityInfo.getSleepTimeMillis(),
8777 mLastModemActivityInfo.getIdleTimeMillis(),
8778 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008779 }
8780
8781 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8782 ActivityStatsTechSpecificInfo[] info) {
8783 int infoSize = info.length;
8784 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8785 for (int i = 0; i < infoSize; i++) {
8786 ret[i] = new ActivityStatsTechSpecificInfo(
8787 info[i].getRat(), info[i].getFrequencyRange(),
8788 info[i].getTransmitTimeMillis(),
8789 (int) info[i].getReceiveTimeMillis());
8790 }
8791 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008792 }
8793
Jack Yu85bd38a2015-11-09 11:34:32 -08008794 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008795 * Returns the service state information on specified subscription.
8796 */
8797 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008798 public ServiceState getServiceStateForSubscriber(int subId,
8799 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8800 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008802 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008803 return null;
8804 }
8805
joonhunshin4ac60942023-11-15 15:23:39 +00008806 enforceTelephonyFeatureWithException(callingPackage,
8807 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8808
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008809 boolean hasFinePermission = false;
8810 boolean hasCoarsePermission = false;
8811 if (!renounceFineLocationAccess) {
8812 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8813 LocationAccessPolicy.checkLocationPermission(mApp,
8814 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8815 .setCallingPackage(callingPackage)
8816 .setCallingFeatureId(callingFeatureId)
8817 .setCallingPid(Binder.getCallingPid())
8818 .setCallingUid(Binder.getCallingUid())
8819 .setMethod("getServiceStateForSubscriber")
8820 .setLogAsInfo(true)
8821 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8822 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8823 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8824 .build());
8825 hasFinePermission =
8826 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8827 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008828
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008829 if (!renounceCoarseLocationAccess) {
8830 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8831 LocationAccessPolicy.checkLocationPermission(mApp,
8832 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8833 .setCallingPackage(callingPackage)
8834 .setCallingFeatureId(callingFeatureId)
8835 .setCallingPid(Binder.getCallingPid())
8836 .setCallingUid(Binder.getCallingUid())
8837 .setMethod("getServiceStateForSubscriber")
8838 .setLogAsInfo(true)
8839 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8840 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8841 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8842 .build());
8843 hasCoarsePermission =
8844 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8845 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008846
Jack Yu479f40e2020-10-27 21:29:25 -07008847 final Phone phone = getPhone(subId);
8848 if (phone == null) {
8849 return null;
8850 }
8851
Jordan Liu0f2bc442020-11-18 16:47:37 -08008852 final long identity = Binder.clearCallingIdentity();
8853
Jack Yu479f40e2020-10-27 21:29:25 -07008854 boolean isCallingPackageDataService = phone.getDataServicePackages()
8855 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008856 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008857 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu3beaf9d2023-04-14 09:17:27 -07008858 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8859 .getSubscriptionInfoInternal(subId);
8860 if (subInfo == null || !subInfo.isActive()) {
8861 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8862 + "subId=" + subId);
8863 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008864 }
8865
Hall Liuf19c44f2018-11-27 14:38:17 -08008866 ServiceState ss = phone.getServiceState();
8867
8868 // Scrub out the location info in ServiceState depending on what level of access
8869 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008870 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008871 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8872 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008873 } finally {
8874 Binder.restoreCallingIdentity(identity);
8875 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008876 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008877
8878 /**
8879 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8880 *
8881 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8882 * voicemail ringtone.
8883 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8884 * PhoneAccount.
8885 */
8886 @Override
8887 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008888 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8889 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008891 final long identity = Binder.clearCallingIdentity();
8892 try {
8893 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8894 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008895 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008896 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008898 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8899 } finally {
8900 Binder.restoreCallingIdentity(identity);
8901 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008902 }
8903
8904 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008905 * Sets the per-account voicemail ringtone.
8906 *
8907 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8908 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8909 *
8910 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8911 * voicemail ringtone.
8912 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8913 * PhoneAccount.
8914 */
8915 @Override
8916 public void setVoicemailRingtoneUri(String callingPackage,
8917 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008918 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008919 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008920 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8921 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8923 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8924 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008926
joonhunshin4ac60942023-11-15 15:23:39 +00008927 enforceTelephonyFeatureWithException(callingPackage,
8928 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008930 final long identity = Binder.clearCallingIdentity();
8931 try {
8932 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8933 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008934 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 }
8936 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8937 } finally {
8938 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008939 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008940 }
8941
8942 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008943 * Returns whether vibration is set for voicemail notification in Phone settings.
8944 *
8945 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8946 * voicemail vibration setting.
8947 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8948 */
8949 @Override
8950 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008951 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8952 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008954 final long identity = Binder.clearCallingIdentity();
8955 try {
8956 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8957 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008958 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008959 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008961 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8962 } finally {
8963 Binder.restoreCallingIdentity(identity);
8964 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008965 }
8966
Youhan Wange64578a2016-05-02 15:32:42 -07008967 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008968 * Sets the per-account voicemail vibration.
8969 *
8970 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8971 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8972 *
8973 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8974 * voicemail vibration setting.
8975 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8976 * specific PhoneAccount.
8977 */
8978 @Override
8979 public void setVoicemailVibrationEnabled(String callingPackage,
8980 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008981 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008982 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008983 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8984 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8986 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8987 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008988 }
8989
joonhunshin4ac60942023-11-15 15:23:39 +00008990 enforceTelephonyFeatureWithException(callingPackage,
8991 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8992
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8996 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008997 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008998 }
8999 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9000 } finally {
9001 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009002 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009003 }
9004
9005 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009006 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9007 *
9008 * @throws SecurityException if the caller does not have the required permission
9009 */
arunvoddud7401012022-12-15 16:08:12 +00009010 @VisibleForTesting
9011 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009012 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009013 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009014 }
9015
9016 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009017 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9018 * permission.
9019 *
9020 * @throws SecurityException if the caller does not have the required permission
9021 */
9022 private void enforceSendSmsPermission() {
9023 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9024 }
9025
9026 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009027 * Make sure either called from same process as self (phone) or IPC caller has interact across
9028 * users permission.
9029 *
9030 * @throws SecurityException if the caller does not have the required permission
9031 */
9032 private void enforceInteractAcrossUsersPermission(String message) {
9033 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9034 }
9035
9036 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009037 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009038 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009039 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009040 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009041 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009042 final long identity = Binder.clearCallingIdentity();
9043 try {
9044 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009045 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009046 if (componentName == null) {
9047 throw new SecurityException(
9048 "Caller not current active visual voicemail package[null]");
9049 }
9050 String vvmPackage = componentName.getPackageName();
9051 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009052 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009053 }
9054 } finally {
9055 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009056 }
9057 }
9058
9059 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009060 * Return the application ID for the app type.
9061 *
9062 * @param subId the subscription ID that this request applies to.
9063 * @param appType the uicc app type.
9064 * @return Application ID for specificied app type, or null if no uicc.
9065 */
9066 @Override
9067 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009068 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009069
9070 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9071 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9072
Youhan Wange64578a2016-05-02 15:32:42 -07009073 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009074
9075 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009076 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009077 if (phone == null) {
9078 return null;
9079 }
9080 String aid = null;
9081 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009082 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009083 .getApplicationByType(appType).getAid();
9084 } catch (Exception e) {
9085 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9086 }
9087 return aid;
9088 } finally {
9089 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009090 }
Youhan Wange64578a2016-05-02 15:32:42 -07009091 }
9092
Youhan Wang4001d252016-05-11 10:29:41 -07009093 /**
9094 * Return the Electronic Serial Number.
9095 *
9096 * @param subId the subscription ID that this request applies to.
9097 * @return ESN or null if error.
9098 */
9099 @Override
9100 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009101 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009102 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009103
9104 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009105 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009106 if (phone == null) {
9107 return null;
9108 }
9109 String esn = null;
9110 try {
9111 esn = phone.getEsn();
9112 } catch (Exception e) {
9113 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9114 }
9115 return esn;
9116 } finally {
9117 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009118 }
Youhan Wang4001d252016-05-11 10:29:41 -07009119 }
9120
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009121 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009122 * Return the Preferred Roaming List Version.
9123 *
9124 * @param subId the subscription ID that this request applies to.
9125 * @return PRLVersion or null if error.
9126 */
9127 @Override
9128 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009129 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009130
9131 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9132 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9133
Youhan Wang66ad5d72016-07-18 17:56:58 -07009134 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009135
9136 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009137 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009138 if (phone == null) {
9139 return null;
9140 }
9141 String cdmaPrlVersion = null;
9142 try {
9143 cdmaPrlVersion = phone.getCdmaPrlVersion();
9144 } catch (Exception e) {
9145 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9146 }
9147 return cdmaPrlVersion;
9148 } finally {
9149 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009150 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009151 }
9152
9153 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009154 * Get snapshot of Telephony histograms
9155 * @return List of Telephony histograms
9156 * @hide
9157 */
9158 @Override
9159 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9161 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009162
9163 final long identity = Binder.clearCallingIdentity();
9164 try {
9165 return RIL.getTelephonyRILTimingHistograms();
9166 } finally {
9167 Binder.restoreCallingIdentity(identity);
9168 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009169 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009170
9171 /**
9172 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009173 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9174 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009175 * Require system privileges. In the future we may add this to carrier APIs.
9176 *
Michele Berionne482f8202018-11-27 18:57:59 -08009177 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009178 */
9179 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009180 @TelephonyManager.SetCarrierRestrictionResult
9181 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009182 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009183
9184 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9185 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9186
vagdeviaf9a5b92018-08-15 16:01:53 -07009187 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009188
Michele Berionne482f8202018-11-27 18:57:59 -08009189 if (carrierRestrictionRules == null) {
9190 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009191 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009193 final long identity = Binder.clearCallingIdentity();
9194 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009195 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009196 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009197 } finally {
9198 Binder.restoreCallingIdentity(identity);
9199 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009200 }
9201
9202 /**
9203 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009204 * Get the allowed carrier list and the excluded carrier list, including the priority between
9205 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009206 * Require system privileges. In the future we may add this to carrier APIs.
9207 *
Michele Berionne482f8202018-11-27 18:57:59 -08009208 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009209 */
9210 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009211 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009212 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009213
9214 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9215 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9216
vagdeviaf9a5b92018-08-15 16:01:53 -07009217 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009218
9219 final long identity = Binder.clearCallingIdentity();
9220 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009221 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9222 if (response instanceof CarrierRestrictionRules) {
9223 return (CarrierRestrictionRules) response;
9224 }
9225 // Response is an Exception of some kind,
9226 // which is signalled to the user as a NULL retval
9227 return null;
9228 } catch (Exception e) {
9229 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9230 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009231 } finally {
9232 Binder.restoreCallingIdentity(identity);
9233 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009234 }
9235
fionaxu59545b42016-05-25 15:53:37 -07009236 /**
arunvoddud7401012022-12-15 16:08:12 +00009237 * Fetches the carrier restriction status of the device and sends the status to the caller
9238 * through the callback.
9239 *
9240 * @param callback The callback that will be used to send the result.
9241 * @throws SecurityException if the caller does not have the required permission/privileges or
9242 * the caller is not allowlisted.
9243 */
9244 @Override
9245 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9246 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009247
9248 enforceTelephonyFeatureWithException(packageName,
9249 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9250
Steve Statia28b7cb32024-03-11 23:58:50 +00009251 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9252 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009253 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9254 throw new SecurityException("Not an authorized caller");
9255 }
9256 final long identity = Binder.clearCallingIdentity();
9257 try {
9258 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009259 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009260 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9261 } finally {
9262 Binder.restoreCallingIdentity(identity);
9263 }
9264 }
9265
arunvoddu567f2b42023-04-25 17:22:00 +00009266 @Override
9267 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9268 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9269 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9270 return allowListInfo.getShaIdList(pkgName, carrierId);
9271 }
9272
arunvoddud7401012022-12-15 16:08:12 +00009273 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009274 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009275 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009276 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009277 }
9278
9279 /**
fionaxu59545b42016-05-25 15:53:37 -07009280 * Action set from carrier signalling broadcast receivers to enable/disable radio
9281 * @param subId the subscription ID that this action applies to.
9282 * @param enabled control enable or disable radio.
9283 * {@hide}
9284 */
9285 @Override
9286 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9287 enforceModifyPermission();
9288 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009289
9290 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009291 if (phone == null) {
9292 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9293 return;
9294 }
9295 try {
9296 phone.carrierActionSetRadioEnabled(enabled);
9297 } catch (Exception e) {
9298 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009299 } finally {
9300 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009301 }
9302 }
9303
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009304 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009305 * Enable or disable Voice over NR (VoNR)
9306 * @param subId the subscription ID that this action applies to.
9307 * @param enabled enable or disable VoNR.
9308 * @return operation result.
9309 */
9310 @Override
9311 public int setVoNrEnabled(int subId, boolean enabled) {
9312 enforceModifyPermission();
9313 final Phone phone = getPhone(subId);
9314
9315 final long identity = Binder.clearCallingIdentity();
9316 if (phone == null) {
9317 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9318 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9319 }
9320
9321 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9322 try {
9323 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9324 workSource);
9325 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009326
9327 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9328 if (DBG) {
9329 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9330 }
9331 SubscriptionManager.setSubscriptionProperty(
9332 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9333 (enabled ? "1" : "0"));
9334 }
9335
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009336 return result;
9337 } finally {
9338 Binder.restoreCallingIdentity(identity);
9339 }
9340 }
9341
9342 /**
9343 * Is voice over NR enabled
9344 * @return true if VoNR is enabled else false
9345 */
9346 @Override
9347 public boolean isVoNrEnabled(int subId) {
9348 enforceReadPrivilegedPermission("isVoNrEnabled");
9349 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9350 final long identity = Binder.clearCallingIdentity();
9351 try {
9352 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9353 null, subId, workSource);
9354 if (DBG) log("isVoNrEnabled: " + isEnabled);
9355 return isEnabled;
9356 } finally {
9357 Binder.restoreCallingIdentity(identity);
9358 }
9359 }
9360
9361 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009362 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9363 * network status based on which carrier apps could apply actions accordingly,
9364 * enable/disable default url handler for example.
9365 *
9366 * @param subId the subscription ID that this action applies to.
9367 * @param report control start/stop reporting the default network status.
9368 * {@hide}
9369 */
9370 @Override
9371 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9372 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009373
9374 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9375 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9376 "carrierActionReportDefaultNetworkStatus");
9377
fionaxu8da9cb12017-05-23 15:02:46 -07009378 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009379
9380 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009381 if (phone == null) {
9382 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9383 return;
9384 }
9385 try {
9386 phone.carrierActionReportDefaultNetworkStatus(report);
9387 } catch (Exception e) {
9388 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009389 } finally {
9390 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009391 }
9392 }
9393
9394 /**
fionaxud9622282017-07-17 17:51:30 -07009395 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9396 * @param subId the subscription ID that this action applies to.
9397 * {@hide}
9398 */
9399 @Override
9400 public void carrierActionResetAll(int subId) {
9401 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009402
9403 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9404 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9405
fionaxud9622282017-07-17 17:51:30 -07009406 final Phone phone = getPhone(subId);
9407 if (phone == null) {
9408 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9409 return;
9410 }
9411 try {
9412 phone.carrierActionResetAll();
9413 } catch (Exception e) {
9414 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9415 }
9416 }
9417
9418 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009419 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9420 * bug report is being generated.
9421 */
9422 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009423 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009424 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9425 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009426 writer.println("Permission Denial: can't dump Phone from pid="
9427 + Binder.getCallingPid()
9428 + ", uid=" + Binder.getCallingUid()
9429 + "without permission "
9430 + android.Manifest.permission.DUMP);
9431 return;
9432 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009433 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009434 }
Jack Yueb89b242016-06-22 13:27:47 -07009435
Brad Ebingerdac2f002018-04-03 15:17:52 -07009436 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009437 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9438 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9439 @NonNull String[] args) {
9440 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9441 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009442 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009443 }
9444
Jack Yueb89b242016-06-22 13:27:47 -07009445 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009446 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009447 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009448 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009449 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009450 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009451 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009452 */
9453 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009454 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009455 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009456 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9457 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9458 try {
9459 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009460 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009461 } catch (SecurityException se) {
9462 enforceModifyPermission();
9463 }
9464 } else {
9465 enforceModifyPermission();
9466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009467
joonhunshin4ac60942023-11-15 15:23:39 +00009468 enforceTelephonyFeatureWithException(callingPackage,
9469 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9470
Nate Myren116695d2024-02-09 09:36:01 -08009471 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009472 final long identity = Binder.clearCallingIdentity();
9473 try {
Nate Myren116695d2024-02-09 09:36:01 -08009474 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9475 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009476 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009477 callingUid, callingPackage, null, null);
9478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009479 Phone phone = getPhone(subId);
9480 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009481 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9482 phone.carrierActionSetMeteredApnsEnabled(enabled);
9483 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009484 phone.getDataSettingsManager().setDataEnabled(
9485 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009487 }
9488 } finally {
9489 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009490 }
9491 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009492
9493 /**
9494 * Get Client request stats
9495 * @return List of Client Request Stats
9496 * @hide
9497 */
9498 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009499 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9500 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009502 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009503 return null;
9504 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009505 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009507 final long identity = Binder.clearCallingIdentity();
9508 try {
9509 if (phone != null) {
9510 return phone.getClientRequestStats();
9511 }
9512
9513 return null;
9514 } finally {
9515 Binder.restoreCallingIdentity(identity);
9516 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009517 }
9518
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009519 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009520 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009521 if (uid == Process.ROOT_UID && packageName == null) {
9522 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9523 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9524 // exception. ROOT_UID seems not to have a valid package name returned by
9525 // PackageManager, so just fake it here to avoid issues when running telephony shell
9526 // commands that plumb through the RIL as root, like so:
9527 // $ adb root
9528 // $ adb shell cmd phone ...
9529 packageName = "root";
9530 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009531 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009532 }
Jack Yueb4124c2017-02-16 15:32:43 -08009533
9534 /**
Grace Chen70990072017-03-24 17:21:30 -07009535 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009536 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009537 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009538 * @param state State of SIM (power down, power up, pass through)
9539 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9540 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9541 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009542 *
9543 **/
9544 @Override
Grace Chen70990072017-03-24 17:21:30 -07009545 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009546 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009547
9548 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9549 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9550
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009551 Phone phone = PhoneFactory.getPhone(slotIndex);
9552
vagdeviaf9a5b92018-08-15 16:01:53 -07009553 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9554
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009555 final long identity = Binder.clearCallingIdentity();
9556 try {
9557 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009558 phone.setSimPowerState(state, null, workSource);
9559 }
9560 } finally {
9561 Binder.restoreCallingIdentity(identity);
9562 }
9563 }
9564
9565 /**
9566 * Set SIM card power state.
9567 *
9568 * @param slotIndex SIM slot id.
9569 * @param state State of SIM (power down, power up, pass through)
9570 * @param callback callback to trigger after success or failure
9571 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9572 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9573 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9574 *
9575 **/
9576 @Override
9577 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9578 IIntegerConsumer callback) {
9579 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009580
9581 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9582 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9583 "setSimPowerStateForSlotWithCallback");
9584
Jordan Liu109698e2020-11-24 14:50:34 -08009585 Phone phone = PhoneFactory.getPhone(slotIndex);
9586
9587 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9588
9589 final long identity = Binder.clearCallingIdentity();
9590 try {
9591 if (phone != null) {
9592 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9593 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009594 }
9595 } finally {
9596 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009597 }
9598 }
Shuo Qiandd210312017-04-12 22:11:33 +00009599
Tyler Gunn65d45c22017-06-05 11:22:26 -07009600 private boolean isUssdApiAllowed(int subId) {
9601 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009602 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009603 if (configManager == null) {
9604 return false;
9605 }
9606 PersistableBundle pb = configManager.getConfigForSubId(subId);
9607 if (pb == null) {
9608 return false;
9609 }
9610 return pb.getBoolean(
9611 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9612 }
9613
Shuo Qiandd210312017-04-12 22:11:33 +00009614 /**
Ling Mac28f0212023-03-24 16:07:15 -07009615 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009616 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009617 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009618 */
goneil9c5f4872017-12-05 14:07:56 -08009619 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009620 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009621 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009622
9623 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9624 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009626 final long identity = Binder.clearCallingIdentity();
9627 try {
Ling Mac28f0212023-03-24 16:07:15 -07009628 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009629 } finally {
9630 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009631 }
9632 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009633
9634 /**
9635 * Get the current signal strength information for the given subscription.
9636 * Because this information is not updated when the device is in a low power state
9637 * it should not be relied-upon to be current.
9638 * @param subId Subscription index
9639 * @return the most recent cached signal strength info from the modem
9640 */
9641 @Override
9642 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009643 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9644 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009646 final long identity = Binder.clearCallingIdentity();
9647 try {
9648 Phone p = getPhone(subId);
9649 if (p == null) {
9650 return null;
9651 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009653 return p.getSignalStrength();
9654 } finally {
9655 Binder.restoreCallingIdentity(identity);
9656 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009657 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009658
Pengquan Meng77b7f132018-08-22 14:49:57 -07009659 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009660 * Get the current modem radio state for the given slot.
9661 * @param slotIndex slot index.
9662 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009663 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009664 * @return the current radio power state from the modem
9665 */
9666 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009667 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009668 Phone phone = PhoneFactory.getPhone(slotIndex);
9669 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9671 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009672 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9673 }
9674
joonhunshin4ac60942023-11-15 15:23:39 +00009675 enforceTelephonyFeatureWithException(callingPackage,
9676 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9677
Chen Xuf792fd62018-10-17 17:54:36 +00009678 final long identity = Binder.clearCallingIdentity();
9679 try {
9680 return phone.getRadioPowerState();
9681 } finally {
9682 Binder.restoreCallingIdentity(identity);
9683 }
9684 }
9685 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9686 }
9687
9688 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009689 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9690 *
9691 * <p>Requires one of the following permissions:
9692 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009693 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009694 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9695 * privileges.
9696 *
9697 * @param subId subscription id
9698 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9699 * {@code false}.
9700 */
9701 @Override
9702 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009703 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009704 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009705 try {
9706 mApp.enforceCallingOrSelfPermission(
9707 android.Manifest.permission.ACCESS_NETWORK_STATE,
9708 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009709 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009710 mApp.enforceCallingOrSelfPermission(
9711 permission.READ_BASIC_PHONE_STATE, functionName);
9712 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009713 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009714 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009715 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009716 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009717
joonhunshin4ac60942023-11-15 15:23:39 +00009718 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9719 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9720
Pengquan Menga1bb6272018-09-06 09:59:22 -07009721 boolean isEnabled = false;
9722 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009723 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009724 Phone phone = getPhone(subId);
9725 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009726 } finally {
9727 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009728 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009729 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009730 }
9731
9732
9733 /**
9734 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9735 *
9736 * <p> Requires permission:
9737 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9738 * privileges.
9739 *
9740 * @param subId subscription id
9741 * @param isEnabled {@code true} means enable, {@code false} means disable.
9742 */
9743 @Override
9744 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9746 mApp, subId, "setDataRoamingEnabled");
9747
joonhunshin4ac60942023-11-15 15:23:39 +00009748 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9749 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9750
Pengquan Menga1bb6272018-09-06 09:59:22 -07009751 final long identity = Binder.clearCallingIdentity();
9752 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009753 Phone phone = getPhone(subId);
9754 if (phone != null) {
9755 phone.setDataRoamingEnabled(isEnabled);
9756 }
9757 } finally {
9758 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009759 }
9760 }
9761
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009762 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009763 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009764 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009765 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009766 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009767
joonhunshin4ac60942023-11-15 15:23:39 +00009768 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9769 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9770
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009771 boolean isAllowed = true;
9772 final long identity = Binder.clearCallingIdentity();
9773 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009774 Phone phone = getPhone(subId);
9775 if (phone != null) {
9776 isAllowed = phone.isCspPlmnEnabled();
9777 }
9778 } finally {
9779 Binder.restoreCallingIdentity(identity);
9780 }
9781 return isAllowed;
9782 }
9783
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009784 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9785 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009786 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009787 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009788 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009789 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9790 if (phone == null) {
9791 return false;
9792 }
9793 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9794 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9795 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009796 }
9797
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009798 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009799 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009800 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009801 mApp.getSystemService(AppOpsManager.class)
9802 .checkPackage(Binder.getCallingUid(), callingPackage);
9803
Jordan Liu1e142fc2019-04-22 15:10:43 -07009804 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009805 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009806 try {
9807 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009808 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009809 } catch (SecurityException e) {
9810 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9811 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009812 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009813 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009814 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009815 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009816 }
joonhunshin4ac60942023-11-15 15:23:39 +00009817
9818 enforceTelephonyFeatureWithException(callingPackage,
9819 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9820
sandeepjsb6c87872021-09-27 15:34:44 +00009821 // checking compatibility, if calling app's target SDK is T and beyond.
9822 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9823 Binder.getCallingUid())) {
9824 isIccIdAccessRestricted = true;
9825 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009826 final long identity = Binder.clearCallingIdentity();
9827 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009828 UiccController uiccController = UiccController.getInstance();
9829 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009830 if (hasReadPermission) {
9831 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009832 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009833
9834 // Remove private info if the caller doesn't have access
9835 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9836 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009837 //setting the value after compatibility check
9838 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009839 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9840 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009841 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009842 if (card == null) {
9843 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009844 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009845 continue;
9846 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009847 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9848 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009849 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009850 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009851 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009852 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9853 for (UiccPortInfo portInfo : portInfos) {
9854 UiccPort port = uiccController.getUiccPortForSlot(
9855 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9856 if (port == null) {
9857 // assume no access if port is null
9858 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9859 continue;
9860 }
9861 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9862 uiccPortInfos.add(portInfo);
9863 } else {
9864 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9865 }
9866 }
9867 filteredInfos.add(new UiccCardInfo(
9868 cardInfo.isEuicc(),
9869 cardInfo.getCardId(),
9870 null,
9871 cardInfo.getPhysicalSlotIndex(),
9872 cardInfo.isRemovable(),
9873 cardInfo.isMultipleEnabledProfilesSupported(),
9874 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009875 }
9876 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009877 } finally {
9878 Binder.restoreCallingIdentity(identity);
9879 }
9880 }
9881
sandeepjsb6c87872021-09-27 15:34:44 +00009882 /**
9883 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9884 * generally private and require carrier privileges to view.
9885 *
9886 * @hide
9887 */
9888 @NonNull
9889 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9890 List<UiccPortInfo> portinfo = new ArrayList<>();
9891 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9892 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9893 }
9894 return new UiccCardInfo(
9895 cardInfo.isEuicc(),
9896 cardInfo.getCardId(),
9897 null,
9898 cardInfo.getPhysicalSlotIndex(),
9899 cardInfo.isRemovable(),
9900 cardInfo.isMultipleEnabledProfilesSupported(),
9901 portinfo
9902 );
9903 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009904
sandeepjsb6c87872021-09-27 15:34:44 +00009905 /**
9906 * @hide
9907 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9908 * These values are generally private and require carrier privileges to view.
9909 */
9910 @NonNull
9911 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9912 return new UiccPortInfo(
9913 UiccPortInfo.ICCID_REDACTED,
9914 portInfo.getPortIndex(),
9915 portInfo.getLogicalSlotIndex(),
9916 portInfo.isActive()
9917 );
9918 }
9919 @Override
9920 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009921 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009922 mApp.getSystemService(AppOpsManager.class)
9923 .checkPackage(Binder.getCallingUid(), callingPackage);
9924
sandeepjsb6c87872021-09-27 15:34:44 +00009925 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009926
Aman Guptaf3c90b32022-03-17 04:54:16 +00009927 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9928 // we are reading iccId which is PII data.
9929 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009930
joonhunshin4ac60942023-11-15 15:23:39 +00009931 enforceTelephonyFeatureWithException(callingPackage,
9932 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9933
sandeepjsb6c87872021-09-27 15:34:44 +00009934 // checking compatibility, if calling app's target SDK is T and beyond.
9935 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9936 Binder.getCallingUid())) {
9937 isLogicalSlotAccessRestricted = true;
9938 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009939 final long identity = Binder.clearCallingIdentity();
9940 try {
9941 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009942 if (slots == null || slots.length == 0) {
9943 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009944 return null;
9945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009946 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9947 for (int i = 0; i < slots.length; i++) {
9948 UiccSlot slot = slots[i];
9949 if (slot == null) {
9950 continue;
9951 }
9952
Jordan Liu7be7e652019-05-06 18:55:02 +00009953 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009954 UiccCard card = slot.getUiccCard();
9955 if (card != null) {
9956 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009957 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009958 cardId = slot.getEid();
9959 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009960 // If cardId is null, use iccId of default port as cardId.
9961 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009963 }
9964
Jordan Liu857451f2019-05-09 16:35:35 -07009965 if (cardId != null) {
9966 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9967 // if cardId is an EID, it's all digits so this is fine
9968 cardId = IccUtils.stripTrailingFs(cardId);
9969 }
9970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009971 int cardState = 0;
9972 switch (slot.getCardState()) {
9973 case CARDSTATE_ABSENT:
9974 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9975 break;
9976 case CARDSTATE_PRESENT:
9977 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9978 break;
9979 case CARDSTATE_ERROR:
9980 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9981 break;
9982 case CARDSTATE_RESTRICTED:
9983 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9984 break;
9985 default:
9986 break;
9987
9988 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009989 List<UiccPortInfo> portInfos = new ArrayList<>();
9990 int[] portIndexes = slot.getPortList();
9991 for (int portIdx : portIndexes) {
9992 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009993 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009994 portInfos.add(new UiccPortInfo(iccId, portIdx,
9995 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009997 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009998 slot.isEuicc(),
9999 cardId,
10000 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010001 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010002 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010003 //setting the value after compatibility check
10004 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010005 }
10006 return infos;
10007 } finally {
10008 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010009 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010010 }
10011
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010012 /* Returns null if doesn't have read permission or carrier privilege access. */
10013 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10014 boolean hasReadPermission) {
10015 String iccId = slot.getIccId(portIndex);
10016 if (hasReadPermission) { // if has read permission
10017 return iccId;
10018 } else {
10019 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10020 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10021 // if no read permission, checking carrier privilege access
10022 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10023 return iccId;
10024 }
10025 }
10026 }
10027 // No read permission or carrier privilege access.
10028 return UiccPortInfo.ICCID_REDACTED;
10029 }
10030
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010031 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010032 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010033 public boolean switchSlots(int[] physicalSlots) {
10034 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010035
joonhunshin4ac60942023-11-15 15:23:39 +000010036 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10037 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10038
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010039 final long identity = Binder.clearCallingIdentity();
10040 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010041 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10042 for (int i = 0; i < physicalSlots.length; i++) {
10043 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10044 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10045 physicalSlots[i], i));
10046 }
10047 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010048 } finally {
10049 Binder.restoreCallingIdentity(identity);
10050 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010051 }
Jack Yu4c988042018-02-27 15:30:01 -080010052
10053 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010054 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10055 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10056 enforceModifyPermission();
10057
joonhunshin4ac60942023-11-15 15:23:39 +000010058 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10059 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10060
sandeepjsb6c87872021-09-27 15:34:44 +000010061 final long identity = Binder.clearCallingIdentity();
10062 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010063 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010064 } finally {
10065 Binder.restoreCallingIdentity(identity);
10066 }
10067 }
10068
10069 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010070 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010071 enforceTelephonyFeatureWithException(callingPackage,
10072 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10073
Jordan Liu7de49fa2018-12-06 14:48:49 -080010074 final long identity = Binder.clearCallingIdentity();
10075 try {
10076 return UiccController.getInstance().getCardIdForDefaultEuicc();
10077 } finally {
10078 Binder.restoreCallingIdentity(identity);
10079 }
10080 }
10081
Pengquan Meng85728fb2018-03-12 16:31:21 -070010082 /**
goneil47ffb6e2018-04-06 15:40:58 -070010083 * A test API to reload the UICC profile.
10084 *
10085 * <p>Requires that the calling app has permission
10086 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10087 * @hide
10088 */
10089 @Override
10090 public void refreshUiccProfile(int subId) {
10091 enforceModifyPermission();
10092
10093 final long identity = Binder.clearCallingIdentity();
10094 try {
10095 Phone phone = getPhone(subId);
10096 if (phone == null) {
10097 return;
10098 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010099 UiccPort uiccPort = phone.getUiccPort();
10100 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010101 return;
10102 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010103 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010104 if (uiccProfile == null) {
10105 return;
10106 }
10107 uiccProfile.refresh();
10108 } finally {
10109 Binder.restoreCallingIdentity(identity);
10110 }
10111 }
10112
10113 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010114 * Returns false if the mobile data is disabled by default, otherwise return true.
10115 */
10116 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010117 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010118 }
10119
10120 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010121 * Returns the default network type for the given {@code subId}, if the default network type is
10122 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10123 */
10124 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010125 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010126 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010127 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10128 return list.get(phoneId);
10129 }
10130 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010131 }
fionaxua13278b2018-03-21 00:08:13 -070010132
10133 @Override
10134 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010135 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010136 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010137
10138 final long identity = Binder.clearCallingIdentity();
10139 try {
10140 final Phone phone = getPhone(subId);
10141 if (phone == null) {
10142 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10143 return;
10144 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010145 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10146 if (cpt != null) {
10147 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10148 }
10149 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010150 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10151 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010152 if (carrierPrivilegeRules == null) {
10153 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10154 } else {
10155 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10156 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010157 } finally {
10158 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010159 }
fionaxua13278b2018-03-21 00:08:13 -070010160 }
10161
10162 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010163 public void setCarrierServicePackageOverride(
10164 int subId, String carrierServicePackage, String callingPackage) {
10165 TelephonyPermissions.enforceShellOnly(
10166 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10167
Benedict Wong66477622023-02-03 23:30:57 +000010168 final long identity = Binder.clearCallingIdentity();
10169 try {
10170 final Phone phone = getPhone(subId);
10171 if (phone == null || phone.getSubId() != subId) {
10172 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10173 throw new IllegalArgumentException("No phone for subid");
10174 }
10175 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10176 if (cpt == null) {
10177 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10178 throw new IllegalStateException("No CPT for phone");
10179 }
10180 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10181 } finally {
10182 Binder.restoreCallingIdentity(identity);
10183 }
10184 }
10185
10186 @Override
fionaxua13278b2018-03-21 00:08:13 -070010187 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010188 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010189
10190 final long identity = Binder.clearCallingIdentity();
10191 try {
10192 final Phone phone = getPhone(subId);
10193 if (phone == null) {
10194 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10195 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10196 }
10197 return phone.getCarrierIdListVersion();
10198 } finally {
10199 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010200 }
fionaxua13278b2018-03-21 00:08:13 -070010201 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010202
10203 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010204 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10205 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010207 mApp, subId, callingPackage, callingFeatureId,
10208 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010209 return -1;
10210 }
10211
10212 final long identity = Binder.clearCallingIdentity();
10213 try {
10214 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10215 } finally {
10216 Binder.restoreCallingIdentity(identity);
10217 }
10218 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010219
10220 @Override
10221 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010222 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010223 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010224 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010225
joonhunshin4ac60942023-11-15 15:23:39 +000010226 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10227 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10228
Pengquan Menga1bb6272018-09-06 09:59:22 -070010229 final long identity = Binder.clearCallingIdentity();
10230 try {
10231 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10232 } finally {
10233 Binder.restoreCallingIdentity(identity);
10234 }
10235 }
10236
10237 @Override
10238 public boolean setCdmaRoamingMode(int subId, int mode) {
10239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10240 mApp, subId, "setCdmaRoamingMode");
10241
joonhunshin4ac60942023-11-15 15:23:39 +000010242 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10243 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10244
Pengquan Menga1bb6272018-09-06 09:59:22 -070010245 final long identity = Binder.clearCallingIdentity();
10246 try {
10247 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10248 } finally {
10249 Binder.restoreCallingIdentity(identity);
10250 }
10251 }
10252
10253 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010254 public int getCdmaSubscriptionMode(int subId) {
10255 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010256 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010257 mApp, subId, "getCdmaSubscriptionMode");
10258
joonhunshin4ac60942023-11-15 15:23:39 +000010259 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10260 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10261
Sarah Chinbaab1432020-10-28 13:46:24 -070010262 final long identity = Binder.clearCallingIdentity();
10263 try {
10264 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10265 } finally {
10266 Binder.restoreCallingIdentity(identity);
10267 }
10268 }
10269
10270 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010271 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10273 mApp, subId, "setCdmaSubscriptionMode");
10274
joonhunshin4ac60942023-11-15 15:23:39 +000010275 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10276 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10277
Pengquan Menga1bb6272018-09-06 09:59:22 -070010278 final long identity = Binder.clearCallingIdentity();
10279 try {
10280 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10281 } finally {
10282 Binder.restoreCallingIdentity(identity);
10283 }
10284 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010285
sqianc5eccab2018-10-19 18:46:41 -070010286 @Override
sqian8c685422019-02-22 15:55:18 -080010287 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010288 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010290 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10291 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010292 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10293 }
joonhunshin4ac60942023-11-15 15:23:39 +000010294
10295 enforceTelephonyFeatureWithException(callingPackage,
10296 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10297
sqian11b7a0e2018-12-05 18:48:28 -080010298 final long identity = Binder.clearCallingIdentity();
10299 try {
sqian854d44b2018-12-12 16:48:18 -080010300 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10301 for (Phone phone: PhoneFactory.getPhones()) {
10302 if (phone.getEmergencyNumberTracker() != null
10303 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10304 emergencyNumberListInternal.put(
10305 phone.getSubId(),
10306 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10307 }
sqian11b7a0e2018-12-05 18:48:28 -080010308 }
sqian854d44b2018-12-12 16:48:18 -080010309 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010310 } finally {
10311 Binder.restoreCallingIdentity(identity);
10312 }
sqianc5eccab2018-10-19 18:46:41 -070010313 }
10314
10315 @Override
sqian8c685422019-02-22 15:55:18 -080010316 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010317 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010318 if (!exactMatch) {
10319 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010320 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010321 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010322 }
joonhunshin4ac60942023-11-15 15:23:39 +000010323
10324 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10325 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10326
sqian11b7a0e2018-12-05 18:48:28 -080010327 final long identity = Binder.clearCallingIdentity();
10328 try {
sqian854d44b2018-12-12 16:48:18 -080010329 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010330 //Note: we ignore passed in param exactMatch. We can remove it once
10331 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010332 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010333 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010334 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010335 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010336 }
sqian11b7a0e2018-12-05 18:48:28 -080010337 }
10338 return false;
10339 } finally {
10340 Binder.restoreCallingIdentity(identity);
10341 }
10342 }
10343
sqianf4ca7ed2019-01-15 18:32:07 -080010344 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010345 * Start emergency callback mode for GsmCdmaPhone for testing.
10346 */
10347 @Override
10348 public void startEmergencyCallbackMode() {
10349 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10350 "startEmergencyCallbackMode");
10351 enforceModifyPermission();
10352 final long identity = Binder.clearCallingIdentity();
10353 try {
10354 for (Phone phone : PhoneFactory.getPhones()) {
10355 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10356 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10357 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10358 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10359 gsmCdmaPhone.obtainMessage(
10360 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10361 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10362 }
10363 }
10364 } finally {
10365 Binder.restoreCallingIdentity(identity);
10366 }
10367 }
10368
10369 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010370 * Update emergency number list for test mode.
10371 */
10372 @Override
10373 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10374 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10375 "updateEmergencyNumberListTestMode");
10376
10377 final long identity = Binder.clearCallingIdentity();
10378 try {
10379 for (Phone phone: PhoneFactory.getPhones()) {
10380 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10381 if (tracker != null) {
10382 tracker.executeEmergencyNumberTestModeCommand(action, num);
10383 }
10384 }
10385 } finally {
10386 Binder.restoreCallingIdentity(identity);
10387 }
10388 }
10389
10390 /**
10391 * Get the full emergency number list for test mode.
10392 */
10393 @Override
10394 public List<String> getEmergencyNumberListTestMode() {
10395 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10396 "getEmergencyNumberListTestMode");
10397
10398 final long identity = Binder.clearCallingIdentity();
10399 try {
10400 Set<String> emergencyNumbers = new HashSet<>();
10401 for (Phone phone: PhoneFactory.getPhones()) {
10402 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10403 if (tracker != null) {
10404 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10405 emergencyNumbers.add(num.getNumber());
10406 }
10407 }
10408 }
10409 return new ArrayList<>(emergencyNumbers);
10410 } finally {
10411 Binder.restoreCallingIdentity(identity);
10412 }
10413 }
10414
chen xud6b45bd2018-10-30 22:27:10 -070010415 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010416 public int getEmergencyNumberDbVersion(int subId) {
10417 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10418
joonhunshin4ac60942023-11-15 15:23:39 +000010419 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10420 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10421
Shuo Qian3b6ee772019-11-13 17:43:31 -080010422 final long identity = Binder.clearCallingIdentity();
10423 try {
10424 final Phone phone = getPhone(subId);
10425 if (phone == null) {
10426 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10427 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10428 }
10429 return phone.getEmergencyNumberDbVersion();
10430 } finally {
10431 Binder.restoreCallingIdentity(identity);
10432 }
10433 }
10434
10435 @Override
10436 public void notifyOtaEmergencyNumberDbInstalled() {
10437 enforceModifyPermission();
10438
joonhunshin4ac60942023-11-15 15:23:39 +000010439 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10440 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10441
Shuo Qian3b6ee772019-11-13 17:43:31 -080010442 final long identity = Binder.clearCallingIdentity();
10443 try {
10444 for (Phone phone: PhoneFactory.getPhones()) {
10445 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10446 if (tracker != null) {
10447 tracker.updateOtaEmergencyNumberDatabase();
10448 }
10449 }
10450 } finally {
10451 Binder.restoreCallingIdentity(identity);
10452 }
10453 }
10454
10455 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010456 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010457 enforceActiveEmergencySessionPermission();
10458
joonhunshin4ac60942023-11-15 15:23:39 +000010459 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10460 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10461
Shuo Qian3b6ee772019-11-13 17:43:31 -080010462 final long identity = Binder.clearCallingIdentity();
10463 try {
10464 for (Phone phone: PhoneFactory.getPhones()) {
10465 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10466 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010467 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10468 }
10469 }
10470 } finally {
10471 Binder.restoreCallingIdentity(identity);
10472 }
10473 }
10474
10475 @Override
10476 public void resetOtaEmergencyNumberDbFilePath() {
10477 enforceActiveEmergencySessionPermission();
10478
joonhunshin4ac60942023-11-15 15:23:39 +000010479 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10480 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10481
Shuo Qianc373f112020-03-05 17:55:34 -080010482 final long identity = Binder.clearCallingIdentity();
10483 try {
10484 for (Phone phone: PhoneFactory.getPhones()) {
10485 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10486 if (tracker != null) {
10487 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010488 }
10489 }
10490 } finally {
10491 Binder.restoreCallingIdentity(identity);
10492 }
10493 }
10494
10495 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010496 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10497 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10498 Phone phone = getPhone(subId);
10499 if (phone == null) {
10500 return null;
10501 }
10502 final long identity = Binder.clearCallingIdentity();
10503 try {
10504 UiccProfile profile = UiccController.getInstance()
10505 .getUiccProfileForPhone(phone.getPhoneId());
10506 if (profile != null) {
10507 return profile.getCertsFromCarrierPrivilegeAccessRules();
10508 }
10509 } finally {
10510 Binder.restoreCallingIdentity(identity);
10511 }
10512 return null;
10513 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010514
10515 /**
10516 * Enable or disable a modem stack.
10517 */
10518 @Override
10519 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10520 enforceModifyPermission();
10521
joonhunshin4ac60942023-11-15 15:23:39 +000010522 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10523 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10524
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010525 final long identity = Binder.clearCallingIdentity();
10526 try {
10527 Phone phone = PhoneFactory.getPhone(slotIndex);
10528 if (phone == null) {
10529 return false;
10530 } else {
10531 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10532 }
10533 } finally {
10534 Binder.restoreCallingIdentity(identity);
10535 }
10536 }
Michelecea4cf22018-12-21 15:00:11 -080010537
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010538 /**
10539 * Whether a modem stack is enabled or not.
10540 */
10541 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010542 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10543 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010544 Phone phone = PhoneFactory.getPhone(slotIndex);
10545 if (phone == null) return false;
10546
10547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010548 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10549 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010550 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10551 }
10552
joonhunshin4ac60942023-11-15 15:23:39 +000010553 enforceTelephonyFeatureWithException(callingPackage,
10554 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10555
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010556 final long identity = Binder.clearCallingIdentity();
10557 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010558 try {
10559 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10560 } catch (NoSuchElementException ex) {
10561 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10562 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010563 } finally {
10564 Binder.restoreCallingIdentity(identity);
10565 }
10566 }
10567
Michelecea4cf22018-12-21 15:00:11 -080010568 @Override
Michele0ea7d782019-03-19 14:58:42 -070010569 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010570 enforceModifyPermission();
10571
joonhunshin4ac60942023-11-15 15:23:39 +000010572 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10573 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10574
Michelecea4cf22018-12-21 15:00:11 -080010575 final long identity = Binder.clearCallingIdentity();
10576 try {
10577 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010578 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010579 .commit();
10580 } finally {
10581 Binder.restoreCallingIdentity(identity);
10582 }
10583 }
10584
10585 @Override
Michele0ea7d782019-03-19 14:58:42 -070010586 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010587 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010589 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10590 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010591 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010592 }
Michelecea4cf22018-12-21 15:00:11 -080010593
joonhunshin4ac60942023-11-15 15:23:39 +000010594 enforceTelephonyFeatureWithException(callingPackage,
10595 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10596
Michelecea4cf22018-12-21 15:00:11 -080010597 final long identity = Binder.clearCallingIdentity();
10598 try {
Michele0ea7d782019-03-19 14:58:42 -070010599 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010600 } finally {
10601 Binder.restoreCallingIdentity(identity);
10602 }
10603 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010604
Michele0ea7d782019-03-19 14:58:42 -070010605 @TelephonyManager.IsMultiSimSupportedResult
10606 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010607 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10608 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10609 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010610 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10611 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010612 }
10613 // Check if the hardware supports multisim functionality. If usage of multisim is not
10614 // supported by the modem, indicate that it is restricted.
10615 PhoneCapability staticCapability =
10616 mPhoneConfigurationManager.getStaticPhoneCapability();
10617 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010618 loge("isMultiSimSupportedInternal: no static configuration available");
10619 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010620 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010621 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010622 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10623 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010624 }
10625 // Check if support of multiple SIMs is restricted by carrier
10626 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010627 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010628 }
10629
Michele0ea7d782019-03-19 14:58:42 -070010630 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010631 }
10632
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010633 /**
10634 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010635 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10636 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10637 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010638 * @param numOfSims number of active sims we want to switch to
10639 */
10640 @Override
10641 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010642 if (numOfSims == 1) {
10643 enforceModifyPermission();
10644 } else {
10645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10646 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10647 }
joonhunshin4ac60942023-11-15 15:23:39 +000010648
10649 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10650 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10651
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010652 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010653
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010654 try {
Michele30b57b22019-03-01 12:01:14 -080010655 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010656 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010657 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10658 return;
10659 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010660 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10661 } finally {
10662 Binder.restoreCallingIdentity(identity);
10663 }
10664 }
10665
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010666 @Override
10667 public boolean isApplicationOnUicc(int subId, int appType) {
10668 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010669
10670 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10671 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10672
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010673 Phone phone = getPhone(subId);
10674 if (phone == null) {
10675 return false;
10676 }
10677 final long identity = Binder.clearCallingIdentity();
10678 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010679 UiccPort uiccPort = phone.getUiccPort();
10680 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010681 return false;
10682 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010683 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010684 if (uiccProfile == null) {
10685 return false;
10686 }
10687 if (TelephonyManager.APPTYPE_SIM <= appType
10688 && appType <= TelephonyManager.APPTYPE_ISIM) {
10689 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10690 }
10691 return false;
10692 } finally {
10693 Binder.restoreCallingIdentity(identity);
10694 }
10695 }
10696
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010697 /**
chen xub4baa772019-04-03 10:23:41 -070010698 * Get whether making changes to modem configurations will trigger reboot.
10699 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010700 */
10701 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010702 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10703 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010705 mApp, subId, callingPackage, callingFeatureId,
10706 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010707 return false;
10708 }
joonhunshin4ac60942023-11-15 15:23:39 +000010709
10710 enforceTelephonyFeatureWithException(callingPackage,
10711 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10712 "doesSwitchMultiSimConfigTriggerReboot");
10713
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010714 final long identity = Binder.clearCallingIdentity();
10715 try {
10716 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10717 } finally {
10718 Binder.restoreCallingIdentity(identity);
10719 }
10720 }
10721
Nathan Harold29f5f052019-02-15 13:41:57 -080010722 private void updateModemStateMetrics() {
10723 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10724 // TODO: check the state for each modem if the api is ready.
10725 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10726 }
10727
Pengquan Meng3889a572019-01-23 11:16:29 -080010728 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010729 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010730 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010731 // Verify that the callingPackage belongs to the calling UID
10732 mApp.getSystemService(AppOpsManager.class)
10733 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010734
10735 enforceTelephonyFeatureWithException(callingPackage,
10736 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10737
Pengquan Meng3889a572019-01-23 11:16:29 -080010738 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010739 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010740 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010741 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10742 if (slotInfos != null) {
10743 for (int i = 0; i < slotInfos.length; i++) {
10744 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10745 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10746 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10747 portInfo.getLogicalSlotIndex()));
10748 }
10749 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010750 }
10751 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010752 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010753 } finally {
10754 Binder.restoreCallingIdentity(identity);
10755 }
10756 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010757
10758 /**
10759 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010760 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010761 */
jimsunf9ec1622022-09-13 21:18:43 +080010762 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010763 @Override
10764 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010765 return getHalVersion(HAL_SERVICE_RADIO);
10766 }
10767
10768 /**
10769 * Get the HAL Version of a specific service
10770 */
10771 @Override
10772 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010773 Phone phone = getDefaultPhone();
10774 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010775 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010776 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10777 return hv.major * 100 + hv.minor;
10778 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010779
10780 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010781 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010782 *
10783 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010784 */
10785 @Override
sangyun097dcf72024-01-04 10:35:49 +090010786 public @Nullable String getCurrentPackageName() {
10787 PackageManager pm = mApp.getPackageManager();
10788 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10789 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010790 }
10791
10792 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010793 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10794 * corresponding network requests on a subId.
10795 *
10796 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010797 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010798 * 2) APN is un-metered for this subscription, or
10799 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010800 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010801 *
10802 * @return whether data is allowed for a apn type.
10803 *
10804 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010805 */
10806 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010807 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010808 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10809 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010810
joonhunshin4ac60942023-11-15 15:23:39 +000010811 enforceTelephonyFeatureWithException(callingPackage,
10812 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10813
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010814 // Now that all security checks passes, perform the operation as ourselves.
10815 final long identity = Binder.clearCallingIdentity();
10816 try {
10817 Phone phone = getPhone(subId);
10818 if (phone == null) return false;
10819
Jack Yu27422a52022-03-21 10:38:05 -070010820 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010821 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010822 isMetered = phone.getDataNetworkController().getDataConfigManager()
10823 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10824 phone.getServiceState().getDataRoaming());
10825 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010826 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010827 } finally {
10828 Binder.restoreCallingIdentity(identity);
10829 }
10830 }
10831
10832 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010833 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010834 enforceReadPrivilegedPermission("isApnMetered");
10835
joonhunshin4ac60942023-11-15 15:23:39 +000010836 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10837 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10838
Malcolm Chene5ad5792019-04-18 13:51:02 -070010839 // Now that all security checks passes, perform the operation as ourselves.
10840 final long identity = Binder.clearCallingIdentity();
10841 try {
10842 Phone phone = getPhone(subId);
10843 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010844 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10845 DataUtils.apnTypeToNetworkCapability(apnType),
10846 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010847 } finally {
10848 Binder.restoreCallingIdentity(identity);
10849 }
10850 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010851
10852 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010853 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10854 int subscriptionId, IBooleanConsumer resultCallback) {
10855 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010856
10857 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10858 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10859
Hall Liu73f5d362020-01-20 13:42:00 -080010860 long token = Binder.clearCallingIdentity();
10861 try {
10862 Phone phone = getPhone(subscriptionId);
10863 if (phone == null) {
10864 try {
10865 if (resultCallback != null) {
10866 resultCallback.accept(false);
10867 }
10868 } catch (RemoteException e) {
10869 // ignore
10870 }
10871 return;
10872 }
10873 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10874 Pair.create(specifiers, (x) -> {
10875 try {
10876 if (resultCallback != null) {
10877 resultCallback.accept(x);
10878 }
10879 } catch (RemoteException e) {
10880 // ignore
10881 }
10882 });
10883 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10884 } finally {
10885 Binder.restoreCallingIdentity(token);
10886 }
10887 }
10888
10889 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010890 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10891 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010892 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010893 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010894
10895 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10896 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10897
Sarah Chin679c08a2020-11-18 13:39:35 -080010898 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10899 final long identity = Binder.clearCallingIdentity();
10900 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010901 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10902 if (result instanceof IllegalStateException) {
10903 throw (IllegalStateException) result;
10904 }
10905 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010906 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10907 return specifiers;
10908 } finally {
10909 Binder.restoreCallingIdentity(identity);
10910 }
10911 }
10912
10913 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010914 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010915 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010916
10917 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10918 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10919
Jack Yu8b766fc2022-03-21 09:42:33 -070010920 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010921 }
10922
10923 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010924 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10925 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010926 if (callingPackage == null) {
10927 callingPackage = getCurrentPackageName();
10928 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010929 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10930 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010931 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10932 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010933 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10934 }
10935 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10936 Intent intent = new Intent();
10937 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10938 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10939 // Bring up choose default SMS subscription dialog right now
10940 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10941 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10942 mApp.startActivity(intent);
10943 }
chen xud5ca2d52019-05-28 15:20:57 -070010944
10945 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010946 public void showSwitchToManagedProfileDialog() {
10947 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010948 try {
10949 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10950 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10951 // for work telephony.
10952 Intent intent = new Intent(Intent.ACTION_SENDTO);
10953 intent.setData(Uri.parse("smsto:"));
10954 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10955 mApp.startActivity(intent);
10956 } catch (ActivityNotFoundException e) {
10957 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10958 Intent intent = new Intent();
10959 intent.setClass(mApp, ErrorDialogActivity.class);
10960 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10961 mApp.startActivity(intent);
10962 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010963 }
10964
10965 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010966 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010967 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10968 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10969
chen xud5ca2d52019-05-28 15:20:57 -070010970 //TODO investigate if this API should require proper permission check in R b/133791609
10971 final long identity = Binder.clearCallingIdentity();
10972 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010973 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10974 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10975 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10976 return carrierUAProfUrl;
10977 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010978 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10979 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010980 } finally {
10981 Binder.restoreCallingIdentity(identity);
10982 }
10983 }
10984
10985 @Override
10986 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010987 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10988 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10989
chen xud5ca2d52019-05-28 15:20:57 -070010990 //TODO investigate if this API should require proper permission check in R b/133791609
10991 final long identity = Binder.clearCallingIdentity();
10992 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010993 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10994 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10995 if (!TextUtils.isEmpty(carrierUserAgent)) {
10996 return carrierUserAgent;
10997 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010998 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10999 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011000 } finally {
11001 Binder.restoreCallingIdentity(identity);
11002 }
11003 }
Jack Yub07d4972019-05-28 16:12:25 -070011004
11005 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011006 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11007 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011008
joonhunshin4ac60942023-11-15 15:23:39 +000011009 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11010 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11011
Jack Yub07d4972019-05-28 16:12:25 -070011012 final long identity = Binder.clearCallingIdentity();
11013 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011014 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011015 if (phone == null) return false;
11016
Ling Maf188d502022-09-16 15:22:36 -070011017 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011018 } finally {
11019 Binder.restoreCallingIdentity(identity);
11020 }
11021 }
11022
11023 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011024 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011025 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011026 enforceModifyPermission();
11027
joonhunshin4ac60942023-11-15 15:23:39 +000011028 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11029 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11030
changbettyd5c246e2019-12-24 15:40:37 +080011031 final long identity = Binder.clearCallingIdentity();
11032 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011033 Phone phone = getPhone(subscriptionId);
11034 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011035
Ling Maf188d502022-09-16 15:22:36 -070011036 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011037 } finally {
11038 Binder.restoreCallingIdentity(identity);
11039 }
11040 }
11041
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011042 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011043 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011044 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11045 * otherwise.
11046 */
11047 @Override
11048 public void setCepEnabled(boolean isCepEnabled) {
11049 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11050
11051 final long identity = Binder.clearCallingIdentity();
11052 try {
11053 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11054 for (Phone phone : PhoneFactory.getPhones()) {
11055 Phone defaultPhone = phone.getImsPhone();
11056 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11057 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11058 ImsPhoneCallTracker imsPhoneCallTracker =
11059 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11060 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11061 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11062 + imsPhone.getMsisdn());
11063 }
11064 }
11065 } finally {
11066 Binder.restoreCallingIdentity(identity);
11067 }
11068 }
allenwtsu46dcc572020-01-08 18:24:03 +080011069
11070 /**
11071 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11072 *
11073 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11074 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11075 * before being read.
11076 */
11077 @Override
11078 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11079 isCompressed) {
11080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11081 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011082 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11083 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11084 }
joonhunshin4ac60942023-11-15 15:23:39 +000011085
11086 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11087 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11088 Binder.getCallingUserHandle())) {
11089 if (!isImsAvailableOnDevice()) {
11090 // ProvisioningManager can not handle ServiceSpecificException.
11091 // Throw the IllegalStateException and annotate ProvisioningManager.
11092 throw new IllegalStateException("IMS not available on device.");
11093 }
11094 } else {
11095 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11096 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11097 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011098 }
11099
11100 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011101 try {
Hui Wang761a6682020-10-31 05:12:53 +000011102 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11103 } finally {
11104 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011105 }
11106 }
zoey chene02881a2019-12-30 16:11:23 +080011107
11108 @Override
11109 public boolean isIccLockEnabled(int subId) {
11110 enforceReadPrivilegedPermission("isIccLockEnabled");
11111
joonhunshin4ac60942023-11-15 15:23:39 +000011112 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11113 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11114
zoey chene02881a2019-12-30 16:11:23 +080011115 // Now that all security checks passes, perform the operation as ourselves.
11116 final long identity = Binder.clearCallingIdentity();
11117 try {
11118 Phone phone = getPhone(subId);
11119 if (phone != null && phone.getIccCard() != null) {
11120 return phone.getIccCard().getIccLockEnabled();
11121 } else {
11122 return false;
11123 }
11124 } finally {
11125 Binder.restoreCallingIdentity(identity);
11126 }
11127 }
11128
11129 /**
11130 * Set the ICC pin lock enabled or disabled.
11131 *
11132 * @return an integer representing the status of IccLock enabled or disabled in the following
11133 * three cases:
11134 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11135 * successfully.
11136 * - Positive number and zero for remaining password attempts.
11137 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11138 *
11139 */
11140 @Override
11141 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11142 enforceModifyPermission();
11143
joonhunshin4ac60942023-11-15 15:23:39 +000011144 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11145 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11146
zoey chene02881a2019-12-30 16:11:23 +080011147 Phone phone = getPhone(subId);
11148 if (phone == null) {
11149 return 0;
11150 }
11151 // Now that all security checks passes, perform the operation as ourselves.
11152 final long identity = Binder.clearCallingIdentity();
11153 try {
11154 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11155 new Pair<Boolean, String>(enabled, password), phone, null);
11156 return attemptsRemaining;
11157
11158 } catch (Exception e) {
11159 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11160 } finally {
11161 Binder.restoreCallingIdentity(identity);
11162 }
11163 return 0;
11164 }
11165
11166 /**
11167 * Change the ICC password used in ICC pin lock.
11168 *
11169 * @return an integer representing the status of IccLock changed in the following three cases:
11170 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11171 * - Positive number and zero for remaining password attempts.
11172 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11173 *
11174 */
11175 @Override
11176 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11177 enforceModifyPermission();
11178
joonhunshin4ac60942023-11-15 15:23:39 +000011179 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11180 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11181
zoey chene02881a2019-12-30 16:11:23 +080011182 Phone phone = getPhone(subId);
11183 if (phone == null) {
11184 return 0;
11185 }
11186 // Now that all security checks passes, perform the operation as ourselves.
11187 final long identity = Binder.clearCallingIdentity();
11188 try {
11189 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11190 new Pair<String, String>(oldPassword, newPassword), phone, null);
11191 return attemptsRemaining;
11192
11193 } catch (Exception e) {
11194 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11195 } finally {
11196 Binder.restoreCallingIdentity(identity);
11197 }
11198 return 0;
11199 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011200
11201 /**
11202 * Request for receiving user activity notification
11203 */
11204 @Override
11205 public void requestUserActivityNotification() {
11206 if (!mNotifyUserActivity.get()
11207 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11208 mNotifyUserActivity.set(true);
11209 }
11210 }
11211
11212 /**
11213 * Called when userActivity is signalled in the power manager.
11214 * This is safe to call from any thread, with any window manager locks held or not.
11215 */
11216 @Override
11217 public void userActivity() {
11218 // ***************************************
11219 // * Inherited from PhoneWindowManager *
11220 // ***************************************
11221 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11222 // WITH ITS LOCKS HELD.
11223 //
11224 // This code must be VERY careful about the locks
11225 // it acquires.
11226 // In fact, the current code acquires way too many,
11227 // and probably has lurking deadlocks.
11228
11229 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11230 throw new SecurityException("Only the OS may call notifyUserActivity()");
11231 }
11232
11233 if (mNotifyUserActivity.getAndSet(false)) {
11234 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11235 USER_ACTIVITY_NOTIFICATION_DELAY);
11236 }
11237 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011238
11239 @Override
11240 public boolean canConnectTo5GInDsdsMode() {
11241 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11242 }
Jack Yud10cdd42020-09-28 20:28:01 -070011243
11244 @Override
11245 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11246 String callingFeatureId) {
11247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11248 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11249 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11250 }
11251
joonhunshin4ac60942023-11-15 15:23:39 +000011252 enforceTelephonyFeatureWithException(callingPackage,
11253 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11254
Jack Yud10cdd42020-09-28 20:28:01 -070011255 Phone phone = getPhone(subId);
11256 if (phone == null) {
11257 throw new RuntimeException("phone is not available");
11258 }
11259 // Now that all security checks passes, perform the operation as ourselves.
11260 final long identity = Binder.clearCallingIdentity();
11261 try {
11262 return phone.getEquivalentHomePlmns();
11263 } finally {
11264 Binder.restoreCallingIdentity(identity);
11265 }
11266 }
Daniel Bright59e67312020-11-13 11:49:37 -080011267
11268 @Override
11269 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011270 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011271 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11272 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11273 "isRadioInterfaceCapabilitySupported");
11274
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011275 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011276 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011277 if (radioInterfaceCapabilities == null) {
11278 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011279 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011280 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011281 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011282
Hui Wang641e81c2020-10-12 12:14:23 -070011283 @Override
11284 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11285 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011286 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11287 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11288 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11289 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11290 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011291
11292 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11293 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11294
Hui Wang641e81c2020-10-12 12:14:23 -070011295 if (DBG) {
11296 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11297 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11298 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11299 }
11300
11301 if (!SubscriptionManager.isValidSubscriptionId(subId)
11302 || appType < TelephonyManager.APPTYPE_UNKNOWN
11303 || appType > TelephonyManager.APPTYPE_ISIM
11304 || nafUrl == null || securityProtocol == null || callback == null) {
11305 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11306 if (callback != null) {
11307 try {
11308 callback.onAuthenticationFailure(
11309 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11310 } catch (RemoteException exception) {
11311 log("Fail to notify onAuthenticationFailure due to " + exception);
11312 }
11313 return;
11314 }
11315 }
11316
11317 final long token = Binder.clearCallingIdentity();
11318 try {
11319 getGbaManager(subId).bootstrapAuthenticationRequest(
11320 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011321 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011322 } finally {
11323 Binder.restoreCallingIdentity(token);
11324 }
11325 }
11326
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011327 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011328 * Attempts to set the radio power state for all phones for thermal reason.
11329 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011330 * requested radio power state will actually be set. See {@link
11331 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11332 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011333 * @param enable {@code true} if trying to turn radio on.
11334 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11335 * false}.
11336 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011337 private boolean setRadioPowerForThermal(boolean enable) {
11338 boolean isPhoneAvailable = false;
11339 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11340 Phone phone = PhoneFactory.getPhone(i);
11341 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011342 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011343 isPhoneAvailable = true;
11344 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011345 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011346
11347 // return true if successfully informed the phone object about the thermal radio power
11348 // request.
11349 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011350 }
11351
11352 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011353 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011354 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11355 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11356 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11357 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11358 throw new IllegalArgumentException("modem does not support data throttling");
11359 }
11360
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011361 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11362 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011363 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011364 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11365 }
11366
Sarah Chinecc78c42022-03-31 21:16:48 -070011367 setDataEnabledForReason(
11368 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011369
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011370 if (isDataThrottlingSupported) {
11371 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011372 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011373 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11374 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11375 } else if (thermalMitigationResult
11376 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011377 log("Modem likely does not support data throttling on secondary carrier. Data " +
11378 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11379 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011380 }
11381 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011382 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011383
11384 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011385 }
11386
Jack Nudelman644b91a2021-03-12 14:09:48 -080011387 private static List<String> getThermalMitigationAllowlist(Context context) {
11388 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11389 for (String pckg : context.getResources()
11390 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11391 sThermalMitigationAllowlistedPackages.add(pckg);
11392 }
11393 }
11394
11395 return sThermalMitigationAllowlistedPackages;
11396 }
11397
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011398 private boolean isAnyPhoneInEmergencyState() {
11399 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11400 if (tm.isInEmergencyCall()) {
11401 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11402 return true;
11403 }
11404 for (Phone phone : PhoneFactory.getPhones()) {
11405 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11406 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011407 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11408 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011409 return true;
11410 }
11411 }
11412
11413 return false;
11414 }
11415
Jack Nudelman644b91a2021-03-12 14:09:48 -080011416 /**
11417 * Used by shell commands to add an authorized package name for thermal mitigation.
11418 * @param packageName name of package to be allowlisted
11419 * @param context
11420 */
11421 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11422 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11423 sThermalMitigationAllowlistedPackages.add(packageName);
11424 }
11425
11426 /**
11427 * Used by shell commands to remove an authorized package name for thermal mitigation.
11428 * @param packageName name of package to remove from allowlist
11429 * @param context
11430 */
11431 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11432 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11433 sThermalMitigationAllowlistedPackages.remove(packageName);
11434 }
11435
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011436 /**
11437 * Thermal mitigation request to control functionalities at modem.
11438 *
11439 * @param subId the id of the subscription.
11440 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011441 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011442 *
11443 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11444 */
11445 @Override
11446 @ThermalMitigationResult
11447 public int sendThermalMitigationRequest(
11448 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011449 ThermalMitigationRequest thermalMitigationRequest,
11450 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011451 enforceModifyPermission();
11452
Jack Nudelman644b91a2021-03-12 14:09:48 -080011453 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011454
11455 enforceTelephonyFeatureWithException(callingPackage,
11456 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11457
Jack Nudelman644b91a2021-03-12 14:09:48 -080011458 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11459 .contains(callingPackage)) {
11460 throw new SecurityException("Calling package must be configured in the device config. "
11461 + "calling package: " + callingPackage);
11462 }
11463
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011464 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11465 final long identity = Binder.clearCallingIdentity();
11466
11467 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11468 try {
11469 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11470 switch (thermalMitigationAction) {
11471 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11472 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011473 handleDataThrottlingRequest(subId,
11474 thermalMitigationRequest.getDataThrottlingRequest(),
11475 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011476 break;
11477 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11478 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11479 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11480 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11481 }
11482
11483 // Ensure that radio is on. If not able to power on due to phone being
11484 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011485 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011486 thermalMitigationResult =
11487 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11488 break;
11489 }
11490
11491 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011492 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011493 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11494 break;
11495 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11496 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11497 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11498 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11499 }
11500
11501 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11502 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011503 Phone phone = getPhone(subId);
11504 if (phone == null) {
11505 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011506 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011507 break;
11508 }
11509
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011510 TelephonyConnectionService service =
11511 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011512 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011513 Log.e(LOG_TAG, "An emergency call is pending");
11514 thermalMitigationResult =
11515 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11516 break;
11517 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011518 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011519 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011520 break;
11521 }
11522 } else {
11523 thermalMitigationResult =
11524 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11525 break;
11526 }
11527
11528 // Turn radio off. If not able to power off due to phone being unavailable,
11529 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011530 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011531 thermalMitigationResult =
11532 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11533 break;
11534 }
11535 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011536 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011537 break;
11538 default:
11539 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11540 + "not exist. Requested action: " + thermalMitigationAction);
11541 }
11542 } catch (IllegalArgumentException e) {
11543 throw e;
11544 } catch (Exception e) {
11545 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11546 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11547 } finally {
11548 Binder.restoreCallingIdentity(identity);
11549 }
11550
11551 if (DBG) {
11552 log("thermalMitigationRequest returning with thermalMitigationResult: "
11553 + thermalMitigationResult);
11554 }
11555
11556 return thermalMitigationResult;
11557 }
Hui Wang641e81c2020-10-12 12:14:23 -070011558
11559 /**
11560 * Set the GbaService Package Name that Telephony will bind to.
11561 *
11562 * @param subId The sim that the GbaService is associated with.
11563 * @param packageName The name of the package to be replaced with.
11564 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11565 */
11566 @Override
11567 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11568 enforceModifyPermission();
11569
11570 final long identity = Binder.clearCallingIdentity();
11571 try {
11572 return getGbaManager(subId).overrideServicePackage(packageName);
11573 } finally {
11574 Binder.restoreCallingIdentity(identity);
11575 }
11576 }
11577
11578 /**
11579 * Return the package name of the currently bound GbaService.
11580 *
11581 * @param subId The sim that the GbaService is associated with.
11582 * @return the package name of the GbaService configuration, null if GBA is not supported.
11583 */
11584 @Override
11585 public String getBoundGbaService(int subId) {
11586 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11587
11588 final long identity = Binder.clearCallingIdentity();
11589 try {
11590 return getGbaManager(subId).getServicePackage();
11591 } finally {
11592 Binder.restoreCallingIdentity(identity);
11593 }
11594 }
11595
11596 /**
11597 * Set the release time for telephony to unbind GbaService.
11598 *
11599 * @param subId The sim that the GbaService is associated with.
11600 * @param interval The release time to unbind GbaService by millisecond.
11601 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11602 */
11603 @Override
11604 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11605 enforceModifyPermission();
11606
11607 final long identity = Binder.clearCallingIdentity();
11608 try {
11609 return getGbaManager(subId).overrideReleaseTime(interval);
11610 } finally {
11611 Binder.restoreCallingIdentity(identity);
11612 }
11613 }
11614
11615 /**
11616 * Return the release time for telephony to unbind GbaService.
11617 *
11618 * @param subId The sim that the GbaService is associated with.
11619 * @return The release time to unbind GbaService by millisecond.
11620 */
11621 @Override
11622 public int getGbaReleaseTime(int subId) {
11623 enforceReadPrivilegedPermission("getGbaReleaseTime");
11624
11625 final long identity = Binder.clearCallingIdentity();
11626 try {
11627 return getGbaManager(subId).getReleaseTime();
11628 } finally {
11629 Binder.restoreCallingIdentity(identity);
11630 }
11631 }
11632
11633 private GbaManager getGbaManager(int subId) {
11634 GbaManager instance = GbaManager.getInstance(subId);
11635 if (instance == null) {
11636 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11637 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11638 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11639 }
11640 return instance;
11641 }
Hui Wang761a6682020-10-31 05:12:53 +000011642
11643 /**
11644 * indicate whether the device and the carrier can support
11645 * RCS VoLTE single registration.
11646 */
11647 @Override
11648 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011649 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11650 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11651 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11652 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011653
11654 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11655 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11656 }
11657
11658 final long identity = Binder.clearCallingIdentity();
11659 try {
11660 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11661 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011662 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11663 if (isCapable != null) {
11664 return isCapable;
11665 }
Hui Wang761a6682020-10-31 05:12:53 +000011666 }
Hui Wang67af90e2021-06-04 16:57:15 -070011667 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11668 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011669 } finally {
11670 Binder.restoreCallingIdentity(identity);
11671 }
11672 }
11673
11674 /**
11675 * Register RCS provisioning callback.
11676 */
11677 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011678 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011679 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011680 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011681 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011682 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11683 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011684
11685 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11686 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11687 }
joonhunshin4ac60942023-11-15 15:23:39 +000011688 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11689 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11690 Binder.getCallingUserHandle())) {
11691 if (!isImsAvailableOnDevice()) {
11692 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11693 "IMS not available on device.");
11694 }
11695 } else {
11696 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11697 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011698 }
11699
11700 final long identity = Binder.clearCallingIdentity();
11701 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011702 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011703 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011704 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11705 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011706 }
Hui Wang761a6682020-10-31 05:12:53 +000011707 } finally {
11708 Binder.restoreCallingIdentity(identity);
11709 }
11710 }
11711
11712 /**
11713 * Unregister RCS provisioning callback.
11714 */
11715 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011716 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011717 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011718 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011719 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011720 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11721 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011722
11723 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11724 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11725 }
joonhunshin4ac60942023-11-15 15:23:39 +000011726
11727 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11728 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11729 Binder.getCallingUserHandle())) {
11730 if (!isImsAvailableOnDevice()) {
11731 // operation failed silently
11732 Rlog.w(LOG_TAG, "IMS not available on device.");
11733 return;
11734 }
11735 } else {
11736 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11737 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11738 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011739 }
11740
11741 final long identity = Binder.clearCallingIdentity();
11742 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011743 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011744 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011745 } finally {
11746 Binder.restoreCallingIdentity(identity);
11747 }
11748 }
11749
11750 /**
11751 * trigger RCS reconfiguration.
11752 */
11753 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011754 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11755 "triggerRcsReconfiguration",
11756 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011757
11758 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11759 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11760 }
joonhunshin4ac60942023-11-15 15:23:39 +000011761 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11762 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11763 Binder.getCallingUserHandle())) {
11764 if (!isImsAvailableOnDevice()) {
11765 // ProvisioningManager can not handle ServiceSpecificException.
11766 // Throw the IllegalStateException and annotate ProvisioningManager.
11767 throw new IllegalStateException("IMS not available on device.");
11768 }
11769 } else {
11770 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11771 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011772 }
11773
11774 final long identity = Binder.clearCallingIdentity();
11775 try {
11776 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11777 } finally {
11778 Binder.restoreCallingIdentity(identity);
11779 }
11780 }
11781
11782 /**
11783 * Provide the client configuration parameters of the RCS application.
11784 */
11785 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011786 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11787 "setRcsClientConfiguration",
11788 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011789
11790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11791 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11792 }
joonhunshin4ac60942023-11-15 15:23:39 +000011793 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11794 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11795 Binder.getCallingUserHandle())) {
11796 if (!isImsAvailableOnDevice()) {
11797 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11798 "IMS not available on device.");
11799 }
11800 } else {
11801 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11802 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011803 }
11804
11805 final long identity = Binder.clearCallingIdentity();
11806
11807 try {
11808 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11809 if (configBinder == null) {
11810 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011811 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11812 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011813 } else {
11814 configBinder.setRcsClientConfiguration(rcc);
11815 }
joonhunshin3e154242021-09-17 06:33:39 +000011816
11817 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11818 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011819 } catch (RemoteException e) {
11820 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011821 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11822 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011823 } finally {
11824 Binder.restoreCallingIdentity(identity);
11825 }
11826 }
11827
11828 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011829 * Enables or disables the test mode for RCS VoLTE single registration.
11830 */
11831 @Override
11832 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11833 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11834 "setRcsSingleRegistrationTestModeEnabled");
11835
11836 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11837 }
11838
11839 /**
11840 * Gets the test mode for RCS VoLTE single registration.
11841 */
11842 @Override
11843 public boolean getRcsSingleRegistrationTestModeEnabled() {
11844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11845 "getRcsSingleRegistrationTestModeEnabled");
11846
11847 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11848 }
11849
11850 /**
Hui Wang761a6682020-10-31 05:12:53 +000011851 * Overrides the config of RCS VoLTE single registration enabled for the device.
11852 */
11853 @Override
11854 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11855 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11856 "setDeviceSingleRegistrationEnabledOverride");
11857 enforceModifyPermission();
11858
11859 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11860 : Boolean.parseBoolean(enabledStr);
11861 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011862 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011863 }
11864
11865 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011866 * Sends a device to device communication message. Only usable via shell.
11867 * @param message message to send.
11868 * @param value message value.
11869 */
11870 @Override
11871 public void sendDeviceToDeviceMessage(int message, int value) {
11872 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011873 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011874 enforceModifyPermission();
11875
11876 final long identity = Binder.clearCallingIdentity();
11877 try {
11878 TelephonyConnectionService service =
11879 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11880 if (service == null) {
11881 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11882 return;
11883 }
11884 service.sendTestDeviceToDeviceMessage(message, value);
11885 } finally {
11886 Binder.restoreCallingIdentity(identity);
11887 }
11888 }
11889
Tyler Gunnbabbda02021-02-10 11:05:02 -080011890 /**
11891 * Sets the specified device to device transport active.
11892 * @param transport The transport to set active.
11893 */
11894 @Override
11895 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11896 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11897 "setActiveDeviceToDeviceTransport");
11898 enforceModifyPermission();
11899
11900 final long identity = Binder.clearCallingIdentity();
11901 try {
11902 TelephonyConnectionService service =
11903 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11904 if (service == null) {
11905 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11906 return;
11907 }
11908 service.setActiveDeviceToDeviceTransport(transport);
11909 } finally {
11910 Binder.restoreCallingIdentity(identity);
11911 }
11912 }
Tyler Gunn92479152021-01-20 16:30:10 -080011913
Tyler Gunnd4339262021-05-03 14:46:49 -070011914 @Override
11915 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11916 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11917 "setDeviceToDeviceForceEnabled");
11918
11919 final long identity = Binder.clearCallingIdentity();
11920 try {
11921 Arrays.stream(PhoneFactory.getPhones()).forEach(
11922 p -> {
11923 Phone thePhone = p.getImsPhone();
11924 if (thePhone != null && thePhone instanceof ImsPhone) {
11925 ImsPhone imsPhone = (ImsPhone) thePhone;
11926 CallTracker tracker = imsPhone.getCallTracker();
11927 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11928 ImsPhoneCallTracker imsPhoneCallTracker =
11929 (ImsPhoneCallTracker) tracker;
11930 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11931 }
11932 }
11933 }
11934 );
11935 } finally {
11936 Binder.restoreCallingIdentity(identity);
11937 }
11938 }
11939
Tyler Gunn92479152021-01-20 16:30:10 -080011940 /**
Hui Wang761a6682020-10-31 05:12:53 +000011941 * Gets the config of RCS VoLTE single registration enabled for the device.
11942 */
11943 @Override
11944 public boolean getDeviceSingleRegistrationEnabled() {
11945 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11946 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11947 }
11948
11949 /**
11950 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11951 */
11952 @Override
11953 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11954 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11955 "setCarrierSingleRegistrationEnabledOverride");
11956 enforceModifyPermission();
11957
11958 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11959 : Boolean.parseBoolean(enabledStr);
11960 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11961 subId, enabled);
11962 }
11963
11964 /**
11965 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11966 */
11967 @Override
11968 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11969 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11970 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11971 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011972
11973 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011974 * Overrides the ims feature validation result
11975 */
11976 @Override
11977 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11979 "setImsFeatureValidationOverride");
11980
11981 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11982 : Boolean.parseBoolean(enabledStr);
11983 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11984 subId, enabled);
11985 }
11986
11987 /**
11988 * Gets the ims feature validation override value
11989 */
11990 @Override
11991 public boolean getImsFeatureValidationOverride(int subId) {
11992 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11993 "getImsFeatureValidationOverride");
11994 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11995 }
11996
11997 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011998 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11999 * their mobile plan.
12000 */
12001 @Override
12002 public String getMobileProvisioningUrl() {
12003 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12004 final long identity = Binder.clearCallingIdentity();
12005 try {
12006 return getDefaultPhone().getMobileProvisioningUrl();
12007 } finally {
12008 Binder.restoreCallingIdentity(identity);
12009 }
12010 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012011
James.cf Linbcdf8b32021-01-14 16:44:13 +080012012 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012013 * Get the EAB contact from the EAB database.
12014 */
12015 @Override
12016 public String getContactFromEab(String contact) {
12017 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12018 enforceModifyPermission();
12019 final long identity = Binder.clearCallingIdentity();
12020 try {
12021 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12022 } finally {
12023 Binder.restoreCallingIdentity(identity);
12024 }
12025 }
12026
12027 /**
Calvin Pana1434322021-07-01 19:27:01 +080012028 * Get the EAB capability from the EAB database.
12029 */
12030 @Override
12031 public String getCapabilityFromEab(String contact) {
12032 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12033 enforceModifyPermission();
12034 final long identity = Binder.clearCallingIdentity();
12035 try {
12036 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12037 } finally {
12038 Binder.restoreCallingIdentity(identity);
12039 }
12040 }
12041
12042 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012043 * Remove the EAB contacts from the EAB database.
12044 */
12045 @Override
12046 public int removeContactFromEab(int subId, String contacts) {
12047 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12048 enforceModifyPermission();
12049 final long identity = Binder.clearCallingIdentity();
12050 try {
12051 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12052 } finally {
12053 Binder.restoreCallingIdentity(identity);
12054 }
12055 }
12056
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012057 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012058 public boolean getDeviceUceEnabled() {
12059 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12060 final long identity = Binder.clearCallingIdentity();
12061 try {
12062 return mApp.getDeviceUceEnabled();
12063 } finally {
12064 Binder.restoreCallingIdentity(identity);
12065 }
12066 }
12067
12068 @Override
12069 public void setDeviceUceEnabled(boolean isEnabled) {
12070 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12071 final long identity = Binder.clearCallingIdentity();
12072 try {
12073 mApp.setDeviceUceEnabled(isEnabled);
12074 } finally {
12075 Binder.restoreCallingIdentity(identity);
12076 }
12077 }
12078
Brad Ebinger14d467f2021-02-12 06:18:28 +000012079 /**
12080 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12081 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12082 */
12083 // Used for SHELL command only right now.
12084 @Override
12085 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12086 List<String> featureTags) {
12087 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12088 "addUceRegistrationOverrideShell");
12089 final long identity = Binder.clearCallingIdentity();
12090 try {
12091 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12092 new ArraySet<>(featureTags));
12093 } catch (ImsException e) {
12094 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12095 } finally {
12096 Binder.restoreCallingIdentity(identity);
12097 }
12098 }
12099
12100 /**
12101 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12102 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12103 */
12104 // Used for SHELL command only right now.
12105 @Override
12106 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12107 List<String> featureTags) {
12108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12109 "removeUceRegistrationOverrideShell");
12110 final long identity = Binder.clearCallingIdentity();
12111 try {
12112 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12113 new ArraySet<>(featureTags));
12114 } catch (ImsException e) {
12115 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12116 } finally {
12117 Binder.restoreCallingIdentity(identity);
12118 }
12119 }
12120
12121 /**
12122 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12123 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12124 */
12125 // Used for SHELL command only right now.
12126 @Override
12127 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12128 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12129 "clearUceRegistrationOverrideShell");
12130 final long identity = Binder.clearCallingIdentity();
12131 try {
12132 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12133 } catch (ImsException e) {
12134 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12135 } finally {
12136 Binder.restoreCallingIdentity(identity);
12137 }
12138 }
12139
12140 /**
12141 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12142 */
12143 // Used for SHELL command only right now.
12144 @Override
12145 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12146 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12147 "getLatestRcsContactUceCapabilityShell");
12148 final long identity = Binder.clearCallingIdentity();
12149 try {
12150 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12151 } catch (ImsException e) {
12152 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12153 } finally {
12154 Binder.restoreCallingIdentity(identity);
12155 }
12156 }
12157
12158 /**
12159 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12160 * device does not have an active PUBLISH.
12161 */
12162 // Used for SHELL command only right now.
12163 @Override
12164 public String getLastUcePidfXmlShell(int subId) {
12165 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12166 final long identity = Binder.clearCallingIdentity();
12167 try {
12168 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12169 } catch (ImsException e) {
12170 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12171 } finally {
12172 Binder.restoreCallingIdentity(identity);
12173 }
12174 }
12175
James.cf Line8713a42021-04-29 16:04:26 +080012176 /**
12177 * Remove UCE requests cannot be sent to the network status.
12178 */
12179 // Used for SHELL command only right now.
12180 @Override
12181 public boolean removeUceRequestDisallowedStatus(int subId) {
12182 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12183 final long identity = Binder.clearCallingIdentity();
12184 try {
12185 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12186 } catch (ImsException e) {
12187 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12188 } finally {
12189 Binder.restoreCallingIdentity(identity);
12190 }
12191 }
12192
James.cf Lin18bb9002021-05-25 01:37:38 +080012193 /**
12194 * Remove UCE requests cannot be sent to the network status.
12195 */
12196 // Used for SHELL command only.
12197 @Override
12198 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12199 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12200 final long identity = Binder.clearCallingIdentity();
12201 try {
12202 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12203 } catch (ImsException e) {
12204 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12205 } finally {
12206 Binder.restoreCallingIdentity(identity);
12207 }
12208 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012209
James.cf Lin4b784aa2021-01-31 03:25:15 +080012210 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012211 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12212 String callingPackage) {
12213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12214 mApp, subId, "setSignalStrengthUpdateRequest");
12215
joonhunshin4ac60942023-11-15 15:23:39 +000012216 enforceTelephonyFeatureWithException(callingPackage,
12217 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12218
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012219 final int callingUid = Binder.getCallingUid();
12220 // Verify that tha callingPackage belongs to the calling UID
12221 mApp.getSystemService(AppOpsManager.class)
12222 .checkPackage(callingUid, callingPackage);
12223
Rambo Wang3607f502021-02-01 21:51:40 -080012224 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012225
12226 final long identity = Binder.clearCallingIdentity();
12227 try {
12228 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12229 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12230
12231 if (result instanceof IllegalStateException) {
12232 throw (IllegalStateException) result;
12233 }
12234 } finally {
12235 Binder.restoreCallingIdentity(identity);
12236 }
12237 }
12238
12239 @Override
12240 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12241 String callingPackage) {
12242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12243 mApp, subId, "clearSignalStrengthUpdateRequest");
12244
joonhunshin4ac60942023-11-15 15:23:39 +000012245 enforceTelephonyFeatureWithException(callingPackage,
12246 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12247
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012248 final int callingUid = Binder.getCallingUid();
12249 // Verify that tha callingPackage belongs to the calling UID
12250 mApp.getSystemService(AppOpsManager.class)
12251 .checkPackage(callingUid, callingPackage);
12252
12253 final long identity = Binder.clearCallingIdentity();
12254 try {
12255 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12256 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12257
12258 if (result instanceof IllegalStateException) {
12259 throw (IllegalStateException) result;
12260 }
12261 } finally {
12262 Binder.restoreCallingIdentity(identity);
12263 }
12264 }
12265
Rambo Wang3607f502021-02-01 21:51:40 -080012266 private static void validateSignalStrengthUpdateRequest(Context context,
12267 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012268 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12269 // phone/system process do not have further restriction on request
12270 return;
12271 }
12272
12273 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012274 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012275 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012276 context.enforceCallingOrSelfPermission(
12277 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12278 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012279 }
12280
12281 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012282 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012283 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012284 || info.isEnabled()) {
12285 throw new IllegalArgumentException(
12286 "Only system can set hide fields in SignalThresholdInfo");
12287 }
12288
12289 // Thresholds length for each RAN need in range. This has been validated in
12290 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12291 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12292 final int[] thresholds = info.getThresholds();
12293 Objects.requireNonNull(thresholds);
12294 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12295 || thresholds.length
12296 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12297 throw new IllegalArgumentException(
12298 "thresholds length is out of range: " + thresholds.length);
12299 }
12300 }
12301 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012302
12303 /**
12304 * Gets the current phone capability.
12305 *
12306 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12307 * @return the PhoneCapability which describes the data connection capability of modem.
12308 * It's used to evaluate possible phone config change, for example from single
12309 * SIM device to multi-SIM device.
12310 */
12311 @Override
12312 public PhoneCapability getPhoneCapability() {
12313 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012314
12315 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12316 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12317
SongFerngWang8236caa2021-01-17 21:51:44 +080012318 final long identity = Binder.clearCallingIdentity();
12319 try {
12320 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12321 } finally {
12322 Binder.restoreCallingIdentity(identity);
12323 }
12324 }
Michele Berionne5e411512020-11-13 02:36:59 +000012325
12326 /**
12327 * Prepare TelephonyManager for an unattended reboot. The reboot is
12328 * required to be done shortly after the API is invoked.
12329 */
12330 @Override
12331 @TelephonyManager.PrepareUnattendedRebootResult
12332 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012333 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012334 enforceRebootPermission();
12335
joonhunshin4ac60942023-11-15 15:23:39 +000012336 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12337 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12338
Michele Berionne5e411512020-11-13 02:36:59 +000012339 final long identity = Binder.clearCallingIdentity();
12340 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012341 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012342 } finally {
12343 Binder.restoreCallingIdentity(identity);
12344 }
12345 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012346
12347 /**
12348 * Request to get the current slicing configuration including URSP rules and
12349 * NSSAIs (configured, allowed and rejected).
12350 *
12351 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12352 */
12353 @Override
12354 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012355 TelephonyPermissions
12356 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12357 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012358
joonhunshin4ac60942023-11-15 15:23:39 +000012359 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12360 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12361 "getSlicingConfig");
12362
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012363 final long identity = Binder.clearCallingIdentity();
12364 try {
12365 Phone phone = getDefaultPhone();
12366 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12367 } finally {
12368 Binder.restoreCallingIdentity(identity);
12369 }
12370 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012371
12372 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012373 * Check whether the given premium capability is available for purchase from the carrier.
12374 *
12375 * @param capability The premium capability to check.
12376 * @param subId The subId to check the premium capability for.
12377 *
12378 * @return Whether the given premium capability is available to purchase.
12379 */
12380 @Override
12381 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12382 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12383 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12384 log("Premium capability "
12385 + TelephonyManager.convertPremiumCapabilityToString(capability)
12386 + " is not available for purchase due to missing permissions.");
12387 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12388 + "permission READ_BASIC_PHONE_STATE.");
12389 }
12390
joonhunshin4ac60942023-11-15 15:23:39 +000012391 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12392 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12393
Sarah Chin2ec39f62022-08-31 17:03:26 -070012394 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012395 if (phone == null) {
12396 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12397 return false;
12398 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012399 final long identity = Binder.clearCallingIdentity();
12400 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012401 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012402 .isPremiumCapabilityAvailableForPurchase(capability);
12403 } finally {
12404 Binder.restoreCallingIdentity(identity);
12405 }
12406 }
12407
12408 /**
12409 * Purchase the given premium capability from the carrier.
12410 *
12411 * @param capability The premium capability to purchase.
12412 * @param callback The result of the purchase request.
12413 * @param subId The subId to purchase the premium capability for.
12414 */
12415 @Override
12416 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12417 log("purchasePremiumCapability: capability="
12418 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12419 + getCurrentPackageName());
12420
12421 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12422 mApp, "purchasePremiumCapability")) {
12423 log("purchasePremiumCapability "
12424 + TelephonyManager.convertPremiumCapabilityToString(capability)
12425 + " failed due to missing permissions.");
12426 throw new SecurityException("purchasePremiumCapability requires permission "
12427 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012428 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12429 mApp, "purchasePremiumCapability")) {
12430 log("purchasePremiumCapability "
12431 + TelephonyManager.convertPremiumCapabilityToString(capability)
12432 + " failed due to missing permissions.");
12433 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012434 }
12435
joonhunshin4ac60942023-11-15 15:23:39 +000012436 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12437 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12438
Sarah Chin2ec39f62022-08-31 17:03:26 -070012439 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012440 if (phone == null) {
12441 try {
12442 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12443 callback.accept(result);
12444 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12445 } catch (RemoteException e) {
12446 String logStr = "Purchase premium capability "
12447 + TelephonyManager.convertPremiumCapabilityToString(capability)
12448 + " failed due to RemoteException handling null phone: " + e;
12449 if (DBG) log(logStr);
12450 AnomalyReporter.reportAnomaly(
12451 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12452 }
12453 return;
12454 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012455
12456 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012457 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012458 callingProcess = mApp.getPackageManager().getApplicationInfo(
12459 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012460 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012461 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012462 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012463
12464 boolean isVisible = false;
12465 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12466 if (am != null) {
12467 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12468 if (processes != null) {
12469 for (ActivityManager.RunningAppProcessInfo process : processes) {
12470 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012471 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012472 if (process.processName.equals(callingProcess) && process.importance
12473 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12474 isVisible = true;
12475 break;
12476 }
12477 }
12478 }
12479 }
12480
12481 if (!isVisible) {
12482 try {
12483 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12484 callback.accept(result);
12485 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12486 } catch (RemoteException e) {
12487 String logStr = "Purchase premium capability "
12488 + TelephonyManager.convertPremiumCapabilityToString(capability)
12489 + " failed due to RemoteException handling background application: " + e;
12490 if (DBG) log(logStr);
12491 AnomalyReporter.reportAnomaly(
12492 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12493 }
12494 return;
12495 }
12496
Sarah Chin71b3a852022-09-28 15:54:19 -070012497 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012498 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012499 }
12500
12501 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012502 * Register an IMS connection state callback
12503 */
12504 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012505 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12506 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012507 if (feature == ImsFeature.FEATURE_MMTEL) {
12508 // ImsMmTelManager
12509 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12510 TelephonyPermissions
12511 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12512 mApp, subId, "registerImsStateCallback");
12513 } else if (feature == ImsFeature.FEATURE_RCS) {
12514 // ImsRcsManager or SipDelegateManager
12515 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12516 Binder.getCallingUid(), "registerImsStateCallback",
12517 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12518 Manifest.permission.READ_PRECISE_PHONE_STATE,
12519 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12520 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12521 }
12522
12523 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12524 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12525 "IMS not available on device.");
12526 }
12527
12528 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12529 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12530 }
12531
12532 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12533 if (controller == null) {
12534 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12535 "IMS not available on device.");
12536 }
12537
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012538 if (callingPackage == null) {
12539 callingPackage = getCurrentPackageName();
12540 }
12541
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012542 final long token = Binder.clearCallingIdentity();
12543 try {
12544 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012545 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012546 } catch (ImsException e) {
12547 throw new ServiceSpecificException(e.getCode());
12548 } finally {
12549 Binder.restoreCallingIdentity(token);
12550 }
12551 }
12552
12553 /**
12554 * Unregister an IMS connection state callback
12555 */
12556 @Override
12557 public void unregisterImsStateCallback(IImsStateCallback cb) {
12558 final long token = Binder.clearCallingIdentity();
12559 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12560 if (controller == null) {
12561 return;
12562 }
12563 try {
12564 controller.unregisterImsStateCallback(cb);
12565 } finally {
12566 Binder.restoreCallingIdentity(token);
12567 }
12568 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012569
12570 /**
12571 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12572 *
12573 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012574 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012575 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012576 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012577 * If there is current registered network this value will be same as the registered cell
12578 * identity. If the device goes out of service the previous cell identity is cached and
12579 * will be returned. If the cache age of the Cell identity is more than 24 hours
12580 * it will be cleared and null will be returned.
12581 *
12582 */
12583 @Override
12584 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12585 String callingFeatureId) {
12586 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12587 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12588 LocationAccessPolicy.checkLocationPermission(mApp,
12589 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12590 .setCallingPackage(callingPackage)
12591 .setCallingFeatureId(callingFeatureId)
12592 .setCallingPid(Binder.getCallingPid())
12593 .setCallingUid(Binder.getCallingUid())
12594 .setMethod("getLastKnownCellIdentity")
12595 .setLogAsInfo(true)
12596 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12597 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12598 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12599 .build());
12600
12601 boolean hasFinePermission =
12602 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12603 if (!hasFinePermission
12604 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12605 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012606 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012607 }
12608
12609 final long identity = Binder.clearCallingIdentity();
12610 try {
Ling Mac28f0212023-03-24 16:07:15 -070012611 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012612 if (sst == null) return null;
12613 return sst.getLastKnownCellIdentity();
12614 } finally {
12615 Binder.restoreCallingIdentity(identity);
12616 }
12617 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012618
jimsun3b9ccac2021-10-26 15:01:23 +080012619 /**
12620 * Sets the modem service class Name that Telephony will bind to.
12621 *
12622 * @param serviceName The class name of the modem service.
12623 * @return true if the operation is succeed, otherwise false.
12624 */
12625 public boolean setModemService(String serviceName) {
12626 Log.d(LOG_TAG, "setModemService - " + serviceName);
12627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012629 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12630 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012631 return mPhoneConfigurationManager.setModemService(serviceName);
12632 }
12633
12634 /**
12635 * Return the class name of the currently bounded modem service.
12636 *
12637 * @return the class name of the modem service.
12638 */
12639 public String getModemService() {
12640 String result;
12641 Log.d(LOG_TAG, "getModemService");
12642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12643 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012644 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012645 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12646 "getModemService");
12647 result = mPhoneConfigurationManager.getModemService();
12648 Log.d(LOG_TAG, "result = " + result);
12649 return result;
12650 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012651
Hakjun Choi3ee81112023-12-19 15:40:58 +000012652 /**
12653 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12654 * including carrier config, entitlement server, and config update.
12655 *
12656 * @param subId subId The subscription ID of the carrier.
12657 *
12658 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12659 * be returned.
12660 *
12661 * @throws SecurityException if the caller doesn't have the required permission.
12662 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012663 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12664 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012665 final long identity = Binder.clearCallingIdentity();
12666 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012667 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012668 } finally {
12669 Binder.restoreCallingIdentity(identity);
12670 }
12671 }
12672
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012673 @Override
12674 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12675 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12676 mApp.enforceCallingOrSelfPermission(
12677 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12678 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12679
12680 final long identity = Binder.clearCallingIdentity();
12681 try {
12682 Phone phone = getPhone(subId);
12683 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012684 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12685 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012686 phone.setVoiceServiceStateOverride(hasService);
12687 } finally {
12688 Binder.restoreCallingIdentity(identity);
12689 }
12690 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012691
12692 /**
12693 * set removable eSIM as default eUICC.
12694 *
12695 * @hide
12696 */
12697 @Override
12698 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12699 enforceModifyPermission();
12700 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12701
12702 final long identity = Binder.clearCallingIdentity();
12703 try {
12704 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12705 } finally {
12706 Binder.restoreCallingIdentity(identity);
12707 }
12708 }
12709
12710 /**
12711 * Returns whether the removable eSIM is default eUICC or not.
12712 *
12713 * @hide
12714 */
12715 @Override
12716 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12717 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12719
12720 final long identity = Binder.clearCallingIdentity();
12721 try {
12722 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12723 } finally {
12724 Binder.restoreCallingIdentity(identity);
12725 }
12726 }
12727
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012728 /**
12729 * Get the component name of the default app to direct respond-via-message intent for the
12730 * user associated with this subscription, update the cache if there is no respond-via-message
12731 * application currently configured for this user.
12732 * @return component name of the app and class to direct Respond Via Message intent to, or
12733 * {@code null} if the functionality is not supported.
12734 * @hide
12735 */
12736 @Override
12737 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12738 boolean updateIfNeeded) {
12739 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012740
joonhunshin4ac60942023-11-15 15:23:39 +000012741 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12742 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12743 "getDefaultRespondViaMessageApplication");
12744
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012745 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12746
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012747 UserHandle userHandle = null;
12748 final long identity = Binder.clearCallingIdentity();
12749 try {
12750 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12751 } finally {
12752 Binder.restoreCallingIdentity(identity);
12753 }
12754 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12755 updateIfNeeded, userHandle);
12756 }
Jack Yuf5badd92022-12-08 00:50:53 -080012757
12758 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012759 * Set whether the device is able to connect with null ciphering or integrity
12760 * algorithms. This is a global setting and will apply to all active subscriptions
12761 * and all new subscriptions after this.
12762 *
12763 * @param enabled when true, null cipher and integrity algorithms are allowed.
12764 * @hide
12765 */
12766 @Override
12767 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12768 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12769 enforceModifyPermission();
12770 checkForNullCipherAndIntegritySupport();
12771
12772 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12773 // for listening to these preference changes and applying them immediately.
12774 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12775 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12776 editor.apply();
12777
12778 for (Phone phone: PhoneFactory.getPhones()) {
12779 phone.handleNullCipherEnabledChange();
12780 }
12781 }
12782
12783
12784 /**
12785 * Get whether the device is able to connect with null ciphering or integrity
12786 * algorithms. Note that this retrieves the phone-global preference and not
12787 * the state of the radio.
12788 *
12789 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12790 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12791 * version for this feature.
12792 * @hide
12793 */
12794 @Override
12795 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12796 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12797 enforceReadPermission();
12798 checkForNullCipherAndIntegritySupport();
12799 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12800 }
12801
12802 private void checkForNullCipherAndIntegritySupport() {
12803 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12804 throw new UnsupportedOperationException(
12805 "Null cipher and integrity operations require HAL 2.1 or above");
12806 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012807 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12808 throw new UnsupportedOperationException(
12809 "Null cipher and integrity operations unsupported by modem");
12810 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012811 }
12812
Gil Cukierman06403e12023-11-29 16:33:03 +000012813 private void checkForIdentifierDisclosureNotificationSupport() {
12814 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12815 throw new UnsupportedOperationException(
12816 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12817 + "above");
12818 }
12819 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12820 throw new UnsupportedOperationException(
12821 "Cellular identifier disclosure transparency operations unsupported by modem");
12822 }
12823 }
12824
Michael Groover826b71d2023-12-21 22:08:06 -060012825 private void checkForNullCipherNotificationSupport() {
12826 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12827 throw new UnsupportedOperationException(
12828 "Null cipher notification operations require HAL 2.2 or above");
12829 }
12830 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12831 throw new UnsupportedOperationException(
12832 "Null cipher notification operations unsupported by modem");
12833 }
12834 }
12835
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012836 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012837 * Get the SIM state for the slot index.
12838 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12839 *
12840 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12841 */
12842 @Override
12843 @SimState
12844 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012845 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12846 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12847
Jack Yuf5badd92022-12-08 00:50:53 -080012848 IccCardConstants.State simState;
12849 if (slotIndex < 0) {
12850 simState = IccCardConstants.State.UNKNOWN;
12851 } else {
12852 Phone phone = null;
12853 try {
12854 phone = PhoneFactory.getPhone(slotIndex);
12855 } catch (IllegalStateException e) {
12856 // ignore
12857 }
12858 if (phone == null) {
12859 simState = IccCardConstants.State.UNKNOWN;
12860 } else {
12861 IccCard icc = phone.getIccCard();
12862 if (icc == null) {
12863 simState = IccCardConstants.State.UNKNOWN;
12864 } else {
12865 simState = icc.getState();
12866 }
12867 }
12868 }
12869 return simState.ordinal();
12870 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012871
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012872 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12873 boolean enableLogcat,
12874 long logcatStartTimestampMillis, boolean enableTelecomDump,
12875 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012876 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012877 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12878 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12879 ecdDataBuilder
12880 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12881 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012882 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012883 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012884 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012885 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12886 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012887 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12888 Executors.newCachedThreadPool(), db,
12889 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012890 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012891 }
12892
12893 /**
12894 * Request telephony to persist state for debugging emergency call failures.
12895 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012896 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012897 * @param enableLogcat whether to collect logcat output
12898 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12899 * @param enableTelecomDump whether to collect telecom dumpsys
12900 * @param enableTelephonyDump whether to collect telephony dumpsys
12901 */
12902 @Override
12903 @RequiresPermission(android.Manifest.permission.DUMP)
12904 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12905 long logcatStartTimestampMillis, boolean enableTelecomDump,
12906 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012907 // Verify that the caller has READ_DROPBOX_DATA permission.
12908 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12909 && Flags.enableReadDropboxPermission()) {
12910 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12911 "persistEmergencyCallDiagnosticData");
12912 } else {
12913 // Otherwise, enforce legacy permission.
12914 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12915 "persistEmergencyCallDiagnosticData");
12916 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012917 final long identity = Binder.clearCallingIdentity();
12918 try {
12919 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12920 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12921
12922 } finally {
12923 Binder.restoreCallingIdentity(identity);
12924 }
12925 }
12926
Hui Wang9b5793a2022-12-05 14:38:06 -060012927 /**
12928 * Get current cell broadcast ranges.
12929 */
12930 @Override
12931 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12932 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12933 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12934 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012935
12936 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12937 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12938
Hui Wang9b5793a2022-12-05 14:38:06 -060012939 final long identity = Binder.clearCallingIdentity();
12940 try {
12941 return getPhone(subId).getCellBroadcastIdRanges();
12942 } finally {
12943 Binder.restoreCallingIdentity(identity);
12944 }
12945 }
12946
12947 /**
12948 * Set reception of cell broadcast messages with the list of the given ranges
12949 *
12950 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12951 */
12952 @Override
12953 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12954 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12955 @Nullable IIntegerConsumer callback) {
12956 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12957 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012958
12959 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12960 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12961
Hui Wang9b5793a2022-12-05 14:38:06 -060012962 final long identity = Binder.clearCallingIdentity();
12963 try {
12964 Phone phone = getPhoneFromSubId(subId);
12965 if (DBG) {
12966 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12967 }
12968 phone.setCellBroadcastIdRanges(ranges, result -> {
12969 if (callback != null) {
12970 try {
12971 callback.accept(result);
12972 } catch (RemoteException e) {
12973 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12974 }
12975 }
12976 });
12977 } finally {
12978 Binder.restoreCallingIdentity(identity);
12979 }
12980 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012981
12982 /**
12983 * Returns whether the device supports the domain selection service.
12984 *
12985 * @return {@code true} if the device supports the domain selection service.
12986 */
12987 @Override
12988 public boolean isDomainSelectionSupported() {
12989 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12990 "isDomainSelectionSupported");
12991
12992 final long identity = Binder.clearCallingIdentity();
12993 try {
12994 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12995 } finally {
12996 Binder.restoreCallingIdentity(identity);
12997 }
12998 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012999
13000 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013001 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13002 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13003 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013004 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013005 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013006 * @param enableSatellite {@code true} to enable the satellite modem and
13007 * {@code false} to disable.
13008 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013009 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013010 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013011 *
13012 * @throws SecurityException if the caller doesn't have the required permission.
13013 */
13014 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013015 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013016 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013017 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013018 if (enableSatellite) {
13019 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13020 @Override
13021 protected void onReceiveResult(int resultCode, Bundle resultData) {
13022 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13023 + ", resultData=" + resultData);
13024 boolean isAllowed = false;
13025 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13026 callback::accept);
13027 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13028 if (resultData != null
13029 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13030 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13031 } else {
13032 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13033 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013034 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013035 result.accept(resultCode);
13036 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013037 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013038 if (isAllowed) {
13039 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013040 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013041 } else {
13042 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13043 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013044 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013045 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013046 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013047 subId, resultReceiver);
13048 } else {
13049 // No need to check if satellite is allowed at current location when disabling satellite
13050 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013051 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013052 }
Sarah Chin503828c2023-02-01 23:54:20 -080013053 }
13054
13055 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013056 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013057 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013058 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013059 * @param result The result receiver that returns whether the satellite modem is enabled
13060 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013061 *
13062 * @throws SecurityException if the caller doesn't have the required permission.
13063 */
13064 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013065 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13066 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013067 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013068 }
13069
13070 /**
Sarah Chin43457982023-02-15 17:50:38 -080013071 * Request to get whether the satellite service demo mode is enabled.
13072 *
13073 * @param subId The subId of the subscription to check whether the satellite demo mode
13074 * is enabled for.
13075 * @param result The result receiver that returns whether the satellite demo mode is enabled
13076 * if the request is successful or an error code if the request failed.
13077 *
13078 * @throws SecurityException if the caller doesn't have the required permission.
13079 */
13080 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013081 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13082 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13083 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013084 }
13085
13086 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013087 * Request to get whether the satellite service is enabled with emergency mode.
13088 *
13089 * @param subId The subId of the subscription to check whether the satellite demo mode
13090 * is enabled for.
13091 * @param result The result receiver that returns whether the satellite emergency mode is
13092 * enabled if the request is successful or an error code if the request failed.
13093 *
13094 * @throws SecurityException if the caller doesn't have the required permission.
13095 */
13096 @Override
13097 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13098 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13099 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13100 }
13101
13102 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013103 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013104 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013105 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013106 * @param result The result receiver that returns whether the satellite service is supported on
13107 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013108 */
13109 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013110 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013111 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013112 }
13113
13114 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013115 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013116 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013117 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013118 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13119 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013120 *
13121 * @throws SecurityException if the caller doesn't have required permission.
13122 */
13123 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013124 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13125 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013126 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013127 }
13128
13129 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013130 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013131 * This can be called by the pointing UI when the user starts pointing to the satellite.
13132 * Modem should continue to report the pointing input as the device or satellite moves.
13133 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013134 * @param subId The subId of the subscription to start satellite transmission updates for.
13135 * @param resultCallback The callback to get the result of the request.
13136 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013137 *
13138 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013139 */
13140 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013141 public void startSatelliteTransmissionUpdates(int subId,
13142 @NonNull IIntegerConsumer resultCallback,
13143 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13144 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13145 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013146 }
13147
13148 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013149 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013150 * This can be called by the pointing UI when the user stops pointing to the satellite.
13151 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013152 * @param subId The subId of the subscription to stop satellite transmission updates for.
13153 * @param resultCallback The callback to get the result of the request.
13154 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13155 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013156 *
13157 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013158 */
13159 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013160 public void stopSatelliteTransmissionUpdates(int subId,
13161 @NonNull IIntegerConsumer resultCallback,
13162 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13163 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13164 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013165 }
13166
13167 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013168 * Register the subscription with a satellite provider.
13169 * This is needed to register the subscription if the provider allows dynamic registration.
13170 *
13171 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013172 * @param token The token to be used as a unique identifier for provisioning with satellite
13173 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013174 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013175 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013176 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013177 * @return The signal transport used by the caller to cancel the provision request,
13178 * or {@code null} if the request failed.
13179 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013180 * @throws SecurityException if the caller doesn't have the required permission.
13181 */
13182 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013183 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013184 @NonNull String token, @NonNull byte[] provisionData,
13185 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013186 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013187 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13188 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013189 }
13190
13191 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013192 * Unregister the device/subscription with the satellite provider.
13193 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013194 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013195 * should report as deprovisioned.
13196 *
13197 * @param subId The subId of the subscription to be deprovisioned.
13198 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013199 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013200 *
13201 * @throws SecurityException if the caller doesn't have the required permission.
13202 */
13203 @Override
13204 public void deprovisionSatelliteService(int subId,
13205 @NonNull String token, @NonNull IIntegerConsumer callback) {
13206 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013207 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013208 }
13209
13210 /**
Sarah Chin43457982023-02-15 17:50:38 -080013211 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013212 *
Sarah Chin43457982023-02-15 17:50:38 -080013213 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013214 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013215 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013216 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013217 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013218 * @throws SecurityException if the caller doesn't have the required permission.
13219 */
13220 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013221 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13222 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013223 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013224 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013225 }
13226
13227 /**
Sarah Chin43457982023-02-15 17:50:38 -080013228 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013229 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013230 *
Sarah Chin43457982023-02-15 17:50:38 -080013231 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013232 * @param callback The callback that was passed to
13233 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013234 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013235 * @throws SecurityException if the caller doesn't have the required permission.
13236 */
13237 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013238 public void unregisterForSatelliteProvisionStateChanged(
13239 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013240 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013241 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013242 }
13243
13244 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013245 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013246 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013247 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013248 * @param result The result receiver that returns whether the device is provisioned with a
13249 * satellite provider if the request is successful or an error code if the
13250 * request failed.
13251 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013252 * @throws SecurityException if the caller doesn't have the required permission.
13253 */
13254 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013255 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13256 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013257 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013258 }
13259
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013260 /**
Sarah Chin43457982023-02-15 17:50:38 -080013261 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013262 *
Sarah Chin43457982023-02-15 17:50:38 -080013263 * @param subId The subId of the subscription to register for satellite modem state changed.
13264 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013265 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013266 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013267 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013268 * @throws SecurityException if the caller doesn't have the required permission.
13269 */
13270 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013271 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013272 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013273 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013274 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013275 }
13276
13277 /**
Sarah Chin43457982023-02-15 17:50:38 -080013278 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013279 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013280 *
Sarah Chin43457982023-02-15 17:50:38 -080013281 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013282 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013283 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013284 *
13285 * @throws SecurityException if the caller doesn't have the required permission.
13286 */
13287 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013288 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013289 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013290 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13291 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013292 }
13293
13294 /**
13295 * Register to receive incoming datagrams over satellite.
13296 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013297 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013298 * @param callback The callback to handle incoming datagrams over satellite.
13299 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013300 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013301 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013302 * @throws SecurityException if the caller doesn't have the required permission.
13303 */
13304 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013305 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013306 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013307 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13308 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013309 }
13310
13311 /**
13312 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013313 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013314 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013315 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13316 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013317 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013318 *
13319 * @throws SecurityException if the caller doesn't have the required permission.
13320 */
13321 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013322 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013323 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013324 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13325 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013326 }
13327
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013328 /**
13329 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013330 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013331 * This method requests modem to check if there are any pending datagrams to be received over
13332 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013333 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013334 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013335 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013336 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013337 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013338 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013339 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013340 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13341 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13342 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013343 }
13344
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013345 /**
13346 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013347 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013348 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13349 * input to this method. Datagram received here will be passed down to modem without any
13350 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013351 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013352 * @param subId The subId of the subscription to send satellite datagrams for.
13353 * @param datagramType datagram type indicating whether the datagram is of type
13354 * SOS_SMS or LOCATION_SHARING.
13355 * @param datagram encoded gateway datagram which is encrypted by the caller.
13356 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013357 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13358 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013359 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013360 *
13361 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013362 */
13363 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013364 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013365 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13366 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013367 enforceSatelliteCommunicationPermission("sendDatagram");
13368 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13369 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013370 }
13371
Sarah Chindf715ec2023-02-13 13:46:24 -080013372 /**
13373 * Request to get whether satellite communication is allowed for the current location.
13374 *
13375 * @param subId The subId of the subscription to check whether satellite communication is
13376 * allowed for the current location for.
13377 * @param result The result receiver that returns whether satellite communication is allowed
13378 * for the current location if the request is successful or an error code
13379 * if the request failed.
13380 *
13381 * @throws SecurityException if the caller doesn't have the required permission.
13382 */
13383 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013384 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013385 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013386 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13387 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13388 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013389 }
13390
13391 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013392 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013393 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013394 * @param subId The subId to get the time after which the satellite will be visible for.
13395 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013396 * be visible if the request is successful or an error code if the request failed.
13397 *
13398 * @throws SecurityException if the caller doesn't have the required permission.
13399 */
13400 @Override
13401 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13402 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013403 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013404 }
13405
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013406 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013407 * Inform that Device is aligned to satellite for demo mode.
13408 *
13409 * @param subId The subId to get the time after which the satellite will be visible for.
13410 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13411 * {@code false} Device fails to align with the satellite for demo mode.
13412 *
13413 * @throws SecurityException if the caller doesn't have required permission.
13414 */
13415 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13416
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013417 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013418 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013419 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013420 }
13421
13422 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013423 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13424 * by modem.
13425 *
13426 * @param subId The subId of the subscription to request for.
13427 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013428 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013429 * operation.
13430 *
13431 * @throws SecurityException if the caller doesn't have required permission.
13432 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013433 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013434 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13435 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013436 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013437 final long identity = Binder.clearCallingIdentity();
13438 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013439 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013440 } finally {
13441 Binder.restoreCallingIdentity(identity);
13442 }
13443 }
13444
13445 /**
13446 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13447 * by modem.
13448 *
13449 * @param subId The subId of the subscription to request for.
13450 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013451 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013452 * operation.
13453 *
13454 * @throws SecurityException if the caller doesn't have required permission.
13455 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013456 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013457 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13458 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013459 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013460 final long identity = Binder.clearCallingIdentity();
13461 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013462 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013463 } finally {
13464 Binder.restoreCallingIdentity(identity);
13465 }
13466 }
13467
13468 /**
13469 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013470 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013471 *
13472 * @param subId The subId of the subscription to request for.
13473 *
13474 * @return Integer array of reasons for disallowing satellite communication.
13475 *
13476 * @throws SecurityException if the caller doesn't have the required permission.
13477 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013478 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013479 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013480 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013481 final long identity = Binder.clearCallingIdentity();
13482 try {
13483 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013484 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013485 return reasonSet.stream().mapToInt(i->i).toArray();
13486 } finally {
13487 Binder.restoreCallingIdentity(identity);
13488 }
13489 }
13490
13491 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013492 * Request to get the signal strength of the satellite connection.
13493 *
13494 * @param subId The subId of the subscription to request for.
13495 * @param result Result receiver to get the error code of the request and the current signal
13496 * strength of the satellite connection.
13497 *
13498 * @throws SecurityException if the caller doesn't have required permission.
13499 */
13500 @Override
13501 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13502 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13503 final long identity = Binder.clearCallingIdentity();
13504 try {
13505 mSatelliteController.requestNtnSignalStrength(subId, result);
13506 } finally {
13507 Binder.restoreCallingIdentity(identity);
13508 }
13509 }
13510
13511 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013512 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13513 * is not successful, a {@link ServiceSpecificException} that contains
13514 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013515 *
13516 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013517 * @param callback The callback to handle the NTN signal strength changed event. If the
13518 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13519 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13520 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13521 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013522 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013523 * @throws SecurityException If the caller doesn't have the required permission.
13524 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013525 */
13526 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013527 public void registerForNtnSignalStrengthChanged(int subId,
13528 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013529 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13530 final long identity = Binder.clearCallingIdentity();
13531 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013532 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013533 } finally {
13534 Binder.restoreCallingIdentity(identity);
13535 }
13536 }
13537
13538 /**
13539 * Unregisters for NTN signal strength changed from satellite modem.
13540 * If callback was not registered before, the request will be ignored.
13541 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013542 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13543 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013544 * @param callback The callback that was passed to
13545 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13546 *
13547 * @throws SecurityException if the caller doesn't have the required permission.
13548 */
13549 @Override
13550 public void unregisterForNtnSignalStrengthChanged(
13551 int subId, @NonNull INtnSignalStrengthCallback callback) {
13552 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13553 final long identity = Binder.clearCallingIdentity();
13554 try {
13555 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13556 } finally {
13557 Binder.restoreCallingIdentity(identity);
13558 }
13559 }
13560
13561 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013562 * Registers for satellite capabilities change event from the satellite service.
13563 *
13564 * @param subId The subId of the subscription to request for.
13565 * @param callback The callback to handle the satellite capabilities changed event.
13566 *
13567 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13568 *
13569 * @throws SecurityException if the caller doesn't have required permission.
13570 */
13571 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013572 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013573 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013574 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013575 final long identity = Binder.clearCallingIdentity();
13576 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013577 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013578 } finally {
13579 Binder.restoreCallingIdentity(identity);
13580 }
13581 }
13582
13583 /**
13584 * Unregisters for satellite capabilities change event from the satellite service.
13585 * If callback was not registered before, the request will be ignored.
13586 *
13587 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13588 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013589 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013590 *
13591 * @throws SecurityException if the caller doesn't have required permission.
13592 */
13593 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013594 public void unregisterForCapabilitiesChanged(int subId,
13595 @NonNull ISatelliteCapabilitiesCallback callback) {
13596 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013597 final long identity = Binder.clearCallingIdentity();
13598 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013599 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013600 } finally {
13601 Binder.restoreCallingIdentity(identity);
13602 }
13603 }
13604
13605 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013606 * Registers for the satellite supported state changed.
13607 *
13608 * @param subId The subId of the subscription to register for supported state changed.
13609 * @param callback The callback to handle the satellite supported state changed event.
13610 *
13611 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13612 *
13613 * @throws SecurityException if the caller doesn't have the required permission.
13614 */
13615 @Override
13616 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13617 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13618 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13619 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13620 }
13621
13622 /**
13623 * Unregisters for the satellite supported state changed.
13624 * If callback was not registered before, the request will be ignored.
13625 *
13626 * @param subId The subId of the subscription to unregister for supported state changed.
13627 * @param callback The callback that was passed to
13628 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13629 *
13630 * @throws SecurityException if the caller doesn't have the required permission.
13631 */
13632 @Override
13633 public void unregisterForSatelliteSupportedStateChanged(
13634 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13635 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13636 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13637 }
13638
13639 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013640 * This API can be used by only CTS to update satellite vendor service package name.
13641 *
13642 * @param servicePackageName The package name of the satellite vendor service.
13643 * @return {@code true} if the satellite vendor service is set successfully,
13644 * {@code false} otherwise.
13645 */
13646 public boolean setSatelliteServicePackageName(String servicePackageName) {
13647 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13648 TelephonyPermissions.enforceShellOnly(
13649 Binder.getCallingUid(), "setSatelliteServicePackageName");
13650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13651 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13652 "setSatelliteServicePackageName");
13653 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13654 }
13655
13656 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013657 * This API can be used by only CTS to update satellite gateway service package name.
13658 *
13659 * @param servicePackageName The package name of the satellite gateway service.
13660 * @return {@code true} if the satellite gateway service is set successfully,
13661 * {@code false} otherwise.
13662 */
13663 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13664 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13665 TelephonyPermissions.enforceShellOnly(
13666 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13668 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13669 "setSatelliteGatewayServicePackageName");
13670 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13671 }
13672
13673 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013674 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13675 *
13676 * @param packageName The package name of the satellite pointing UI app.
13677 * @param className The class name of the satellite pointing UI app.
13678 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13679 * {@code false} otherwise.
13680 */
13681 public boolean setSatellitePointingUiClassName(
13682 @Nullable String packageName, @Nullable String className) {
13683 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13684 + ", className=" + className);
13685 TelephonyPermissions.enforceShellOnly(
13686 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13688 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13689 "setSatelliteGatewayServicePackageName");
13690 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13691 }
13692
13693 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013694 * This API can be used by only CTS to update the timeout duration in milliseconds that
13695 * satellite should stay at listening mode to wait for the next incoming page before disabling
13696 * listening mode.
13697 *
13698 * @param timeoutMillis The timeout duration in millisecond.
13699 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13700 */
13701 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13702 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13703 TelephonyPermissions.enforceShellOnly(
13704 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13706 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13707 "setSatelliteListeningTimeoutDuration");
13708 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13709 }
13710
13711 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013712 * This API can be used by only CTS to override the timeout durations used by the
13713 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013714 *
13715 * @param timeoutMillis The timeout duration in millisecond.
13716 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13717 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013718 public boolean setDatagramControllerTimeoutDuration(
13719 boolean reset, int timeoutType, long timeoutMillis) {
13720 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13721 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013722 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013723 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13725 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013726 "setDatagramControllerTimeoutDuration");
13727 return mSatelliteController.setDatagramControllerTimeoutDuration(
13728 reset, timeoutType, timeoutMillis);
13729 }
13730
13731 /**
13732 * This API can be used by only CTS to override the timeout durations used by the
13733 * SatelliteController module.
13734 *
13735 * @param timeoutMillis The timeout duration in millisecond.
13736 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13737 */
13738 public boolean setSatelliteControllerTimeoutDuration(
13739 boolean reset, int timeoutType, long timeoutMillis) {
13740 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13741 + reset + ", timeoutMillis=" + timeoutMillis);
13742 TelephonyPermissions.enforceShellOnly(
13743 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13745 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13746 "setSatelliteControllerTimeoutDuration");
13747 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13748 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013749 }
13750
13751 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013752 * This API can be used in only testing to override connectivity status in monitoring emergency
13753 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13754 *
13755 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13756 * of the following values to enable the override:
13757 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13758 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13759 * To disable the override, use -1 for handoverType.
13760 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13761 * delaySeconds after the emergency call starts.
13762 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13763 */
13764 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13765 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13766 TelephonyPermissions.enforceShellOnly(
13767 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13769 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13770 "setEmergencyCallToSatelliteHandoverType");
13771 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13772 handoverType, delaySeconds);
13773 }
13774
13775 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013776 * This API can be used in only testing to override oem-enabled satellite provision status.
13777 *
13778 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13779 * otherwise.
13780 * @param isProvisioned The overriding provision status.
13781 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13782 */
13783 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13784 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13785 + ", isProvisioned=" + isProvisioned);
13786 TelephonyPermissions.enforceShellOnly(
13787 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13789 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13790 "setOemEnabledSatelliteProvisionStatus");
13791 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13792 }
13793
13794 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013795 * This API should be used by only CTS tests to forcefully set telephony country codes.
13796 *
13797 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13798 */
13799 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13800 Map cachedNetworkCountryCodes, String locationCountryCode,
13801 long locationCountryCodeTimestampNanos) {
13802 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13803 + String.join(", ", currentNetworkCountryCodes)
13804 + ", locationCountryCode=" + locationCountryCode
13805 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13806 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13807 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13808 TelephonyPermissions.enforceShellOnly(
13809 Binder.getCallingUid(), "setCachedLocationCountryCode");
13810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13811 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13812 "setCachedLocationCountryCode");
13813 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13814 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13815 locationCountryCodeTimestampNanos);
13816 }
13817
13818 /**
13819 * This API should be used by only CTS tests to override the overlay configs of satellite
13820 * access controller.
13821 *
13822 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13823 * otherwise.
13824 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13825 */
13826 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13827 String s2CellFile, long locationFreshDurationNanos,
13828 List<String> satelliteCountryCodes) {
13829 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13830 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13831 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13832 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13833 ? String.join(", ", satelliteCountryCodes) : null));
13834 TelephonyPermissions.enforceShellOnly(
13835 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13837 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13838 "setSatelliteAccessControlOverlayConfigs");
13839 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13840 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13841 }
13842
13843 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013844 * This API can be used by only CTS to override the cached value for the device overlay config
13845 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13846 * outgoing satellite datagrams should be sent to modem in demo mode.
13847 *
13848 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13849 * satellite modem or not.
13850 *
13851 * @return {@code true} if the operation is successful, {@code false} otherwise.
13852 */
13853 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13854 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13855 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13856 + "disabled");
13857 return false;
13858 }
13859 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13860 TelephonyPermissions.enforceShellOnly(
13861 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13863 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13864 "setShouldSendDatagramToModemInDemoMode");
13865 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13866 shouldSendToModemInDemoMode);
13867 }
13868
13869 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013870 * Sets the service defined in ComponentName to be bound.
13871 *
13872 * This should only be used for testing.
13873 * @return {@code true} if the DomainSelectionService to bind to was set,
13874 * {@code false} otherwise.
13875 */
13876 @Override
13877 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13878 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13879
13880 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13881 "setDomainSelectionServiceOverride");
13882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13883 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13884
13885 final long identity = Binder.clearCallingIdentity();
13886 try {
13887 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13888 return DomainSelectionResolver.getInstance()
13889 .setDomainSelectionServiceOverride(componentName);
13890 }
13891 } finally {
13892 Binder.restoreCallingIdentity(identity);
13893 }
13894 return false;
13895 }
13896
13897 /**
13898 * Clears the DomainSelectionService override.
13899 *
13900 * This should only be used for testing.
13901 * @return {@code true} if the DomainSelectionService override was cleared,
13902 * {@code false} otherwise.
13903 */
13904 @Override
13905 public boolean clearDomainSelectionServiceOverride() {
13906 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13907
13908 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13909 "clearDomainSelectionServiceOverride");
13910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13911 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13912
13913 final long identity = Binder.clearCallingIdentity();
13914 try {
13915 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13916 return DomainSelectionResolver.getInstance()
13917 .clearDomainSelectionServiceOverride();
13918 }
13919 } finally {
13920 Binder.restoreCallingIdentity(identity);
13921 }
13922 return false;
13923 }
13924
13925 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013926 * Enable or disable notifications sent for cellular identifier disclosure events.
13927 *
13928 * Disclosure events are defined as instances where a device has sent a cellular identifier
13929 * on the Non-access stratum (NAS) before a security context is established. As a result the
13930 * identifier is sent in the clear, which has privacy implications for the user.
13931 *
13932 * @param enable if notifications about disclosure events should be enabled
13933 * @throws SecurityException if the caller does not have the required privileges
13934 * @throws UnsupportedOperationException if the modem does not support this feature.
13935 */
13936 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013937 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013938 enforceModifyPermission();
13939 checkForIdentifierDisclosureNotificationSupport();
13940
13941 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13942 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13943 editor.apply();
13944
13945 // Each phone instance is responsible for updating its respective modem immediately
13946 // after we've made a preference change.
13947 for (Phone phone : PhoneFactory.getPhones()) {
13948 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13949 }
13950 }
13951
13952 /**
13953 * Get whether or not cellular identifier disclosure notifications are enabled.
13954 *
13955 * @throws SecurityException if the caller does not have the required privileges
13956 * @throws UnsupportedOperationException if the modem does not support this feature.
13957 */
13958 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013959 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013960 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13961 checkForIdentifierDisclosureNotificationSupport();
13962 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13963 }
13964
13965 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013966 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13967 * are in use by the cellular modem.
13968 *
13969 * @throws IllegalStateException if the Telephony process is not currently available
13970 * @throws SecurityException if the caller does not have the required privileges
13971 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13972 * and integrity algorithms in use
13973 * @hide
13974 */
13975 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060013976 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060013977 enforceModifyPermission();
13978 checkForNullCipherNotificationSupport();
13979
13980 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13981 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
13982 editor.apply();
13983
13984 // Each phone instance is responsible for updating its respective modem immediately
13985 // after a preference change.
13986 for (Phone phone : PhoneFactory.getPhones()) {
13987 phone.handleNullCipherNotificationPreferenceChanged();
13988 }
13989 }
13990
13991 /**
13992 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
13993 * cellular modem.
13994 *
13995 * @throws IllegalStateException if the Telephony process is not currently available
13996 * @throws SecurityException if the caller does not have the required privileges
13997 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
13998 * and integrity algorithms in use
13999 * @hide
14000 */
14001 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14002 public boolean isNullCipherNotificationsEnabled() {
14003 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14004 checkForNullCipherNotificationSupport();
14005 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14006 }
14007
14008 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014009 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14010 *
14011 * <p>This method behaves in one of the following ways:
14012 * <ul>
14013 * <li>return true : if the calling package has the appop permission {@link
14014 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14015 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14016 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14017 * Owner device identifier access check, or the calling package has carrier privileges</>
14018 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14019 * </ul>
14020 */
14021 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14022 String callingPackage, @Nullable String callingFeatureId, String message) {
14023 for (Phone phone : PhoneFactory.getPhones()) {
14024 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14025 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14026 return true;
14027 }
14028 }
14029 return false;
14030 }
arunvoddud7401012022-12-15 16:08:12 +000014031
14032 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014033 * @return The subscription manager service instance.
14034 */
14035 public SubscriptionManagerService getSubscriptionManagerService() {
14036 return SubscriptionManagerService.getInstance();
14037 }
14038
14039 /**
arunvoddud7401012022-12-15 16:08:12 +000014040 * Class binds the consumer[callback] and carrierId.
14041 */
14042 private static class CallerCallbackInfo {
14043 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014044 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014045
Steve Statia28b7cb32024-03-11 23:58:50 +000014046 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014047 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014048 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014049 }
14050
14051 public Consumer<Integer> getConsumer() {
14052 return mConsumer;
14053 }
14054
Steve Statia28b7cb32024-03-11 23:58:50 +000014055 public Set<Integer> getCarrierIds() {
14056 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014057 }
14058 }
joonhunshin4ac60942023-11-15 15:23:39 +000014059
14060 /*
14061 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14062 * But the context that is passed in is unused if the phone app is already alive.
14063 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14064 */
14065 @VisibleForTesting
14066 public void setPackageManager(PackageManager packageManager) {
14067 mPackageManager = packageManager;
14068 }
14069
14070 /*
Nate Myren453c3472024-03-13 11:28:11 -070014071 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14072 * But the context that is passed in is unused if the phone app is already alive.
14073 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14074 */
14075 @VisibleForTesting
14076 public void setAppOpsManager(AppOpsManager appOps) {
14077 mAppOps = appOps;
14078 }
14079
14080 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014081 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14082 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14083 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14084 */
14085 @VisibleForTesting
14086 public void setFeatureFlags(FeatureFlags featureFlags) {
14087 mFeatureFlags = featureFlags;
14088 }
14089
14090 /**
14091 * Make sure the device has required telephony feature
14092 *
14093 * @throws UnsupportedOperationException if the device does not have required telephony feature
14094 */
14095 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14096 @NonNull String telephonyFeature, @NonNull String methodName) {
14097 if (callingPackage == null || mPackageManager == null) {
14098 return;
14099 }
14100
14101 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14102 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
14103 Binder.getCallingUserHandle())) {
14104 return;
14105 }
14106
14107 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14108 throw new UnsupportedOperationException(
14109 methodName + " is unsupported without " + telephonyFeature);
14110 }
14111 }
Jack Yufa8ed012023-02-11 15:42:28 -080014112}