blob: d95f33c4cc0e5d5f6cbfc586982e66789bcc7805 [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;
joonhunshinf624b2a2024-04-18 04:42:12 +000079import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070081import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070083import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070084import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080085import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070086import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000087import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090088import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080089import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080090import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070091import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080092import android.telephony.AccessNetworkConstants;
93import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070094import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070095import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080096import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070097import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080098import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070099import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -0800100import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600101import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700102import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800103import android.telephony.CellIdentityCdma;
104import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700106import android.telephony.CellInfoGsm;
107import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700108import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800109import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700110import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700111import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700112import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800113import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700114import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800115import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700116import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800117import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800118import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700119import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800120import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800122import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800123import android.telephony.SignalStrengthUpdateRequest;
124import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800125import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800127import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700128import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700129import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800130import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800131import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800132import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800133import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000134import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000135import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000136import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700137import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700138import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800139import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800140import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700141import android.telephony.gba.GbaAuthRequest;
142import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700143import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800144import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000145import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000146import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700147import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000148import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700149import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800150import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700151import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800152import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700153import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000154import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700155import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800156import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800157import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000158import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000159import android.telephony.satellite.ISatelliteCapabilitiesCallback;
youngtaecha5d483d52024-04-29 17:05:45 +0000160import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800161import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000162import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800163import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000164import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800165import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000166import android.telephony.satellite.NtnSignalStrength;
167import android.telephony.satellite.NtnSignalStrengthCallback;
Hyosun Kim8bac3be2024-06-28 13:35:30 +0000168import android.telephony.satellite.ProvisionSubscriberId;
Sarah Chin503828c2023-02-01 23:54:20 -0800169import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000170import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800171import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800172import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800173import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800175import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700176import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800178import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800179
Andrew Lee312e8172014-10-23 17:01:36 -0700180import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800181import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800182import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800183import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800184import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700186import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700187import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800188import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800189import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700190import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800192import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700193import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800194import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800195import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800196import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700197import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000198import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700199import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800200import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800202import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800203import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800204import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700205import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700206import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700207import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700209import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800210import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700211import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700212import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700213import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700214import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800215import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800216import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700217import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000218import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700219import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700220import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800221import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800222import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800223import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700224import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000225import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800226import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700227import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700228import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800229import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700230import com.android.internal.telephony.imsphone.ImsPhone;
231import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000232import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800233import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000234import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800235import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
236import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700237import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700238import com.android.internal.telephony.uicc.IccIoResult;
239import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700241import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800242import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700243import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000244import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800245import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000246import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800247import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000248import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700249import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700250import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800251import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800252import com.android.phone.callcomposer.CallComposerPictureManager;
253import com.android.phone.callcomposer.CallComposerPictureTransfer;
254import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800255import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000256import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700257import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700258import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000259import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700260import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800261import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700262import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700263import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800264import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800265import com.android.services.telephony.TelecomAccountRegistry;
266import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000267import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800268import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800269
Hall Liu82694d52020-12-11 18:22:04 -0800270import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700271import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800272import java.io.IOException;
273import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700274import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800276import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000277import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800278import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800279import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800280import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800281import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100282import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800283import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700284import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800285import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800286import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700287import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800288import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800289import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800290import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
292/**
293 * Implementation of the ITelephony interface.
294 */
Santos Cordon117fee72014-05-16 17:56:12 -0700295public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 private static final String LOG_TAG = "PhoneInterfaceManager";
297 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
298 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800299 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300
301 // Message codes used with mMainThreadHandler
302 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700303 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
304 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700305 private static final int CMD_OPEN_CHANNEL = 9;
306 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
307 private static final int CMD_CLOSE_CHANNEL = 11;
308 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800309 private static final int CMD_NV_READ_ITEM = 13;
310 private static final int EVENT_NV_READ_ITEM_DONE = 14;
311 private static final int CMD_NV_WRITE_ITEM = 15;
312 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
313 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
314 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700315 private static final int CMD_RESET_MODEM_CONFIG = 19;
316 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800317 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
318 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800319 private static final int CMD_SEND_ENVELOPE = 25;
320 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700321 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
322 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
323 private static final int CMD_EXCHANGE_SIM_IO = 31;
324 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800325 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
326 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700327 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
328 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700329 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
330 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700331 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
332 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
333 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
334 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700335 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
336 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
337 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
338 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700339 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800340 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
341 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000342 private static final int CMD_SWITCH_SLOTS = 50;
343 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700344 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
345 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
346 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
347 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
348 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
349 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
350 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
351 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700352 private static final int CMD_GET_ALL_CELL_INFO = 60;
353 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
354 private static final int CMD_GET_CELL_LOCATION = 62;
355 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700356 private static final int CMD_MODEM_REBOOT = 64;
357 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700358 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
359 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800360 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
361 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700362 private static final int CMD_GET_MODEM_STATUS = 70;
363 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700364 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
365 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700366 private static final int CMD_ERASE_MODEM_CONFIG = 74;
367 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800368 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
369 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
370 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
371 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800372 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
373 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800374 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800375 private static final int CMD_GET_CALL_FORWARDING = 83;
376 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
377 private static final int CMD_SET_CALL_FORWARDING = 85;
378 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
379 private static final int CMD_GET_CALL_WAITING = 87;
380 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
381 private static final int CMD_SET_CALL_WAITING = 89;
382 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700383 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
384 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
385 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
386 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700387 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
388 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800389 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
390 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800391 private static final int CMD_SET_DATA_THROTTLING = 99;
392 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800393 private static final int CMD_SET_SIM_POWER = 101;
394 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800395 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
396 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
397 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
398 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800399 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
400 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000401 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800402 private static final int CMD_GET_SLICING_CONFIG = 110;
403 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800404 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700405 private static final int CMD_ENABLE_VONR = 113;
406 private static final int EVENT_ENABLE_VONR_DONE = 114;
407 private static final int CMD_IS_VONR_ENABLED = 115;
408 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700409 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
410 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000411
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800412 // Parameters of select command.
413 private static final int SELECT_COMMAND = 0xA4;
414 private static final int SELECT_P1 = 0x04;
415 private static final int SELECT_P2 = 0;
416 private static final int SELECT_P3 = 0x10;
417
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000418 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
419 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000420 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
421 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600422 // Null cipher notification support was added in IRadioNetwork 2.2
423 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000424
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 /** The singleton instance. */
426 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800427 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428
Sarah Chin4beb2b72023-02-14 14:47:54 -0800429 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000430 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800431 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800432 private final CallManager mCM;
433 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000434
435 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800436 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800437 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800439 private final SharedPreferences mTelephonySharedPreferences;
440 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800441 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700442 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000443 private PackageManager mPackageManager;
joonhunshinf624b2a2024-04-18 04:42:12 +0000444 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Peter Wangdafb9ac2020-01-15 14:13:38 -0800446 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800447 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800448 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800449 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800450
Derek Tan97ebb422014-09-05 16:55:38 -0700451 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
452 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800453 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800454 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700455
Michelecea4cf22018-12-21 15:00:11 -0800456 // String to store multi SIM allowed
457 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
458
Derek Tan740e1672017-06-27 14:56:27 -0700459 // The AID of ISD-R.
460 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
461
yinxub1bed742017-04-17 11:45:04 -0700462 private NetworkScanRequestTracker mNetworkScanRequestTracker;
463
David Kelly5e06a7f2018-03-12 14:10:59 +0000464 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
465 private static final int MANUFACTURER_CODE_LENGTH = 8;
466
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800467 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800468 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800469
Sarah Chin2ec39f62022-08-31 17:03:26 -0700470 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
471 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
472
Derek Tan89e89d42014-07-08 17:00:10 -0700473 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700474 * Experiment flag to enable erase modem config on reset network, default value is false
475 */
476 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
477 "reset_network_erase_modem_config_enabled";
478
Rambo Wang0f050d82021-02-12 11:43:36 -0800479 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800480
Gary Jian76280a42022-12-07 16:18:33 +0800481 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
482
sandeepjsb6c87872021-09-27 15:34:44 +0000483 /**
484 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
485 * one ICCID active at the same time.
486 * Apps should use below API signatures if targeting SDK is T and beyond.
487 *
488 * @hide
489 */
490 @ChangeId
491 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
492 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800493
Naina Nallurid63128d2019-09-17 14:10:30 -0700494 /**
Chen Xu540470b2021-12-14 17:15:47 -0800495 * Apps targeting on Android T and beyond will get exception whenever icc close channel
496 * operation fails.
497 */
498 @ChangeId
499 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
500 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
501
502 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 * A request object to use for transmitting data to an ICC.
504 */
505 private static final class IccAPDUArgument {
506 public int channel, cla, command, p1, p2, p3;
507 public String data;
508
509 public IccAPDUArgument(int channel, int cla, int command,
510 int p1, int p2, int p3, String data) {
511 this.channel = channel;
512 this.cla = cla;
513 this.command = command;
514 this.p1 = p1;
515 this.p2 = p2;
516 this.p3 = p3;
517 this.data = data;
518 }
519 }
520
521 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700522 * A request object to use for transmitting data to an ICC.
523 */
524 private static final class ManualNetworkSelectionArgument {
525 public OperatorInfo operatorInfo;
526 public boolean persistSelection;
527
528 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
529 this.operatorInfo = operatorInfo;
530 this.persistSelection = persistSelection;
531 }
532 }
533
Sarah Chin71b3a852022-09-28 15:54:19 -0700534 private static final class PurchasePremiumCapabilityArgument {
535 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700536 public @NonNull IIntegerConsumer callback;
537
538 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800539 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700540 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700541 this.callback = callback;
542 }
543 }
544
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700545 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
547 * request after sending. The main thread will notify the request when it is complete.
548 */
549 private static final class MainThreadRequest {
550 /** The argument to use for the request */
551 public Object argument;
552 /** The result of the request that is run on the main thread */
553 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800554 // The subscriber id that this request applies to. Defaults to
555 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
556 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700557
Nathan Harold92bed182018-10-12 18:16:49 -0700558 // In cases where subId is unavailable, the caller needs to specify the phone.
559 public Phone phone;
560
vagdeviaf9a5b92018-08-15 16:01:53 -0700561 public WorkSource workSource;
562
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700563 public MainThreadRequest(Object argument) {
564 this.argument = argument;
565 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800566
Nathan Harold92bed182018-10-12 18:16:49 -0700567 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
568 this.argument = argument;
569 if (phone != null) {
570 this.phone = phone;
571 }
572 this.workSource = workSource;
573 }
574
vagdeviaf9a5b92018-08-15 16:01:53 -0700575 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800576 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800577 if (subId != null) {
578 this.subId = subId;
579 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700580 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 }
583
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800584 private static final class IncomingThirdPartyCallArgs {
585 public final ComponentName component;
586 public final String callId;
587 public final String callerDisplayName;
588
589 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
590 String callerDisplayName) {
591 this.component = component;
592 this.callId = callId;
593 this.callerDisplayName = callerDisplayName;
594 }
595 }
596
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700597 /**
598 * A handler that processes messages on the main thread in the phone process. Since many
599 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
600 * inbound binder threads to the main thread in the phone process. The Binder thread
601 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
602 * on, which will be notified when the operation completes and will contain the result of the
603 * request.
604 *
605 * <p>If a MainThreadRequest object is provided in the msg.obj field,
606 * note that request.result must be set to something non-null for the calling thread to
607 * unblock.
608 */
609 private final class MainThreadHandler extends Handler {
610 @Override
611 public void handleMessage(Message msg) {
612 MainThreadRequest request;
613 Message onCompleted;
614 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000615 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800617 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700618
619 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 case CMD_HANDLE_USSD_REQUEST: {
621 request = (MainThreadRequest) msg.obj;
622 final Phone phone = getPhoneFromRequest(request);
623 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800624 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700626
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 if (!isUssdApiAllowed(request.subId)) {
628 // Carrier does not support use of this API, return failure.
629 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
630 UssdResponse response = new UssdResponse(ussdRequest, null);
631 Bundle returnData = new Bundle();
632 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
633 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700634
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 request.result = true;
636 notifyRequester(request);
637 return;
638 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700639
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 try {
641 request.result = phone != null
642 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
643 } catch (CallStateException cse) {
644 request.result = false;
645 }
646 // Wake up the requesting thread
647 notifyRequester(request);
648 break;
pkanwar32d516d2016-10-14 19:37:38 -0700649 }
650
Yorke Lee716f67e2015-06-17 15:39:16 -0700651 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700652 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700653 final Phone phone = getPhoneFromRequest(request);
654 request.result = phone != null ?
655 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
656 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700657 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700659 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000665 uiccPort = getUiccPortFromRequest(request);
666 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700667 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800668 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700670 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800672 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000673 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800674 iccArgument.channel, iccArgument.cla, iccArgument.command,
675 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
676 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 break;
679
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 ar = (AsyncResult) msg.obj;
682 request = (MainThreadRequest) ar.userObj;
683 if (ar.exception == null && ar.result != null) {
684 request.result = ar.result;
685 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800686 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 if (ar.result == null) {
688 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800689 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800691 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 } else {
693 loge("iccTransmitApduLogicalChannel: Unknown exception");
694 }
695 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 break;
698
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
700 request = (MainThreadRequest) msg.obj;
701 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000702 uiccPort = getUiccPortFromRequest(request);
703 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800705 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 } else {
708 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800709 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000710 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800711 iccArgument.cla, iccArgument.command, iccArgument.p1,
712 iccArgument.p2,
713 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700714 }
715 break;
716
717 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
718 ar = (AsyncResult) msg.obj;
719 request = (MainThreadRequest) ar.userObj;
720 if (ar.exception == null && ar.result != null) {
721 request.result = ar.result;
722 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800723 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 if (ar.result == null) {
725 loge("iccTransmitApduBasicChannel: Empty response");
726 } else if (ar.exception instanceof CommandException) {
727 loge("iccTransmitApduBasicChannel: CommandException: " +
728 ar.exception);
729 } else {
730 loge("iccTransmitApduBasicChannel: Unknown exception");
731 }
732 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 break;
735
736 case CMD_EXCHANGE_SIM_IO:
737 request = (MainThreadRequest) msg.obj;
738 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000739 uiccPort = getUiccPortFromRequest(request);
740 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800742 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 } else {
745 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
746 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000747 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700748 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
749 iccArgument.data, onCompleted);
750 }
751 break;
752
753 case EVENT_EXCHANGE_SIM_IO_DONE:
754 ar = (AsyncResult) msg.obj;
755 request = (MainThreadRequest) ar.userObj;
756 if (ar.exception == null && ar.result != null) {
757 request.result = ar.result;
758 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800759 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700760 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700761 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 break;
763
Derek Tan4d5e5c12014-02-04 11:54:58 -0800764 case CMD_SEND_ENVELOPE:
765 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000766 uiccPort = getUiccPortFromRequest(request);
767 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700768 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800769 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700771 } else {
772 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800773 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700774 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800775 break;
776
777 case EVENT_SEND_ENVELOPE_DONE:
778 ar = (AsyncResult) msg.obj;
779 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700780 if (ar.exception == null && ar.result != null) {
781 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800782 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800783 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700784 if (ar.result == null) {
785 loge("sendEnvelopeWithStatus: Empty response");
786 } else if (ar.exception instanceof CommandException) {
787 loge("sendEnvelopeWithStatus: CommandException: " +
788 ar.exception);
789 } else {
790 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
791 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800792 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700793 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800794 break;
795
Shishir Agrawal566b7612013-10-28 14:41:00 -0700796 case CMD_OPEN_CHANNEL:
797 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000798 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800799 IccLogicalChannelRequest openChannelRequest =
800 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000801 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700802 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800803 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800804 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700805 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700806 } else {
807 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800808 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
809 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700810 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700811 break;
812
813 case EVENT_OPEN_CHANNEL_DONE:
814 ar = (AsyncResult) msg.obj;
815 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700816 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700817 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700818 int[] result = (int[]) ar.result;
819 int channelId = result[0];
820 byte[] selectResponse = null;
821 if (result.length > 1) {
822 selectResponse = new byte[result.length - 1];
823 for (int i = 1; i < result.length; ++i) {
824 selectResponse[i - 1] = (byte) result[i];
825 }
826 }
827 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800828 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800829
830 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700831 if (uiccPort == null) {
832 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
833 } else {
834 IccLogicalChannelRequest channelRequest =
835 (IccLogicalChannelRequest) request.argument;
836 channelRequest.channel = channelId;
837 uiccPort.onLogicalChannelOpened(channelRequest);
838 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700840 if (ar.result == null) {
841 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700842 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700843 if (ar.exception != null) {
844 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
845 }
846
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700847 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700848 if (ar.exception instanceof CommandException) {
849 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800850 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700851 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700852 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700853 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700854 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700855 }
856 }
857 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800858 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700859 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700860 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700861 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700862 break;
863
864 case CMD_CLOSE_CHANNEL:
865 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000866 uiccPort = getUiccPortFromRequest(request);
867 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700868 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800869 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800870 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800871 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700872 } else {
873 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000874 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700875 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700876 break;
877
878 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800879 ar = (AsyncResult) msg.obj;
880 request = (MainThreadRequest) ar.userObj;
881 if (ar.exception == null) {
882 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800883 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700884 if (uiccPort == null) {
885 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
886 } else {
887 final int channelId = (Integer) request.argument;
888 uiccPort.onLogicalChannelClosed(channelId);
889 }
Chen Xu540470b2021-12-14 17:15:47 -0800890 } else {
891 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800892 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800893 if (ar.exception instanceof CommandException) {
894 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
895 CommandException.Error error =
896 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800897 if (error == CommandException.Error.INVALID_ARGUMENTS) {
898 // should only throw exceptions from the binder threads.
899 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800900 "iccCloseLogicalChannel: invalid argument ");
901 }
902 } else {
903 loge("iccCloseLogicalChannel: Unknown exception");
904 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800905 request.result = (exception != null) ? exception :
906 new IllegalStateException(
907 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800908 }
909 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800910 break;
911
912 case CMD_NV_READ_ITEM:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800915 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
916 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800917 break;
918
919 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700920 ar = (AsyncResult) msg.obj;
921 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800922 if (ar.exception == null && ar.result != null) {
923 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700924 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800925 request.result = "";
926 if (ar.result == null) {
927 loge("nvReadItem: Empty response");
928 } else if (ar.exception instanceof CommandException) {
929 loge("nvReadItem: CommandException: " +
930 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700931 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800932 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700933 }
934 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700935 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700936 break;
937
Jake Hambye994d462014-02-03 13:10:13 -0800938 case CMD_NV_WRITE_ITEM:
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
941 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800942 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700943 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800944 break;
945
946 case EVENT_NV_WRITE_ITEM_DONE:
947 handleNullReturnEvent(msg, "nvWriteItem");
948 break;
949
950 case CMD_NV_WRITE_CDMA_PRL:
951 request = (MainThreadRequest) msg.obj;
952 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800953 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800954 break;
955
956 case EVENT_NV_WRITE_CDMA_PRL_DONE:
957 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
958 break;
959
chen xu6dac5ab2018-10-26 17:39:23 -0700960 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800961 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700962 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800963 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800964 break;
965
chen xu6dac5ab2018-10-26 17:39:23 -0700966 case EVENT_RESET_MODEM_CONFIG_DONE:
967 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800968 break;
969
Sooraj Sasindran37444802020-08-11 10:40:43 -0700970 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
973 request);
974 Phone phone = getPhoneFromRequest(request);
975 if (phone != null) {
976 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
977 } else {
978 loge("isNRDualConnectivityEnabled: No phone object");
979 request.result = false;
980 notifyRequester(request);
981 }
982 break;
983 }
984
985 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
988 if (ar.exception == null && ar.result != null) {
989 request.result = ar.result;
990 } else {
991 // request.result must be set to something non-null
992 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700993 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700994 request.result = ar.result;
995 } else {
996 request.result = false;
997 }
998 if (ar.result == null) {
999 loge("isNRDualConnectivityEnabled: Empty response");
1000 } else if (ar.exception instanceof CommandException) {
1001 loge("isNRDualConnectivityEnabled: CommandException: "
1002 + ar.exception);
1003 } else {
1004 loge("isNRDualConnectivityEnabled: Unknown exception");
1005 }
1006 }
1007 notifyRequester(request);
1008 break;
1009
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001010 case CMD_IS_VONR_ENABLED: {
1011 request = (MainThreadRequest) msg.obj;
1012 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1013 request);
1014 Phone phone = getPhoneFromRequest(request);
1015 if (phone != null) {
1016 phone.isVoNrEnabled(onCompleted, request.workSource);
1017 } else {
1018 loge("isVoNrEnabled: No phone object");
1019 request.result = false;
1020 notifyRequester(request);
1021 }
1022 break;
1023 }
1024
1025 case EVENT_IS_VONR_ENABLED_DONE:
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 if (ar.exception == null && ar.result != null) {
1029 request.result = ar.result;
1030 } else {
1031 // request.result must be set to something non-null
1032 // for the calling thread to unblock
1033 if (ar.result != null) {
1034 request.result = ar.result;
1035 } else {
1036 request.result = false;
1037 }
1038 if (ar.result == null) {
1039 loge("isVoNrEnabled: Empty response");
1040 } else if (ar.exception instanceof CommandException) {
1041 loge("isVoNrEnabled: CommandException: "
1042 + ar.exception);
1043 } else {
1044 loge("isVoNrEnabled: Unknown exception");
1045 }
1046 }
1047 notifyRequester(request);
1048 break;
1049
Sooraj Sasindran37444802020-08-11 10:40:43 -07001050 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1053 Phone phone = getPhoneFromRequest(request);
1054 if (phone != null) {
1055 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1056 request.workSource);
1057 } else {
1058 loge("enableNrDualConnectivity: No phone object");
1059 request.result =
1060 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1061 notifyRequester(request);
1062 }
1063 break;
1064 }
1065
1066 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 if (ar.exception == null) {
1070 request.result =
1071 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1072 } else {
1073 request.result =
1074 TelephonyManager
1075 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1076 if (ar.exception instanceof CommandException) {
1077 CommandException.Error error =
1078 ((CommandException) (ar.exception)).getCommandError();
1079 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1080 request.result =
1081 TelephonyManager
1082 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001083 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1084 request.result =
1085 TelephonyManager
1086 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001087 }
1088 loge("enableNrDualConnectivity" + ": CommandException: "
1089 + ar.exception);
1090 } else {
1091 loge("enableNrDualConnectivity" + ": Unknown exception");
1092 }
1093 }
1094 notifyRequester(request);
1095 break;
1096 }
1097
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001098 case CMD_ENABLE_VONR: {
1099 request = (MainThreadRequest) msg.obj;
1100 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1101 Phone phone = getPhoneFromRequest(request);
1102 if (phone != null) {
1103 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1104 request.workSource);
1105 } else {
1106 loge("setVoNrEnabled: No phone object");
1107 request.result =
1108 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1109 notifyRequester(request);
1110 }
1111 break;
1112 }
1113
1114 case EVENT_ENABLE_VONR_DONE: {
1115 ar = (AsyncResult) msg.obj;
1116 request = (MainThreadRequest) ar.userObj;
1117 if (ar.exception == null) {
1118 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1119 } else {
1120 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1121 if (ar.exception instanceof CommandException) {
1122 CommandException.Error error =
1123 ((CommandException) (ar.exception)).getCommandError();
1124 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1125 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1126 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1127 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1128 } else {
1129 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1130 }
1131 loge("setVoNrEnabled" + ": CommandException: "
1132 + ar.exception);
1133 } else {
1134 loge("setVoNrEnabled" + ": Unknown exception");
1135 }
1136 }
1137 notifyRequester(request);
1138 break;
1139 }
1140
SongFerngWang3ef3e072020-12-21 16:41:52 +08001141 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001142 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001143 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1144 request);
1145 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001146 break;
1147
SongFerngWang3ef3e072020-12-21 16:41:52 +08001148 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001149 ar = (AsyncResult) msg.obj;
1150 request = (MainThreadRequest) ar.userObj;
1151 if (ar.exception == null && ar.result != null) {
1152 request.result = ar.result; // Integer
1153 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301154 // request.result must be set to something non-null
1155 // for the calling thread to unblock
1156 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001157 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001158 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001159 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001160 loge("getAllowedNetworkTypesBitmask: CommandException: "
1161 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001162 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001163 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001164 }
1165 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001166 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001167 break;
1168
SongFerngWang3ef3e072020-12-21 16:41:52 +08001169 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001170 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001171 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1172 request);
1173 Pair<Integer, Long> reasonWithNetworkTypes =
1174 (Pair<Integer, Long>) request.argument;
1175 getPhoneFromRequest(request).setAllowedNetworkTypes(
1176 reasonWithNetworkTypes.first,
1177 reasonWithNetworkTypes.second,
1178 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001179 break;
1180
SongFerngWang3ef3e072020-12-21 16:41:52 +08001181 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1182 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001183 break;
1184
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001185 case CMD_SET_VOICEMAIL_NUMBER:
1186 request = (MainThreadRequest) msg.obj;
1187 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1188 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001189 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1190 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001191 break;
1192
1193 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1194 handleNullReturnEvent(msg, "setVoicemailNumber");
1195 break;
1196
Stuart Scott54788802015-03-30 13:18:01 -07001197 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1198 request = (MainThreadRequest) msg.obj;
1199 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1200 request);
1201 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1202 break;
1203
1204 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1205 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1206 break;
1207
Shishir Agrawal302c8692015-06-19 13:49:39 -07001208 case CMD_PERFORM_NETWORK_SCAN:
1209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1211 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1212 break;
1213
Hall Liu27d24262020-09-18 19:04:59 -07001214 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001215 request = (MainThreadRequest) msg.obj;
1216 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001217 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1218 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1219 request.argument;
1220 int callForwardingReason = args.first;
1221 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001222 break;
Hall Liu27d24262020-09-18 19:04:59 -07001223 }
1224 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001225 ar = (AsyncResult) msg.obj;
1226 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001227 TelephonyManager.CallForwardingInfoCallback callback =
1228 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1229 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001230 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001231 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001232 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1233 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1234 // Service Class is a bit mask per 3gpp 27.007. Search for
1235 // any service for voice call.
1236 if ((callForwardInfo.serviceClass
1237 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001238 callForwardingInfo = new CallForwardingInfo(
1239 callForwardInfo.status
1240 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001241 callForwardInfo.reason,
1242 callForwardInfo.number,
1243 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001244 break;
1245 }
1246 }
1247 // Didn't find a call forward info for voice call.
1248 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001249 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1250 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001251 }
Hall Liu27d24262020-09-18 19:04:59 -07001252 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001253 } else {
1254 if (ar.result == null) {
1255 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1256 }
1257 if (ar.exception != null) {
1258 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1259 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001260 int errorCode = TelephonyManager
1261 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001262 if (ar.exception instanceof CommandException) {
1263 CommandException.Error error =
1264 ((CommandException) (ar.exception)).getCommandError();
1265 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001266 errorCode = TelephonyManager
1267 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001268 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001269 errorCode = TelephonyManager
1270 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001271 }
1272 }
Hall Liu27d24262020-09-18 19:04:59 -07001273 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001274 }
Shuo Qian4a594052020-01-23 11:59:30 -08001275 break;
Hall Liu27d24262020-09-18 19:04:59 -07001276 }
Shuo Qian4a594052020-01-23 11:59:30 -08001277
Hall Liu27d24262020-09-18 19:04:59 -07001278 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001279 request = (MainThreadRequest) msg.obj;
1280 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001281 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001282 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001283 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1284 request.argument).first;
1285 request.phone.setCallForwardingOption(
1286 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001287 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001288 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001289 callForwardingInfoToSet.getReason(),
1290 callForwardingInfoToSet.getNumber(),
1291 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1292 break;
Hall Liu27d24262020-09-18 19:04:59 -07001293 }
Shuo Qian4a594052020-01-23 11:59:30 -08001294
Hall Liu27d24262020-09-18 19:04:59 -07001295 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001296 ar = (AsyncResult) msg.obj;
1297 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001298 Consumer<Integer> callback =
1299 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1300 request.argument).second;
1301 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001302 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001303 int errorCode = TelephonyManager.CallForwardingInfoCallback
1304 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001305 if (ar.exception instanceof CommandException) {
1306 CommandException.Error error =
1307 ((CommandException) (ar.exception)).getCommandError();
1308 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001309 errorCode = TelephonyManager.CallForwardingInfoCallback
1310 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001311 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001312 errorCode = TelephonyManager.CallForwardingInfoCallback
1313 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001314 }
1315 }
1316 callback.accept(errorCode);
1317 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001318 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001319 }
Shuo Qian4a594052020-01-23 11:59:30 -08001320 break;
Hall Liu27d24262020-09-18 19:04:59 -07001321 }
Shuo Qian4a594052020-01-23 11:59:30 -08001322
Hall Liu27d24262020-09-18 19:04:59 -07001323 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001324 request = (MainThreadRequest) msg.obj;
1325 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1326 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1327 break;
Hall Liu27d24262020-09-18 19:04:59 -07001328 }
Shuo Qian4a594052020-01-23 11:59:30 -08001329
Hall Liu27d24262020-09-18 19:04:59 -07001330 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001331 ar = (AsyncResult) msg.obj;
1332 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001333 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001334 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001335 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001336 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001337 // Service Class is a bit mask per 3gpp 27.007.
1338 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001339 if (callForwardResults.length > 1
1340 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001341 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001342 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001343 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1344 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001345 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001346 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001347 }
1348 } else {
1349 if (ar.result == null) {
1350 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1351 }
1352 if (ar.exception != null) {
1353 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1354 }
1355 if (ar.exception instanceof CommandException) {
1356 CommandException.Error error =
1357 ((CommandException) (ar.exception)).getCommandError();
1358 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001359 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001360 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001361 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1362 callWaitingStatus =
1363 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001364 }
1365 }
1366 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001367 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001368 break;
Hall Liu27d24262020-09-18 19:04:59 -07001369 }
Shuo Qian4a594052020-01-23 11:59:30 -08001370
Hall Liu27d24262020-09-18 19:04:59 -07001371 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001372 request = (MainThreadRequest) msg.obj;
1373 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001374 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1375 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001376 break;
Hall Liu27d24262020-09-18 19:04:59 -07001377 }
Shuo Qian4a594052020-01-23 11:59:30 -08001378
Hall Liu27d24262020-09-18 19:04:59 -07001379 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001380 ar = (AsyncResult) msg.obj;
1381 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001382 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1383 Consumer<Integer> callback =
1384 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1385 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001386 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001387 if (ar.exception instanceof CommandException) {
1388 CommandException.Error error =
1389 ((CommandException) (ar.exception)).getCommandError();
1390 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1391 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001392 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1393 callback.accept(
1394 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001395 } else {
1396 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1397 }
1398 } else {
1399 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1400 }
1401 } else {
1402 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1403 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001404 }
Shuo Qian4a594052020-01-23 11:59:30 -08001405 break;
Hall Liu27d24262020-09-18 19:04:59 -07001406 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001407 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1408 ar = (AsyncResult) msg.obj;
1409 request = (MainThreadRequest) ar.userObj;
1410 CellNetworkScanResult cellScanResult;
1411 if (ar.exception == null && ar.result != null) {
1412 cellScanResult = new CellNetworkScanResult(
1413 CellNetworkScanResult.STATUS_SUCCESS,
1414 (List<OperatorInfo>) ar.result);
1415 } else {
1416 if (ar.result == null) {
1417 loge("getCellNetworkScanResults: Empty response");
1418 }
1419 if (ar.exception != null) {
1420 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1421 }
1422 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1423 if (ar.exception instanceof CommandException) {
1424 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001425 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001426 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1427 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1428 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1429 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1430 }
1431 }
1432 cellScanResult = new CellNetworkScanResult(errorCode, null);
1433 }
1434 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001435 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001436 break;
1437
1438 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1439 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001440 ManualNetworkSelectionArgument selArg =
1441 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001442 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1443 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001444 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1445 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001446 break;
1447
1448 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 if (ar.exception == null) {
1452 request.result = true;
1453 } else {
1454 request.result = false;
1455 loge("setNetworkSelectionModeManual " + ar.exception);
1456 }
1457 notifyRequester(request);
1458 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001459 break;
1460
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001461 case CMD_GET_MODEM_ACTIVITY_INFO:
1462 request = (MainThreadRequest) msg.obj;
1463 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001464 if (defaultPhone != null) {
1465 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001466 } else {
1467 ResultReceiver result = (ResultReceiver) request.argument;
1468 Bundle bundle = new Bundle();
1469 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001470 new ModemActivityInfo(0, 0, 0,
1471 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001472 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001473 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001474 break;
1475
Hall Liud0f208c2020-10-14 16:54:44 -07001476 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001477 ar = (AsyncResult) msg.obj;
1478 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001479 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001480 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001481 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001482 if (mLastModemActivityInfo == null) {
1483 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1484 mLastModemActivitySpecificInfo[0] =
1485 new ActivityStatsTechSpecificInfo(
1486 0,
1487 0,
1488 new int[ModemActivityInfo.getNumTxPowerLevels()],
1489 0);
1490 mLastModemActivityInfo =
1491 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1492 }
1493
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001494 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001495 // Update the last modem activity info and the result of the request.
1496 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1497 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001498 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001499 } else {
1500 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001501 }
Kai Shi917fdc62022-11-28 14:01:02 -08001502 // This is needed to decouple ret from mLastModemActivityInfo
1503 // We don't want to return mLastModemActivityInfo which is updated
1504 // inside mergeModemActivityInfo()
1505 ret = new ModemActivityInfo(
1506 mLastModemActivityInfo.getTimestampMillis(),
1507 mLastModemActivityInfo.getSleepTimeMillis(),
1508 mLastModemActivityInfo.getIdleTimeMillis(),
1509 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001510
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001511 } else {
1512 if (ar.result == null) {
1513 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001514 error = TelephonyManager.ModemActivityInfoException
1515 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001516 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001517 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001518 error = TelephonyManager.ModemActivityInfoException
1519 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001520 } else {
1521 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001522 error = TelephonyManager.ModemActivityInfoException
1523 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001524 }
1525 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001526 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001527 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001528 bundle.putParcelable(
1529 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001530 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001531 } else {
1532 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1533 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001534 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001535 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001536 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001537 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001538
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001539 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001540 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001541 CarrierRestrictionRules argument =
1542 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001543 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001544 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001546 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001547
1548 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1549 ar = (AsyncResult) msg.obj;
1550 request = (MainThreadRequest) ar.userObj;
1551 if (ar.exception == null && ar.result != null) {
1552 request.result = ar.result;
1553 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001554 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1555 if (ar.exception instanceof CommandException) {
1556 loge("setAllowedCarriers: CommandException: " + ar.exception);
1557 CommandException.Error error =
1558 ((CommandException) (ar.exception)).getCommandError();
1559 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1560 request.result =
1561 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1562 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001563 } else {
1564 loge("setAllowedCarriers: Unknown exception");
1565 }
1566 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001567 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001568 break;
1569
1570 case CMD_GET_ALLOWED_CARRIERS:
1571 request = (MainThreadRequest) msg.obj;
1572 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001573 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001574 break;
1575
1576 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 if (ar.exception == null && ar.result != null) {
1580 request.result = ar.result;
1581 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001582 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001583 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001584 if (ar.result == null) {
1585 loge("getAllowedCarriers: Empty response");
1586 } else if (ar.exception instanceof CommandException) {
1587 loge("getAllowedCarriers: CommandException: " +
1588 ar.exception);
1589 } else {
1590 loge("getAllowedCarriers: Unknown exception");
1591 }
1592 }
arunvoddud7401012022-12-15 16:08:12 +00001593 if (request.argument != null) {
1594 // This is for the implementation of carrierRestrictionStatus.
1595 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1596 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001597 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001598 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1599 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1600 CarrierRestrictionRules carrierRestrictionRules =
1601 (CarrierRestrictionRules) ar.result;
1602 int carrierId = -1;
1603 try {
1604 CarrierIdentifier carrierIdentifier =
1605 carrierRestrictionRules.getAllowedCarriers().get(0);
1606 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1607 carrierIdentifier);
1608 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1609 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1610 }
1611 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001612 int restrictedStatus =
1613 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1614 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1615 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001616 lockStatus = TelephonyManager
1617 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001618 }
1619 } else {
1620 Rlog.e(LOG_TAG,
1621 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1622 }
1623 callback.accept(lockStatus);
1624 } else {
1625 // This is for the implementation of getAllowedCarriers.
1626 notifyRequester(request);
1627 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001628 break;
1629
Nathan Haroldb3014052017-01-25 15:57:32 -08001630 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 if (ar.exception == null && ar.result != null) {
1634 request.result = ar.result;
1635 } else {
1636 request.result = new IllegalArgumentException(
1637 "Failed to retrieve Forbidden Plmns");
1638 if (ar.result == null) {
1639 loge("getForbiddenPlmns: Empty response");
1640 } else {
1641 loge("getForbiddenPlmns: Unknown exception");
1642 }
1643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001644 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001645 break;
1646
1647 case CMD_GET_FORBIDDEN_PLMNS:
1648 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001649 uiccPort = getUiccPortFromRequest(request);
1650 if (uiccPort == null) {
1651 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001652 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001653 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001654 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001655 break;
1656 }
1657 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001658 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001659 if (uiccApp == null) {
1660 loge("getForbiddenPlmns() no app with specified type -- "
1661 + appType);
1662 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001663 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001664 break;
1665 } else {
1666 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1667 + " specified type -- " + appType);
1668 }
1669 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1670 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001671 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001672 break;
1673
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001674 case CMD_SWITCH_SLOTS:
1675 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001676 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001677 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001678 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001679 break;
1680
1681 case EVENT_SWITCH_SLOTS_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001685 notifyRequester(request);
1686 break;
1687 case CMD_GET_NETWORK_SELECTION_MODE:
1688 request = (MainThreadRequest) msg.obj;
1689 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1690 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1691 break;
1692
1693 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1694 ar = (AsyncResult) msg.obj;
1695 request = (MainThreadRequest) ar.userObj;
1696 if (ar.exception != null) {
1697 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1698 } else {
1699 int mode = ((int[]) ar.result)[0];
1700 if (mode == 0) {
1701 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1702 } else {
1703 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1704 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001706 notifyRequester(request);
1707 break;
1708 case CMD_GET_CDMA_ROAMING_MODE:
1709 request = (MainThreadRequest) msg.obj;
1710 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1711 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1712 break;
1713 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 if (ar.exception != null) {
1717 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1718 } else {
1719 request.result = ((int[]) ar.result)[0];
1720 }
1721 notifyRequester(request);
1722 break;
1723 case CMD_SET_CDMA_ROAMING_MODE:
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1726 int mode = (int) request.argument;
1727 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1728 break;
1729 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1730 ar = (AsyncResult) msg.obj;
1731 request = (MainThreadRequest) ar.userObj;
1732 request.result = ar.exception == null;
1733 notifyRequester(request);
1734 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001735 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1736 request = (MainThreadRequest) msg.obj;
1737 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1738 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1739 break;
1740 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
1743 if (ar.exception != null) {
1744 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1745 } else {
1746 request.result = ((int[]) ar.result)[0];
1747 }
1748 notifyRequester(request);
1749 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001750 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1751 request = (MainThreadRequest) msg.obj;
1752 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1753 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001754 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1755 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001756 break;
1757 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1758 ar = (AsyncResult) msg.obj;
1759 request = (MainThreadRequest) ar.userObj;
1760 request.result = ar.exception == null;
1761 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001762 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001763 case CMD_GET_ALL_CELL_INFO:
1764 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001765 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001766 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001767 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001768 case EVENT_GET_ALL_CELL_INFO_DONE:
1769 ar = (AsyncResult) msg.obj;
1770 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001771 // If a timeout occurs, the response will be null
1772 request.result = (ar.exception == null && ar.result != null)
1773 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001774 synchronized (request) {
1775 request.notifyAll();
1776 }
1777 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001778 case CMD_REQUEST_CELL_INFO_UPDATE:
1779 request = (MainThreadRequest) msg.obj;
1780 request.phone.requestCellInfoUpdate(request.workSource,
1781 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1782 break;
1783 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1784 ar = (AsyncResult) msg.obj;
1785 request = (MainThreadRequest) ar.userObj;
1786 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1787 try {
1788 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001789 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001790 cb.onError(
1791 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1792 ar.exception.getClass().getName(),
1793 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001794 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001795 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001796 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001797 } else {
1798 // use the result as returned
1799 cb.onCellInfo((List<CellInfo>) ar.result);
1800 }
1801 } catch (RemoteException re) {
1802 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1803 }
1804 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001805 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001806 request = (MainThreadRequest) msg.obj;
1807 WorkSource ws = (WorkSource) request.argument;
1808 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001809 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001810 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001811 }
1812 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001813 ar = (AsyncResult) msg.obj;
1814 request = (MainThreadRequest) ar.userObj;
1815 if (ar.exception == null) {
1816 request.result = ar.result;
1817 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001818 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001819 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001820 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001821 }
1822
1823 synchronized (request) {
1824 request.notifyAll();
1825 }
1826 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001827 }
chen xu6dac5ab2018-10-26 17:39:23 -07001828 case CMD_MODEM_REBOOT:
1829 request = (MainThreadRequest) msg.obj;
1830 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001831 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001832 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001833 case EVENT_CMD_MODEM_REBOOT_DONE:
1834 handleNullReturnEvent(msg, "rebootModem");
1835 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001836 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001837 request = (MainThreadRequest) msg.obj;
1838 boolean enable = (boolean) request.argument;
1839 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001840 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001841 PhoneConfigurationManager.getInstance()
1842 .enablePhone(request.phone, enable, onCompleted);
1843 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001844 }
Michele Berionne5e411512020-11-13 02:36:59 +00001845 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001846 ar = (AsyncResult) msg.obj;
1847 request = (MainThreadRequest) ar.userObj;
1848 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001849 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001850 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001851 if ((boolean) request.result) {
1852 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1853 updateModemStateMetrics();
1854 } else {
1855 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1856 + ar.exception);
1857 }
1858 notifyRequester(request);
1859 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001860 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001861 case CMD_GET_MODEM_STATUS:
1862 request = (MainThreadRequest) msg.obj;
1863 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1864 PhoneConfigurationManager.getInstance()
1865 .getPhoneStatusFromModem(request.phone, onCompleted);
1866 break;
1867 case EVENT_GET_MODEM_STATUS_DONE:
1868 ar = (AsyncResult) msg.obj;
1869 request = (MainThreadRequest) ar.userObj;
1870 int id = request.phone.getPhoneId();
1871 if (ar.exception == null && ar.result != null) {
1872 request.result = ar.result;
1873 //update the cache as modem status has changed
1874 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1875 (boolean) request.result);
1876 } else {
1877 // Return true if modem status cannot be retrieved. For most cases,
1878 // modem status is on. And for older version modems, GET_MODEM_STATUS
1879 // and disable modem are not supported. Modem is always on.
1880 // TODO: this should be fixed in R to support a third
1881 // status UNKNOWN b/131631629
1882 request.result = true;
1883 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1884 + ar.exception);
1885 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001886 notifyRequester(request);
1887 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001888 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1889 request = (MainThreadRequest) msg.obj;
1890 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1891 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1892 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1893 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1894 break;
1895 }
1896 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1897 ar = (AsyncResult) msg.obj;
1898 request = (MainThreadRequest) ar.userObj;
1899 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1900 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1901 args.second.accept(ar.exception == null);
1902 notifyRequester(request);
1903 break;
1904 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001905 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1906 request = (MainThreadRequest) msg.obj;
1907 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1908 Phone phone = getPhoneFromRequest(request);
1909 if (phone != null) {
1910 phone.getSystemSelectionChannels(onCompleted);
1911 } else {
1912 loge("getSystemSelectionChannels: No phone object");
1913 request.result = new ArrayList<RadioAccessSpecifier>();
1914 notifyRequester(request);
1915 }
1916 break;
1917 }
1918 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1919 ar = (AsyncResult) msg.obj;
1920 request = (MainThreadRequest) ar.userObj;
1921 if (ar.exception == null && ar.result != null) {
1922 request.result = ar.result;
1923 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001924 request.result = new IllegalStateException(
1925 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001926 if (ar.result == null) {
1927 loge("getSystemSelectionChannels: Empty response");
1928 } else {
1929 loge("getSystemSelectionChannels: Unknown exception");
1930 }
1931 }
1932 notifyRequester(request);
1933 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001934 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1935 ar = (AsyncResult) msg.obj;
1936 request = (MainThreadRequest) ar.userObj;
1937 if (ar.exception == null && ar.result != null) {
1938 request.result = ar.result;
1939 } else {
1940 request.result = -1;
1941 loge("Failed to set Forbidden Plmns");
1942 if (ar.result == null) {
1943 loge("setForbidenPlmns: Empty response");
1944 } else if (ar.exception != null) {
1945 loge("setForbiddenPlmns: Exception: " + ar.exception);
1946 request.result = -1;
1947 } else {
1948 loge("setForbiddenPlmns: Unknown exception");
1949 }
1950 }
1951 notifyRequester(request);
1952 break;
1953 case CMD_SET_FORBIDDEN_PLMNS:
1954 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001955 uiccPort = getUiccPortFromRequest(request);
1956 if (uiccPort == null) {
1957 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001958 request.result = -1;
1959 notifyRequester(request);
1960 break;
1961 }
1962 Pair<Integer, List<String>> setFplmnsArgs =
1963 (Pair<Integer, List<String>>) request.argument;
1964 appType = setFplmnsArgs.first;
1965 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001966 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001967 if (uiccApp == null) {
1968 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1969 request.result = -1;
1970 loge("Failed to get UICC App");
1971 notifyRequester(request);
1972 } else {
1973 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1974 ((SIMRecords) uiccApp.getIccRecords())
1975 .setForbiddenPlmns(onCompleted, fplmns);
1976 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001977 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001978 case CMD_ERASE_MODEM_CONFIG:
1979 request = (MainThreadRequest) msg.obj;
1980 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1981 defaultPhone.eraseModemConfig(onCompleted);
1982 break;
1983 case EVENT_ERASE_MODEM_CONFIG_DONE:
1984 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001985 break;
zoey chene02881a2019-12-30 16:11:23 +08001986
Kai Shif70f46f2021-03-03 13:59:46 -08001987 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1988 request = (MainThreadRequest) msg.obj;
1989 request.result = defaultPhone.eraseDataInSharedPreferences();
1990 notifyRequester(request);
1991 break;
1992
zoey chene02881a2019-12-30 16:11:23 +08001993 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1994 request = (MainThreadRequest) msg.obj;
1995 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1996 Pair<String, String> changed = (Pair<String, String>) request.argument;
1997 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1998 changed.first, changed.second, onCompleted);
1999 break;
2000 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2001 ar = (AsyncResult) msg.obj;
2002 request = (MainThreadRequest) ar.userObj;
2003 if (ar.exception == null) {
2004 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002005 // If the operation is successful, update the PIN storage
2006 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2007 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002008 UiccController.getInstance().getPinStorage()
2009 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002010 } else {
2011 request.result = msg.arg1;
2012 }
2013 notifyRequester(request);
2014 break;
2015
Michele Berionne5e411512020-11-13 02:36:59 +00002016 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002017 request = (MainThreadRequest) msg.obj;
2018 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2019 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2020 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2021 enabled.first, enabled.second, onCompleted);
2022 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002023 }
zoey chene02881a2019-12-30 16:11:23 +08002024 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2025 ar = (AsyncResult) msg.obj;
2026 request = (MainThreadRequest) ar.userObj;
2027 if (ar.exception == null) {
2028 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002029 // If the operation is successful, update the PIN storage
2030 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2031 int phoneId = getPhoneFromRequest(request).getPhoneId();
2032 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002033 UiccController.getInstance().getPinStorage()
2034 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002035 } else {
2036 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2037 }
zoey chene02881a2019-12-30 16:11:23 +08002038 } else {
2039 request.result = msg.arg1;
2040 }
Michele Berionne5e411512020-11-13 02:36:59 +00002041
2042
zoey chene02881a2019-12-30 16:11:23 +08002043 notifyRequester(request);
2044 break;
2045
Peter Wangdafb9ac2020-01-15 14:13:38 -08002046 case MSG_NOTIFY_USER_ACTIVITY:
2047 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002048 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002049 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2050 getDefaultPhone().getContext().sendBroadcastAsUser(
2051 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2052 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002053
2054 case CMD_SET_DATA_THROTTLING: {
2055 request = (MainThreadRequest) msg.obj;
2056 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2057 DataThrottlingRequest dataThrottlingRequest =
2058 (DataThrottlingRequest) request.argument;
2059 Phone phone = getPhoneFromRequest(request);
2060 if (phone != null) {
2061 phone.setDataThrottling(onCompleted,
2062 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2063 dataThrottlingRequest.getCompletionDurationMillis());
2064 } else {
2065 loge("setDataThrottling: No phone object");
2066 request.result =
2067 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2068 notifyRequester(request);
2069 }
2070
2071 break;
2072 }
2073 case EVENT_SET_DATA_THROTTLING_DONE:
2074 ar = (AsyncResult) msg.obj;
2075 request = (MainThreadRequest) ar.userObj;
2076
2077 if (ar.exception == null) {
2078 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2079 } else if (ar.exception instanceof CommandException) {
2080 loge("setDataThrottling: CommandException: " + ar.exception);
2081 CommandException.Error error =
2082 ((CommandException) (ar.exception)).getCommandError();
2083
2084 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2085 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002086 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002087 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2088 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002089 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2090 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002091 } else {
2092 request.result =
2093 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2094 }
2095 } else {
2096 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2097 }
2098 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2099 notifyRequester(request);
2100 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002101
2102 case CMD_SET_SIM_POWER: {
2103 request = (MainThreadRequest) msg.obj;
2104 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2105 request = (MainThreadRequest) msg.obj;
2106 int stateToSet =
2107 ((Pair<Integer, IIntegerConsumer>)
2108 request.argument).first;
2109 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2110 break;
2111 }
2112 case EVENT_SET_SIM_POWER_DONE: {
2113 ar = (AsyncResult) msg.obj;
2114 request = (MainThreadRequest) ar.userObj;
2115 IIntegerConsumer callback =
2116 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2117 if (ar.exception != null) {
2118 loge("setSimPower exception: " + ar.exception);
2119 int errorCode = TelephonyManager.CallForwardingInfoCallback
2120 .RESULT_ERROR_UNKNOWN;
2121 if (ar.exception instanceof CommandException) {
2122 CommandException.Error error =
2123 ((CommandException) (ar.exception)).getCommandError();
2124 if (error == CommandException.Error.SIM_ERR) {
2125 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2126 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2127 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2128 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2129 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2130 } else {
2131 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2132 }
2133 }
2134 try {
2135 callback.accept(errorCode);
2136 } catch (RemoteException e) {
2137 // Ignore if the remote process is no longer available to call back.
2138 Log.w(LOG_TAG, "setSimPower: callback not available.");
2139 }
2140 } else {
2141 try {
2142 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2143 } catch (RemoteException e) {
2144 // Ignore if the remote process is no longer available to call back.
2145 Log.w(LOG_TAG, "setSimPower: callback not available.");
2146 }
2147 }
2148 break;
2149 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002150 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2151 request = (MainThreadRequest) msg.obj;
2152
2153 final Phone phone = getPhoneFromRequest(request);
2154 if (phone == null || phone.getServiceStateTracker() == null) {
2155 request.result = new IllegalStateException("Phone or SST is null");
2156 notifyRequester(request);
2157 break;
2158 }
2159
2160 Pair<Integer, SignalStrengthUpdateRequest> pair =
2161 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2162 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2163 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002164 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002165 request.subId, pair.first /*callingUid*/,
2166 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002167 break;
2168 }
2169 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2170 ar = (AsyncResult) msg.obj;
2171 request = (MainThreadRequest) ar.userObj;
2172 // request.result will be the exception of ar if present, true otherwise.
2173 // Be cautious not to leave result null which will wait() forever
2174 request.result = ar.exception != null ? ar.exception : true;
2175 notifyRequester(request);
2176 break;
2177 }
2178 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2179 request = (MainThreadRequest) msg.obj;
2180
2181 Phone phone = getPhoneFromRequest(request);
2182 if (phone == null || phone.getServiceStateTracker() == null) {
2183 request.result = new IllegalStateException("Phone or SST is null");
2184 notifyRequester(request);
2185 break;
2186 }
2187
2188 Pair<Integer, SignalStrengthUpdateRequest> pair =
2189 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2190 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2191 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002192 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002193 request.subId, pair.first /*callingUid*/,
2194 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002195 break;
2196 }
2197 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2198 ar = (AsyncResult) msg.obj;
2199 request = (MainThreadRequest) ar.userObj;
2200 request.result = ar.exception != null ? ar.exception : true;
2201 notifyRequester(request);
2202 break;
2203 }
Jordan Liu109698e2020-11-24 14:50:34 -08002204
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002205 case CMD_GET_SLICING_CONFIG: {
2206 request = (MainThreadRequest) msg.obj;
2207 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2208 request.phone.getSlicingConfig(onCompleted);
2209 break;
2210 }
2211 case EVENT_GET_SLICING_CONFIG_DONE: {
2212 ar = (AsyncResult) msg.obj;
2213 request = (MainThreadRequest) ar.userObj;
2214 ResultReceiver result = (ResultReceiver) request.argument;
2215
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002216 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002217 Bundle bundle = new Bundle();
2218 int resultCode = 0;
2219 if (ar.exception != null) {
2220 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2221 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002222 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002223 } else if (ar.result == null) {
2224 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002225 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002226 } else {
2227 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002228 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2229 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002230 }
2231
2232 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002233 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002234 }
2235 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2236 result.send(resultCode, bundle);
2237 notifyRequester(request);
2238 break;
2239 }
2240
Sarah Chin71b3a852022-09-28 15:54:19 -07002241 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242 request = (MainThreadRequest) msg.obj;
2243 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002244 PurchasePremiumCapabilityArgument arg =
2245 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002246 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2247 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002249 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002250
Sarah Chin71b3a852022-09-28 15:54:19 -07002251 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002252 ar = (AsyncResult) msg.obj;
2253 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002254 PurchasePremiumCapabilityArgument arg =
2255 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002256 try {
2257 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002258 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002259 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002260 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002261 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002262 + TelephonyManager.convertPurchaseResultToString(result));
2263 } catch (RemoteException e) {
2264 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002265 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002266 + " failed: " + e;
2267 if (DBG) log(logStr);
2268 AnomalyReporter.reportAnomaly(
2269 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2270 }
2271 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002272 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002273
Michele Berionne5e411512020-11-13 02:36:59 +00002274 case CMD_PREPARE_UNATTENDED_REBOOT:
2275 request = (MainThreadRequest) msg.obj;
2276 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002277 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002278 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002279 notifyRequester(request);
2280 break;
2281
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 default:
2283 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2284 break;
2285 }
2286 }
Jake Hambye994d462014-02-03 13:10:13 -08002287
Pengquan Menga1bb6272018-09-06 09:59:22 -07002288 private void notifyRequester(MainThreadRequest request) {
2289 synchronized (request) {
2290 request.notifyAll();
2291 }
2292 }
2293
Jake Hambye994d462014-02-03 13:10:13 -08002294 private void handleNullReturnEvent(Message msg, String command) {
2295 AsyncResult ar = (AsyncResult) msg.obj;
2296 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2297 if (ar.exception == null) {
2298 request.result = true;
2299 } else {
2300 request.result = false;
2301 if (ar.exception instanceof CommandException) {
2302 loge(command + ": CommandException: " + ar.exception);
2303 } else {
2304 loge(command + ": Unknown exception");
2305 }
2306 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002307 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 }
2310
2311 /**
2312 * Posts the specified command to be executed on the main thread,
2313 * waits for the request to complete, and returns the result.
2314 * @see #sendRequestAsync
2315 */
2316 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002317 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2318 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002319 }
2320
2321 /**
2322 * Posts the specified command to be executed on the main thread,
2323 * waits for the request to complete, and returns the result.
2324 * @see #sendRequestAsync
2325 */
2326 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2327 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002328 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002329 }
2330
2331 /**
2332 * Posts the specified command to be executed on the main thread,
2333 * waits for the request to complete, and returns the result.
2334 * @see #sendRequestAsync
2335 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002336 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002337 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2338 }
2339
2340 /**
2341 * Posts the specified command to be executed on the main thread,
2342 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2343 * if not timeout or null otherwise.
2344 * @see #sendRequestAsync
2345 */
2346 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2347 long timeoutInMs) {
2348 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002349 }
2350
2351 /**
2352 * Posts the specified command to be executed on the main thread,
2353 * waits for the request to complete, and returns the result.
2354 * @see #sendRequestAsync
2355 */
Nathan Harold92bed182018-10-12 18:16:49 -07002356 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002357 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002358 }
2359
2360 /**
2361 * Posts the specified command to be executed on the main thread,
2362 * waits for the request to complete, and returns the result.
2363 * @see #sendRequestAsync
2364 */
2365 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002366 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2367 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002368 }
2369
2370 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002371 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2372 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2373 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002374 * @see #sendRequestAsync
2375 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002376 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2377 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2379 throw new RuntimeException("This method will deadlock if called from the main thread.");
2380 }
2381
Nathan Harold92bed182018-10-12 18:16:49 -07002382 MainThreadRequest request = null;
2383 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2384 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2385 } else if (phone != null) {
2386 request = new MainThreadRequest(argument, phone, workSource);
2387 } else {
2388 request = new MainThreadRequest(argument, subId, workSource);
2389 }
2390
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 Message msg = mMainThreadHandler.obtainMessage(command, request);
2392 msg.sendToTarget();
2393
Rambo Wang0f050d82021-02-12 11:43:36 -08002394
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002396 if (timeoutInMs >= 0) {
2397 // Wait for at least timeoutInMs before returning null request result
2398 long now = SystemClock.elapsedRealtime();
2399 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002400 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002401 try {
2402 request.wait(deadline - now);
2403 } catch (InterruptedException e) {
2404 // Do nothing, go back and check if request is completed or timeout
2405 } finally {
2406 now = SystemClock.elapsedRealtime();
2407 }
2408 }
2409 } else {
2410 // Wait for the request to complete
2411 while (request.result == null) {
2412 try {
2413 request.wait();
2414 } catch (InterruptedException e) {
2415 // Do nothing, go back and wait until the request is complete
2416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 }
2418 }
2419 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002420 if (request.result == null) {
2421 Log.wtf(LOG_TAG,
2422 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 return request.result;
2425 }
2426
2427 /**
2428 * Asynchronous ("fire and forget") version of sendRequest():
2429 * Posts the specified command to be executed on the main thread, and
2430 * returns immediately.
2431 * @see #sendRequest
2432 */
2433 private void sendRequestAsync(int command) {
2434 mMainThreadHandler.sendEmptyMessage(command);
2435 }
2436
2437 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002438 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002439 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002440 */
2441 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002442 sendRequestAsync(command, argument, null, null);
2443 }
2444
2445 /**
2446 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2447 * @see {@link #sendRequest(int,Object)}
2448 */
2449 private void sendRequestAsync(
2450 int command, Object argument, Phone phone, WorkSource workSource) {
2451 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002452 Message msg = mMainThreadHandler.obtainMessage(command, request);
2453 msg.sendToTarget();
2454 }
2455
2456 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 * Initialize the singleton PhoneInterfaceManager instance.
2458 * This is only done once, at startup, from PhoneApp.onCreate().
2459 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002460 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 synchronized (PhoneInterfaceManager.class) {
2462 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002463 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 } else {
2465 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2466 }
2467 return sInstance;
2468 }
2469 }
2470
2471 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002472 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002474 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002475 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002477 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002478 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002479 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2481 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002482 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002483 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002484 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002485 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002486 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002487 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002488 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2489 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002490 mVendorApiLevel = SystemProperties.getInt(
2491 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2492
Tyler Gunn64144d92022-03-17 14:16:41 -07002493 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002494 publish();
arunvoddud7401012022-12-15 16:08:12 +00002495 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002496
2497 // Create the SatelliteEntitlementController singleton, for using the get the
2498 // entitlementStatus for satellite service.
2499 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002502 @VisibleForTesting
2503 public SharedPreferences getSharedPreferences() {
2504 return mTelephonySharedPreferences;
2505 }
2506
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002507 /**
2508 * Get the default phone for this device.
2509 */
2510 @VisibleForTesting
2511 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002512 Phone thePhone = getPhone(getDefaultSubscription());
2513 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2514 }
2515
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 private void publish() {
2517 if (DBG) log("publish: " + this);
2518
Peter Wangc035ce42020-01-08 21:00:22 -08002519 TelephonyFrameworkInitializer
2520 .getTelephonyServiceManager()
2521 .getTelephonyServiceRegisterer()
2522 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 }
2524
Stuart Scott584921c2015-01-15 17:10:34 -08002525 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002526 if (request.phone != null) {
2527 return request.phone;
2528 } else {
2529 return getPhoneFromSubId(request.subId);
2530 }
2531 }
2532
2533 private Phone getPhoneFromSubId(int subId) {
2534 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2535 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002536 }
2537
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002538 /**
2539 * Get phone object associated with a subscription.
2540 * Return default phone if phone object associated with subscription is null
2541 * @param subId - subscriptionId
2542 * @return phone object associated with a subscription or default phone if null.
2543 */
Ling Mac28f0212023-03-24 16:07:15 -07002544 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002545 Phone phone = getPhoneFromSubId(subId);
2546 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002547 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002548 phone = getDefaultPhone();
2549 }
2550 return phone;
2551 }
2552
Rambo Wange53e07d2022-05-10 13:01:13 -07002553 @Nullable
2554 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002555 Phone phone = getPhoneFromRequest(request);
2556 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002557 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002558 }
2559
Ling Mac28f0212023-03-24 16:07:15 -07002560 /**
2561 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2562 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2563 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2564 * @return The Phone associated the sub Id
2565 */
2566 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002567 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569
Kai Shif70f46f2021-03-03 13:59:46 -08002570 private void sendEraseModemConfig(@NonNull Phone phone) {
2571 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2572 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2573 }
2574
2575 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2576 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2577 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002578 }
2579
Peter Wang44b186e2020-01-13 23:33:09 -08002580 private boolean isImsAvailableOnDevice() {
2581 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2582 if (pm == null) {
2583 // For some reason package manger is not available.. This will fail internally anyway,
2584 // so do not throw error and allow.
2585 return true;
2586 }
2587 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2588 }
2589
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002591 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2592 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2593
Wink Savilleadd7cc52014-09-08 14:23:09 -07002594 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002595 }
2596
Wink Savilleb564aae2014-10-23 10:18:09 -07002597 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598 if (DBG) log("dial: " + number);
2599 // No permission check needed here: This is just a wrapper around the
2600 // ACTION_DIAL intent, which is available to any app since it puts up
2601 // the UI before it does anything.
2602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 final long identity = Binder.clearCallingIdentity();
2604 try {
2605 String url = createTelUrl(number);
2606 if (url == null) {
2607 return;
2608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610 // PENDING: should we just silently fail if phone is offhook or ringing?
2611 PhoneConstants.State state = mCM.getState(subId);
2612 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2613 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2614 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2615 mApp.startActivity(intent);
2616 }
2617 } finally {
2618 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 }
2620 }
2621
2622 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002623 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002624 }
2625
Wink Savilleb564aae2014-10-23 10:18:09 -07002626 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 if (DBG) log("call: " + number);
2628
2629 // This is just a wrapper around the ACTION_CALL intent, but we still
2630 // need to do a permission check since we're calling startActivity()
2631 // from the context of the phone app.
2632 enforceCallPermission();
2633
Jordan Liu1617b712019-07-10 15:06:26 -07002634 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 != AppOpsManager.MODE_ALLOWED) {
2636 return;
2637 }
2638
joonhunshin4ac60942023-11-15 15:23:39 +00002639 enforceTelephonyFeatureWithException(callingPackage,
2640 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 String url = createTelUrl(number);
2645 if (url == null) {
2646 return;
2647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649 boolean isValid = false;
2650 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2651 if (slist != null) {
2652 for (SubscriptionInfo subInfoRecord : slist) {
2653 if (subInfoRecord.getSubscriptionId() == subId) {
2654 isValid = true;
2655 break;
2656 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002657 }
Wink Saville08874612014-08-31 19:19:58 -07002658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 if (!isValid) {
2660 return;
2661 }
Wink Saville08874612014-08-31 19:19:58 -07002662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2664 intent.putExtra(SUBSCRIPTION_KEY, subId);
2665 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2666 mApp.startActivity(intent);
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 }
2671
Wink Savilleb564aae2014-10-23 10:18:09 -07002672 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002673 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002674 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2675 }
2676
Wink Savilleb564aae2014-10-23 10:18:09 -07002677 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002678 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002679 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2680 }
2681
Wink Savilleb564aae2014-10-23 10:18:09 -07002682 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
joonhunshin4ac60942023-11-15 15:23:39 +00002685 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2686 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2687 "supplyPinReportResultForSubscriber");
2688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 final long identity = Binder.clearCallingIdentity();
2690 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002691 Phone phone = getPhone(subId);
2692 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 checkSimPin.start();
2694 return checkSimPin.unlockSim(null, pin);
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
2697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699
Wink Savilleb564aae2014-10-23 10:18:09 -07002700 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
joonhunshin4ac60942023-11-15 15:23:39 +00002703 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2704 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706 final long identity = Binder.clearCallingIdentity();
2707 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002708 Phone phone = getPhone(subId);
2709 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 checkSimPuk.start();
2711 return checkSimPuk.unlockSim(puk, pin);
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
2714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 }
2716
2717 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002718 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 * a synchronous one.
2720 */
2721 private static class UnlockSim extends Thread {
2722
2723 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002724 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725
2726 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002727 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2728 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729
2730 // For replies from SimCard interface
2731 private Handler mHandler;
2732
2733 // For async handler to identify request type
2734 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002735 private static final int SUPPLY_PIN_DELAYED = 101;
2736 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2737 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2738 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739
Michele Berionne5e411512020-11-13 02:36:59 +00002740 UnlockSim(int phoneId, IccCard simCard) {
2741 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 mSimCard = simCard;
2743 }
2744
2745 @Override
2746 public void run() {
2747 Looper.prepare();
2748 synchronized (UnlockSim.this) {
2749 mHandler = new Handler() {
2750 @Override
2751 public void handleMessage(Message msg) {
2752 AsyncResult ar = (AsyncResult) msg.obj;
2753 switch (msg.what) {
2754 case SUPPLY_PIN_COMPLETE:
2755 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2756 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002757 mRetryCount = msg.arg1;
2758 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002759 CommandException.Error error = null;
2760 if (ar.exception instanceof CommandException) {
2761 error = ((CommandException) (ar.exception))
2762 .getCommandError();
2763 }
2764 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002765 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002766 } else if (error == CommandException.Error.ABORTED) {
2767 /* When UiccCardApp dispose, handle message and return
2768 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002769 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002770 } else {
2771 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2772 }
2773 } else {
2774 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002777 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 UnlockSim.this.notifyAll();
2779 }
2780 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002781 case SUPPLY_PIN_DELAYED:
2782 if(!mDone) {
2783 String logStr = "Delay in receiving SIM PIN response ";
2784 if (DBG) log(logStr);
2785 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2786 }
2787 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002788 }
2789 }
2790 };
2791 UnlockSim.this.notifyAll();
2792 }
2793 Looper.loop();
2794 }
2795
2796 /*
2797 * Use PIN or PUK to unlock SIM card
2798 *
2799 * If PUK is null, unlock SIM card with PIN
2800 *
2801 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302802 *
2803 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2804 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 */
Wink Saville9de0f752013-10-22 19:04:03 -07002806 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002807
2808 while (mHandler == null) {
2809 try {
2810 wait();
2811 } catch (InterruptedException e) {
2812 Thread.currentThread().interrupt();
2813 }
2814 }
2815 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2816
2817 if (puk == null) {
2818 mSimCard.supplyPin(pin, callback);
2819 } else {
2820 mSimCard.supplyPuk(puk, pin, callback);
2821 }
2822
2823 while (!mDone) {
2824 try {
2825 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002826 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2827 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 wait();
2829 } catch (InterruptedException e) {
2830 // Restore the interrupted status
2831 Thread.currentThread().interrupt();
2832 }
2833 }
2834 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002835 int[] resultArray = new int[2];
2836 resultArray[0] = mResult;
2837 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002838
2839 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002840 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002841 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302842 // This instance is no longer reused, so quit its thread's looper.
2843 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002844
Wink Saville9de0f752013-10-22 19:04:03 -07002845 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 }
2847 }
2848
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002849 /**
2850 * This method has been removed due to privacy and stability concerns.
2851 */
2852 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002853 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002854 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2855 return;
Wink Saville36469e72014-06-11 15:17:00 -07002856 }
2857
Nathan Harold1f889d82020-06-04 17:05:26 -07002858 @Override
2859 public void updateServiceLocationWithPackageName(String callingPackage) {
2860 mApp.getSystemService(AppOpsManager.class)
2861 .checkPackage(Binder.getCallingUid(), callingPackage);
2862
Nathan Haroldf096d982020-11-18 17:18:06 -08002863 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002864 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2865 // Callers targeting S have no business invoking this method.
2866 return;
2867 }
2868
2869 LocationAccessPolicy.LocationPermissionResult locationResult =
2870 LocationAccessPolicy.checkLocationPermission(mApp,
2871 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2872 .setCallingPackage(callingPackage)
2873 .setCallingFeatureId(null)
2874 .setCallingPid(Binder.getCallingPid())
2875 .setCallingUid(Binder.getCallingUid())
2876 .setMethod("updateServiceLocation")
2877 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2878 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2879 .build());
2880 // Apps that lack location permission have no business calling this method;
2881 // however, because no permission was declared in the public API, denials must
2882 // all be "soft".
2883 switch (locationResult) {
2884 case DENIED_HARD: /* fall through */
2885 case DENIED_SOFT:
2886 return;
2887 }
2888
2889 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 final long identity = Binder.clearCallingIdentity();
2891 try {
Ling Mac28f0212023-03-24 16:07:15 -07002892 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893 } finally {
2894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 }
2897
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002898 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002899 @Override
2900 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002901 return isRadioOnWithFeature(callingPackage, null);
2902 }
2903
2904
2905 @Override
2906 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2907 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2908 callingFeatureId);
2909 }
2910
2911 @Deprecated
2912 @Override
2913 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2914 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002915 }
2916
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002917 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002918 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2919 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002921 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002922 return false;
2923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924
joonhunshin4ac60942023-11-15 15:23:39 +00002925 enforceTelephonyFeatureWithException(callingPackage,
2926 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 return isRadioOnForSubscriber(subId);
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
2933 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002934 }
2935
2936 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 final Phone phone = getPhone(subId);
2940 if (phone != null) {
2941 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2942 } else {
2943 return false;
2944 }
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 }
2949
2950 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002951 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 }
Wink Saville36469e72014-06-11 15:17:00 -07002953
Wink Savilleb564aae2014-10-23 10:18:09 -07002954 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002955 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956
joonhunshin4ac60942023-11-15 15:23:39 +00002957 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2958 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 final long identity = Binder.clearCallingIdentity();
2961 try {
2962 final Phone phone = getPhone(subId);
2963 if (phone != null) {
2964 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2965 }
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002968 }
Wink Saville36469e72014-06-11 15:17:00 -07002969 }
2970
2971 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002972 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002973 }
2974
Wink Savilleb564aae2014-10-23 10:18:09 -07002975 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002976 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977
2978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 final Phone phone = getPhone(subId);
2981 if (phone == null) {
2982 return false;
2983 }
2984 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2985 toggleRadioOnOffForSubscriber(subId);
2986 }
2987 return true;
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 }
Wink Saville36469e72014-06-11 15:17:00 -07002992
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002993 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002994 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002995
2996 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2997 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2998
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002999 /*
3000 * If any of the Radios are available, it will need to be
3001 * shutdown. So return true if any Radio is available.
3002 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 final long identity = Binder.clearCallingIdentity();
3004 try {
3005 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3006 Phone phone = PhoneFactory.getPhone(i);
3007 if (phone != null && phone.isRadioAvailable()) return true;
3008 }
3009 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3010 return false;
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003013 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003014 }
3015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003017 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 enforceModifyPermission();
3019
joonhunshin4ac60942023-11-15 15:23:39 +00003020 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3021 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3026 logv("Shutting down Phone " + i);
3027 shutdownRadioUsingPhoneId(i);
3028 }
3029 } finally {
3030 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003031 }
3032 }
3033
3034 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003035 Phone phone = PhoneFactory.getPhone(phoneId);
3036 if (phone != null && phone.isRadioAvailable()) {
3037 phone.shutdownRadio();
3038 }
3039 }
3040
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003042 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043
Ling Ma83dc5ea2023-01-12 15:06:04 -08003044 if (!turnOn) {
3045 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3046 }
3047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3051 if (defaultPhone != null) {
3052 defaultPhone.setRadioPower(turnOn);
3053 return true;
3054 } else {
3055 loge("There's no default phone.");
3056 return false;
3057 }
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003060 }
Wink Saville36469e72014-06-11 15:17:00 -07003061 }
3062
Wink Savilleb564aae2014-10-23 10:18:09 -07003063 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065
Ling Ma83dc5ea2023-01-12 15:06:04 -08003066 if (!turnOn) {
3067 log("setRadioPowerForSubscriber off: subId=" + subId
3068 + ",callingPackage=" + getCurrentPackageName());
3069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 final Phone phone = getPhone(subId);
3073 if (phone != null) {
3074 phone.setRadioPower(turnOn);
3075 return true;
3076 } else {
3077 return false;
3078 }
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003082 }
3083
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003084 /**
3085 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3086 * no reason to power it off. When any of the voters want to power it off, it will be turned
3087 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3088 * powering it off, and these radio off votes will be cleared.
3089 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3090 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3091 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3092 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3093 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3094 * check its vote.
3095 *
3096 * @param subId The subscription ID.
3097 * @param reason The reason for powering off radio.
3098 * @return true on success and false on failure.
3099 */
3100 public boolean requestRadioPowerOffForReason(int subId,
3101 @TelephonyManager.RadioPowerReason int reason) {
3102 enforceModifyPermission();
3103
joonhunshin4ac60942023-11-15 15:23:39 +00003104 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3105 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3106
Ling Ma83dc5ea2023-01-12 15:06:04 -08003107 log("requestRadioPowerOffForReason: subId=" + subId
3108 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003109 final long identity = Binder.clearCallingIdentity();
3110 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003111 boolean result = false;
3112 for (Phone phone : PhoneFactory.getPhones()) {
3113 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003114 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003115 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003116 if (!result) {
3117 loge("requestRadioPowerOffForReason: no phone exists");
3118 }
3119 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
3123 }
3124
3125 /**
3126 * Remove the vote on powering off the radio for a reason, as requested by
3127 * {@link requestRadioPowerOffForReason}.
3128 *
3129 * @param subId The subscription ID.
3130 * @param reason The reason for powering off radio.
3131 * @return true on success and false on failure.
3132 */
3133 public boolean clearRadioPowerOffForReason(int subId,
3134 @TelephonyManager.RadioPowerReason int reason) {
3135 enforceModifyPermission();
3136
joonhunshin4ac60942023-11-15 15:23:39 +00003137 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3138 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3139
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003140 final long identity = Binder.clearCallingIdentity();
3141 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003142 boolean result = false;
3143 for (Phone phone : PhoneFactory.getPhones()) {
3144 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003145 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003146 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003147 if (!result) {
3148 loge("clearRadioPowerOffForReason: no phone exists");
3149 }
3150 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
3154 }
3155
3156 /**
3157 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3158 *
3159 * @param subId The subscription ID.
3160 * @param callingPackage The package making the call.
3161 * @param callingFeatureId The feature in the package.
3162 * @return List of reasons for powering off radio.
3163 */
3164 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3165 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3166
joonhunshin4ac60942023-11-15 15:23:39 +00003167 enforceTelephonyFeatureWithException(callingPackage,
3168 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3169
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003170 final long identity = Binder.clearCallingIdentity();
3171 List result = new ArrayList();
3172 try {
3173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3174 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3175 return result;
3176 }
3177
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003178 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003179 if (phone != null) {
3180 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003181 } else {
3182 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003183 }
3184 } finally {
3185 Binder.restoreCallingIdentity(identity);
3186 }
3187 return result;
3188 }
3189
Wink Saville36469e72014-06-11 15:17:00 -07003190 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003191 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003192 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194
joonhunshin4ac60942023-11-15 15:23:39 +00003195 enforceTelephonyFeatureWithException(callingPackage,
3196 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3197
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198 final long identity = Binder.clearCallingIdentity();
3199 try {
Jack Yu285100e2022-12-02 22:48:35 -08003200 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003202 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003203 phone.getDataSettingsManager().setDataEnabled(
3204 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 return true;
3206 } else {
3207 return false;
3208 }
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 }
3213
Wink Saville36469e72014-06-11 15:17:00 -07003214 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003215 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003216 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003217 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218
joonhunshin4ac60942023-11-15 15:23:39 +00003219 enforceTelephonyFeatureWithException(callingPackage,
3220 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222 final long identity = Binder.clearCallingIdentity();
3223 try {
Jack Yu285100e2022-12-02 22:48:35 -08003224 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003226 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003227 phone.getDataSettingsManager().setDataEnabled(
3228 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 return true;
3230 } else {
3231 return false;
3232 }
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003236 }
3237
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003239 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003240 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3241 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003243 final long identity = Binder.clearCallingIdentity();
3244 try {
3245 final Phone phone = getPhone(subId);
3246 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003247 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 } else {
3249 return false;
3250 }
3251 } finally {
3252 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003254 }
3255
3256 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003257 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003258 }
3259
pkanwarae03a6b2016-11-06 20:37:09 -08003260 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003261 enforceCallPermission();
3262
joonhunshin4ac60942023-11-15 15:23:39 +00003263 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3264 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3269 return;
3270 }
3271 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3272 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3273 } finally {
3274 Binder.restoreCallingIdentity(identity);
3275 }
pkanwar32d516d2016-10-14 19:37:38 -07003276 };
3277
Wink Savilleb564aae2014-10-23 10:18:09 -07003278 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003279 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280
joonhunshin4ac60942023-11-15 15:23:39 +00003281 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3282 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284 final long identity = Binder.clearCallingIdentity();
3285 try {
3286 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3287 return false;
3288 }
3289 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003293 }
3294
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003295 /**
3296 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3297 * tag on getCallState Binder call.
3298 */
3299 @Deprecated
3300 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003301 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003302 if (CompatChanges.isChangeEnabled(
3303 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3304 Binder.getCallingUid())) {
3305 // Do not allow this API to be called on API version 31+, it should only be
3306 // called on old apps using this Binder call directly.
3307 throw new SecurityException("This method can only be used for applications "
3308 + "targeting API version 30 or less.");
3309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310 final long identity = Binder.clearCallingIdentity();
3311 try {
Ling Mac28f0212023-03-24 16:07:15 -07003312 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3313 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
3317 }
3318
3319 @Override
3320 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3321 if (CompatChanges.isChangeEnabled(
3322 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3323 Binder.getCallingUid())) {
3324 // Check READ_PHONE_STATE for API version 31+
3325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3326 featureId, "getCallStateForSubscription")) {
3327 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3328 + "targeting API level 31+.");
3329 }
3330 }
joonhunshin4ac60942023-11-15 15:23:39 +00003331
3332 enforceTelephonyFeatureWithException(callingPackage,
3333 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3334
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3339 PhoneConstantConversions.convertCallState(phone.getState());
3340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003343 }
3344
Sanket Padawe356d7632015-06-22 14:03:32 -07003345 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003346 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003347 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003348 }
3349
3350 @Override
3351 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003352 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3353 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 final long identity = Binder.clearCallingIdentity();
3356 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003357 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003359 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003360 } else {
3361 return PhoneConstantConversions.convertDataState(
3362 PhoneConstants.DataState.DISCONNECTED);
3363 }
3364 } finally {
3365 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003367 }
3368
Sanket Padawe356d7632015-06-22 14:03:32 -07003369 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003370 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003371 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003372 }
3373
3374 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003375 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003376 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3377 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003379 final long identity = Binder.clearCallingIdentity();
3380 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003381 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003383 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003384 } else {
3385 return TelephonyManager.DATA_ACTIVITY_NONE;
3386 }
3387 } finally {
3388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 }
3391
3392 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003393 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003394 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003395 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003396
3397 LocationAccessPolicy.LocationPermissionResult locationResult =
3398 LocationAccessPolicy.checkLocationPermission(mApp,
3399 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3400 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003401 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003402 .setCallingPid(Binder.getCallingPid())
3403 .setCallingUid(Binder.getCallingUid())
3404 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003405 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003406 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3407 .build());
3408 switch (locationResult) {
3409 case DENIED_HARD:
3410 throw new SecurityException("Not allowed to access cell location");
3411 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003412 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3413 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003414 }
3415
joonhunshin4ac60942023-11-15 15:23:39 +00003416 enforceTelephonyFeatureWithException(callingPackage,
3417 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3418
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003419 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003423 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003424 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
Svetoslav64fad262015-04-14 14:35:21 -07003428 }
3429
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003430 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003431 public String getNetworkCountryIsoForPhone(int phoneId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003432 if (!mApp.getResources().getBoolean(
3433 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3434 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3435 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3436 }
joonhunshin4ac60942023-11-15 15:23:39 +00003437
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003438 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3439 // registered cell info, so return a NULL country instead.
3440 final long identity = Binder.clearCallingIdentity();
3441 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003442 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3443 // Get default phone in this case.
3444 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3445 }
Jack Yu285100e2022-12-02 22:48:35 -08003446 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003448 if (phone == null) return "";
3449 ServiceStateTracker sst = phone.getServiceStateTracker();
3450 if (sst == null) return "";
3451 LocaleTracker lt = sst.getLocaleTracker();
3452 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003453 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003454 } finally {
3455 Binder.restoreCallingIdentity(identity);
3456 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003457 }
3458
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003459 /**
3460 * This method was removed due to potential issues caused by performing partial
3461 * updates of service state, and lack of a credible use case.
3462 *
3463 * This has the ability to break the telephony implementation by disabling notification of
3464 * changes in device connectivity. DO NOT USE THIS!
3465 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003466 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003467 public void enableLocationUpdates() {
3468 mApp.enforceCallingOrSelfPermission(
3469 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003470 }
3471
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003472 /**
3473 * This method was removed due to potential issues caused by performing partial
3474 * updates of service state, and lack of a credible use case.
3475 *
3476 * This has the ability to break the telephony implementation by disabling notification of
3477 * changes in device connectivity. DO NOT USE THIS!
3478 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003479 @Override
3480 public void disableLocationUpdates() {
3481 mApp.enforceCallingOrSelfPermission(
3482 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483 }
3484
3485 @Override
3486 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003487 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3488 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003489 try {
3490 mApp.getSystemService(AppOpsManager.class)
3491 .checkPackage(Binder.getCallingUid(), callingPackage);
3492 } catch (SecurityException e) {
3493 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3494 throw e;
3495 }
3496
Nathan Haroldf096d982020-11-18 17:18:06 -08003497 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003498 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3499 throw new SecurityException(
3500 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3501 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003502
Jordan Liu1617b712019-07-10 15:06:26 -07003503 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003504 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3505 return null;
3506 }
Svetoslav64fad262015-04-14 14:35:21 -07003507
joonhunshin4ac60942023-11-15 15:23:39 +00003508 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3509 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3510
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003511 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003512
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003513 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003514 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003515
Nathan Haroldf180aac2018-06-01 18:43:55 -07003516 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3517 for (CellInfo ci : info) {
3518 if (ci instanceof CellInfoGsm) {
3519 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3520 } else if (ci instanceof CellInfoWcdma) {
3521 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003523 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003524 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 }
3526
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003527 private List<CellInfo> getCachedCellInfo() {
3528 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3529 for (Phone phone : PhoneFactory.getPhones()) {
3530 List<CellInfo> info = phone.getAllCellInfo();
3531 if (info != null) cellInfos.addAll(info);
3532 }
3533 return cellInfos;
3534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003535
3536 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003537 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003538 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003539 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003540
3541 LocationAccessPolicy.LocationPermissionResult locationResult =
3542 LocationAccessPolicy.checkLocationPermission(mApp,
3543 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3544 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003545 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003546 .setCallingPid(Binder.getCallingPid())
3547 .setCallingUid(Binder.getCallingUid())
3548 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003549 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003550 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3551 .build());
3552 switch (locationResult) {
3553 case DENIED_HARD:
3554 throw new SecurityException("Not allowed to access cell info");
3555 case DENIED_SOFT:
3556 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003557 }
3558
Nathan Haroldf096d982020-11-18 17:18:06 -08003559 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003560 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3561 return getCachedCellInfo();
3562 }
3563
joonhunshin4ac60942023-11-15 15:23:39 +00003564 enforceTelephonyFeatureWithException(callingPackage,
3565 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3566
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003567 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003568 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3572 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003573 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003574 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575 if (info != null) cellInfos.addAll(info);
3576 }
3577 return cellInfos;
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003580 }
3581 }
3582
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003583 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003584 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3585 String callingFeatureId) {
3586 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3587 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003588 }
3589
3590 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003591 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3592 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003593 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003594 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003595 }
3596
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003597 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3598 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003599 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003600 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003601
3602 LocationAccessPolicy.LocationPermissionResult locationResult =
3603 LocationAccessPolicy.checkLocationPermission(mApp,
3604 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3605 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003606 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003607 .setCallingPid(Binder.getCallingPid())
3608 .setCallingUid(Binder.getCallingUid())
3609 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003610 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3611 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003612 .build());
3613 switch (locationResult) {
3614 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003615 if (TelephonyPermissions
3616 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003617 // Safetynet logging for b/154934934
3618 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3619 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003620 throw new SecurityException("Not allowed to access cell info");
3621 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003622 if (TelephonyPermissions
3623 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003624 // Safetynet logging for b/154934934
3625 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3626 }
Nathan Harold5320c422019-05-09 10:26:08 -07003627 try {
3628 cb.onCellInfo(new ArrayList<CellInfo>());
3629 } catch (RemoteException re) {
3630 // Drop without consequences
3631 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003632 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003633 }
3634
joonhunshin4ac60942023-11-15 15:23:39 +00003635 enforceTelephonyFeatureWithException(callingPackage,
3636 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003637
3638 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003639 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3640
3641 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3642 }
3643
3644 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003645 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003646 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003647 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003651 Phone phone = getPhone(subId);
3652 if (phone == null) {
3653 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3654 } else {
3655 phone.setCellInfoListRate(rateInMillis, workSource);
3656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003660 }
3661
Shishir Agrawala9f32182016-04-12 12:00:16 -07003662 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003663 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003664 Phone phone = PhoneFactory.getPhone(slotIndex);
3665 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003666 return null;
3667 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003668 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003669 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003670 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003671 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003672 return null;
3673 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003674
joonhunshin4ac60942023-11-15 15:23:39 +00003675 enforceTelephonyFeatureWithException(callingPackage,
3676 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3677
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003678 final long identity = Binder.clearCallingIdentity();
3679 try {
3680 return phone.getImei();
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
3683 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003684 }
3685
3686 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003687 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3688 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3689 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3690 callingFeatureId, "getPrimaryImei")) {
3691 throw new SecurityException("Caller does not have permission");
3692 }
joonhunshin4ac60942023-11-15 15:23:39 +00003693
3694 enforceTelephonyFeatureWithException(callingPackage,
3695 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3696
arunvoddud5c6ce02022-12-11 06:03:12 +00003697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 for (Phone phone : PhoneFactory.getPhones()) {
3700 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3701 return phone.getImei();
3702 }
3703 }
3704 throw new UnsupportedOperationException("Operation not supported");
3705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
3708 }
3709
3710 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003711 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003712 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3713 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3714
David Kelly5e06a7f2018-03-12 14:10:59 +00003715 Phone phone = PhoneFactory.getPhone(slotIndex);
3716 String tac = null;
3717 if (phone != null) {
3718 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003719 try {
3720 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3721 } catch (IndexOutOfBoundsException e) {
3722 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3723 return null;
3724 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003725 }
3726 return tac;
3727 }
3728
3729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003730 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003731 try {
3732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3733 } catch (SecurityException se) {
3734 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3735 throw new SecurityException("Package " + callingPackage + " does not belong to "
3736 + Binder.getCallingUid());
3737 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003738 Phone phone = PhoneFactory.getPhone(slotIndex);
3739 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003740 return null;
3741 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742
Jeff Davidson913390f2018-02-23 17:11:49 -08003743 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003744 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003745 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003746 return null;
3747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748
joonhunshin4ac60942023-11-15 15:23:39 +00003749 enforceTelephonyFeatureWithException(callingPackage,
3750 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 return phone.getMeid();
3755 } finally {
3756 Binder.restoreCallingIdentity(identity);
3757 }
Jack Yu2af8d712017-03-15 17:14:14 -07003758 }
3759
3760 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003761 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003762 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3763 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3764
David Kelly5e06a7f2018-03-12 14:10:59 +00003765 Phone phone = PhoneFactory.getPhone(slotIndex);
3766 String manufacturerCode = null;
3767 if (phone != null) {
3768 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003769 try {
3770 manufacturerCode =
3771 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3772 } catch (IndexOutOfBoundsException e) {
3773 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3774 return null;
3775 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003776 }
3777 return manufacturerCode;
3778 }
3779
3780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003781 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3782 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003783 Phone phone = PhoneFactory.getPhone(slotIndex);
3784 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003785 return null;
3786 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003787 int subId = phone.getSubId();
3788 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003789 mApp, subId, callingPackage, callingFeatureId,
3790 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003791 return null;
3792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793
joonhunshin4ac60942023-11-15 15:23:39 +00003794 enforceTelephonyFeatureWithException(callingPackage,
3795 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 return phone.getDeviceSvn();
3800 } finally {
3801 Binder.restoreCallingIdentity(identity);
3802 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003803 }
3804
fionaxu43304da2017-11-27 22:51:16 -08003805 @Override
3806 public int getSubscriptionCarrierId(int subId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003807 if (!mApp.getResources().getBoolean(
3808 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3809 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3810 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3811 }
joonhunshin4ac60942023-11-15 15:23:39 +00003812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 final Phone phone = getPhone(subId);
3816 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3817 } finally {
3818 Binder.restoreCallingIdentity(identity);
3819 }
fionaxu43304da2017-11-27 22:51:16 -08003820 }
3821
3822 @Override
3823 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003824 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3825 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 final Phone phone = getPhone(subId);
3830 return phone == null ? null : phone.getCarrierName();
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
3833 }
fionaxu43304da2017-11-27 22:51:16 -08003834 }
3835
calvinpanffe225e2018-11-01 19:43:06 +08003836 @Override
chen xu0026ca62019-03-06 15:28:50 -08003837 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003838 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3839 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3840
chen xu25637222018-11-04 17:17:00 -08003841 final long identity = Binder.clearCallingIdentity();
3842 try {
3843 final Phone phone = getPhone(subId);
3844 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003845 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003846 } finally {
3847 Binder.restoreCallingIdentity(identity);
3848 }
3849 }
3850
3851 @Override
chen xu0026ca62019-03-06 15:28:50 -08003852 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003853 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3854 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3855 "getSubscriptionSpecificCarrierName");
3856
chen xu25637222018-11-04 17:17:00 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003860 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003861 } finally {
3862 Binder.restoreCallingIdentity(identity);
3863 }
3864 }
3865
chen xu651eec72018-11-11 19:03:44 -08003866 @Override
chen xu864e11c2018-12-06 22:10:03 -08003867 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3868 if (!isSubscriptionMccMnc) {
3869 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3870 }
chen xu651eec72018-11-11 19:03:44 -08003871 final Phone phone = PhoneFactory.getPhone(slotIndex);
3872 if (phone == null) {
3873 return TelephonyManager.UNKNOWN_CARRIER_ID;
3874 }
joonhunshin4ac60942023-11-15 15:23:39 +00003875
3876 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3877 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3878
chen xu651eec72018-11-11 19:03:44 -08003879 final long identity = Binder.clearCallingIdentity();
3880 try {
3881 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
3884 }
3885 }
3886
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003887 //
3888 // Internal helper methods.
3889 //
3890
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003891 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003892 * Make sure the caller is the calling package itself
3893 *
3894 * @throws SecurityException if the caller is not the calling package
3895 */
3896 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3897 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003898 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3899 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003900 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003901 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003902 } catch (PackageManager.NameNotFoundException e) {
3903 // packageUid is -1
3904 }
3905 if (packageUid != callingUid) {
3906 throw new SecurityException(message + ": Package " + callingPackage
3907 + " does not belong to " + callingUid);
3908 }
3909 }
3910
3911 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003912 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3913 *
3914 * @throws SecurityException if the caller does not have the required permission
3915 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003916 @VisibleForTesting
3917 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003918 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3919 }
3920
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003921 /**
arunvoddud7401012022-12-15 16:08:12 +00003922 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003923 *
3924 * @throws SecurityException if the caller does not have the required permission
3925 */
3926 @VisibleForTesting
3927 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003928 enforceReadPermission(null);
3929 }
3930
3931 /**
3932 * Make sure the caller has the READ_PHONE_STATE permissions.
3933 *
3934 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3935 */
3936 @VisibleForTesting
3937 public void enforceReadPermission(String msg) {
3938 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003939 }
3940
Shuo Qian3b6ee772019-11-13 17:43:31 -08003941 private void enforceActiveEmergencySessionPermission() {
3942 mApp.enforceCallingOrSelfPermission(
3943 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3944 }
3945
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003946 /**
3947 * Make sure the caller has the CALL_PHONE permission.
3948 *
3949 * @throws SecurityException if the caller does not have the required permission
3950 */
3951 private void enforceCallPermission() {
3952 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3953 }
3954
paulhu5a773602019-08-23 19:17:33 +08003955 private void enforceSettingsPermission() {
3956 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003957 }
3958
Michele Berionne5e411512020-11-13 02:36:59 +00003959 private void enforceRebootPermission() {
3960 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3961 }
3962
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003963 /**
3964 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3965 * @param message - log message to print.
3966 * @throws SecurityException if the caller does not have the required permission
3967 */
3968 private void enforceSatelliteCommunicationPermission(String message) {
3969 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3970 }
3971
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003972 /**
3973 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3974 * @param message - log message to print.
3975 * @throws SecurityException if the caller does not have the required permission
3976 */
3977 private void enforcePackageUsageStatsPermission(String message) {
3978 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3979 }
3980
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003981 private String createTelUrl(String number) {
3982 if (TextUtils.isEmpty(number)) {
3983 return null;
3984 }
3985
Jake Hambye994d462014-02-03 13:10:13 -08003986 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003987 }
3988
Ihab Awadf9e92732013-12-05 18:02:52 -08003989 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003990 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003991 }
3992
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003993 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003994 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003995 }
3996
Ihab Awadf9e92732013-12-05 18:02:52 -08003997 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003998 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003999 }
4000
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004001 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004002 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004003 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004004 }
4005
Sanket Padawe356d7632015-06-22 14:03:32 -07004006 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004007 public int getActivePhoneTypeForSlot(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07004008 if (!mApp.getResources().getBoolean(
4009 com.android.internal.R.bool.config_force_phone_globals_creation)) {
4010 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4011 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4012 }
joonhunshin4ac60942023-11-15 15:23:39 +00004013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 final Phone phone = PhoneFactory.getPhone(slotIndex);
4017 if (phone == null) {
4018 return PhoneConstants.PHONE_TYPE_NONE;
4019 } else {
4020 return phone.getPhoneType();
4021 }
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004025 }
4026
4027 /**
4028 * Returns the CDMA ERI icon index to display
4029 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004031 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4032 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4033 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004034 }
4035
Sanket Padawe356d7632015-06-22 14:03:32 -07004036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004037 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4038 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004040 mApp, subId, callingPackage, callingFeatureId,
4041 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004042 return -1;
4043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044
joonhunshin4ac60942023-11-15 15:23:39 +00004045 enforceTelephonyFeatureWithException(callingPackage,
4046 PackageManager.FEATURE_TELEPHONY_CDMA,
4047 "getCdmaEriIconIndexForSubscriber");
4048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 final Phone phone = getPhone(subId);
4052 if (phone != null) {
4053 return phone.getCdmaEriIconIndex();
4054 } else {
4055 return -1;
4056 }
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004060 }
4061
4062 /**
4063 * Returns the CDMA ERI icon mode,
4064 * 0 - ON
4065 * 1 - FLASHING
4066 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004067 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004068 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4069 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4070 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004071 }
4072
Sanket Padawe356d7632015-06-22 14:03:32 -07004073 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004074 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4075 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004077 mApp, subId, callingPackage, callingFeatureId,
4078 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004079 return -1;
4080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081
4082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 final Phone phone = getPhone(subId);
4085 if (phone != null) {
4086 return phone.getCdmaEriIconMode();
4087 } else {
4088 return -1;
4089 }
4090 } finally {
4091 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004093 }
4094
4095 /**
4096 * Returns the CDMA ERI text,
4097 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004098 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004099 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4100 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4101 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004102 }
4103
Sanket Padawe356d7632015-06-22 14:03:32 -07004104 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004105 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4106 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004108 mApp, subId, callingPackage, callingFeatureId,
4109 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004110 return null;
4111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112
4113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 final Phone phone = getPhone(subId);
4116 if (phone != null) {
4117 return phone.getCdmaEriText();
4118 } else {
4119 return null;
4120 }
4121 } finally {
4122 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004124 }
4125
4126 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004127 * Returns the CDMA MDN.
4128 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004129 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004130 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4132 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004133
joonhunshin4ac60942023-11-15 15:23:39 +00004134 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4135 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004140 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 return phone.getLine1Number();
4142 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004143 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144 return null;
4145 }
4146 } finally {
4147 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004148 }
4149 }
4150
4151 /**
4152 * Returns the CDMA MIN.
4153 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004154 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004155 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4157 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004158
joonhunshin4ac60942023-11-15 15:23:39 +00004159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4160 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 final Phone phone = getPhone(subId);
4165 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4166 return phone.getCdmaMin();
4167 } else {
4168 return null;
4169 }
4170 } finally {
4171 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004172 }
4173 }
4174
Hall Liud892bec2018-11-30 14:51:45 -08004175 @Override
4176 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4177 INumberVerificationCallback callback, String callingPackage) {
4178 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4179 != PERMISSION_GRANTED) {
4180 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4181 }
4182 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4183
4184 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4185 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004186 throw new SecurityException("Calling package must be configured in the device config: "
4187 + "calling package: " + callingPackage
4188 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004189 }
4190
joonhunshin4ac60942023-11-15 15:23:39 +00004191 enforceTelephonyFeatureWithException(callingPackage,
4192 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4193
Hall Liud892bec2018-11-30 14:51:45 -08004194 if (range == null) {
4195 throw new NullPointerException("Range must be non-null");
4196 }
4197
4198 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004199 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004200
4201 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4202 }
4203
Junda Liuca05d5d2014-08-14 22:36:34 -07004204 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004205 * Returns true if CDMA provisioning needs to run.
4206 */
4207 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004208 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4209 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 final long identity = Binder.clearCallingIdentity();
4212 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004213 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004217 }
4218
4219 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004220 * Sets the voice mail number of a given subId.
4221 */
4222 @Override
4223 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004224 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4225 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226
joonhunshin4ac60942023-11-15 15:23:39 +00004227 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4228 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230 final long identity = Binder.clearCallingIdentity();
4231 try {
4232 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4233 new Pair<String, String>(alphaTag, number), new Integer(subId));
4234 return success;
4235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004238 }
4239
Ta-wei Yen87c49842016-05-13 21:19:52 -07004240 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004241 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4242 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004243 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4244 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004245 if (!TextUtils.equals(callingPackage, systemDialer)) {
4246 throw new SecurityException("caller must be system dialer");
4247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248
joonhunshin4ac60942023-11-15 15:23:39 +00004249 enforceTelephonyFeatureWithException(callingPackage,
4250 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 final long identity = Binder.clearCallingIdentity();
4253 try {
4254 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4255 if (phoneAccountHandle == null) {
4256 return null;
4257 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004258 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004261 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004262 }
4263
4264 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004265 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4266 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004267 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004268 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 mApp, subId, callingPackage, callingFeatureId,
4270 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004271 return null;
4272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273
joonhunshin4ac60942023-11-15 15:23:39 +00004274 enforceTelephonyFeatureWithException(callingPackage,
4275 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4276
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004277 final long identity = Binder.clearCallingIdentity();
4278 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004279 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004283 }
4284
4285 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004286 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4287 VisualVoicemailSmsFilterSettings settings) {
4288 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004289 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004290 enforceTelephonyFeatureWithException(callingPackage,
4291 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292 final long identity = Binder.clearCallingIdentity();
4293 try {
4294 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004295 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004299 }
4300
4301 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004302 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4303 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004304 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004305 enforceTelephonyFeatureWithException(callingPackage,
4306 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004311 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312 } finally {
4313 Binder.restoreCallingIdentity(identity);
4314 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004315 }
4316
4317 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004318 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4319 String callingPackage, int subId) {
4320 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321
4322 final long identity = Binder.clearCallingIdentity();
4323 try {
4324 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004325 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004329 }
4330
4331 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004332 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004333 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334
4335 final long identity = Binder.clearCallingIdentity();
4336 try {
4337 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004338 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004342 }
4343
4344 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004345 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4346 String callingAttributionTag, int subId, String number, int port, String text,
4347 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004348 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004349 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004350 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004351
4352 enforceTelephonyFeatureWithException(callingPackage,
4353 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4354
Amit Mahajandccb3f12019-05-13 13:48:32 -07004355 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004356 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4357 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004358 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004359
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004360 /**
fionaxu0152e512016-11-14 13:36:14 -08004361 * Sets the voice activation state of a given subId.
4362 */
4363 @Override
4364 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4366 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367
joonhunshin4ac60942023-11-15 15:23:39 +00004368 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4369 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371 final long identity = Binder.clearCallingIdentity();
4372 try {
4373 final Phone phone = getPhone(subId);
4374 if (phone != null) {
4375 phone.setVoiceActivationState(activationState);
4376 } else {
4377 loge("setVoiceActivationState fails with invalid subId: " + subId);
4378 }
4379 } finally {
4380 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004381 }
4382 }
4383
4384 /**
4385 * Sets the data activation state of a given subId.
4386 */
4387 @Override
4388 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4390 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004391
joonhunshin4ac60942023-11-15 15:23:39 +00004392 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4393 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395 final long identity = Binder.clearCallingIdentity();
4396 try {
4397 final Phone phone = getPhone(subId);
4398 if (phone != null) {
4399 phone.setDataActivationState(activationState);
4400 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004401 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 }
4403 } finally {
4404 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004405 }
4406 }
4407
4408 /**
4409 * Returns the voice activation state of a given subId.
4410 */
4411 @Override
4412 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004413 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414
joonhunshin4ac60942023-11-15 15:23:39 +00004415 enforceTelephonyFeatureWithException(callingPackage,
4416 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4417
fionaxu0152e512016-11-14 13:36:14 -08004418 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 final long identity = Binder.clearCallingIdentity();
4420 try {
4421 if (phone != null) {
4422 return phone.getVoiceActivationState();
4423 } else {
4424 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4425 }
4426 } finally {
4427 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004428 }
4429 }
4430
4431 /**
4432 * Returns the data activation state of a given subId.
4433 */
4434 @Override
4435 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004436 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437
joonhunshin4ac60942023-11-15 15:23:39 +00004438 enforceTelephonyFeatureWithException(callingPackage,
4439 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4440
fionaxu0152e512016-11-14 13:36:14 -08004441 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 final long identity = Binder.clearCallingIdentity();
4443 try {
4444 if (phone != null) {
4445 return phone.getDataActivationState();
4446 } else {
4447 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4448 }
4449 } finally {
4450 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004451 }
4452 }
4453
4454 /**
Wink Saville36469e72014-06-11 15:17:00 -07004455 * Returns the unread count of voicemails for a subId
4456 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004458 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4459 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004461 mApp, subId, callingPackage, callingFeatureId,
4462 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004463 return 0;
4464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004465 final long identity = Binder.clearCallingIdentity();
4466 try {
4467 final Phone phone = getPhone(subId);
4468 if (phone != null) {
4469 return phone.getVoiceMessageCount();
4470 } else {
4471 return 0;
4472 }
4473 } finally {
4474 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004476 }
4477
4478 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004479 * returns true, if the device is in a state where both voice and data
4480 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004481 */
4482 @Override
4483 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004484 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4485 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 final long identity = Binder.clearCallingIdentity();
4488 try {
Ling Mac28f0212023-03-24 16:07:15 -07004489 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004493 }
4494
4495 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004496 * Send the dialer code if called from the current default dialer or the caller has
4497 * carrier privilege.
4498 * @param inputCode The dialer code to send
4499 */
4500 @Override
4501 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004502 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004503 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004504 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4505 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004506 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004507 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004508 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004509 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004510
joonhunshin4ac60942023-11-15 15:23:39 +00004511 enforceTelephonyFeatureWithException(callingPackage,
4512 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4513
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 final long identity = Binder.clearCallingIdentity();
4515 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004516 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
fionaxu235cc5e2017-03-06 22:25:57 -08004520 }
4521
Pengquan Menga1bb6272018-09-06 09:59:22 -07004522 @Override
4523 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004524 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004525 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4526 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004527
4528 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4529 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4530
shilufc958392020-01-20 11:36:01 -08004531 final long identity = Binder.clearCallingIdentity();
4532 try {
4533 if (!isActiveSubscription(subId)) {
4534 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4535 }
4536 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4537 } finally {
4538 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004540 }
4541
Brad Ebinger35c841c2018-10-01 10:40:55 -07004542 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004543 public boolean isInEmergencySmsMode() {
4544 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004545
4546 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4547 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4548
Brad Ebingerb2b65522019-03-15 13:48:47 -07004549 final long identity = Binder.clearCallingIdentity();
4550 try {
4551 for (Phone phone : PhoneFactory.getPhones()) {
4552 if (phone.isInEmergencySmsMode()) {
4553 return true;
4554 }
4555 }
4556 } finally {
4557 Binder.restoreCallingIdentity(identity);
4558 }
4559 return false;
4560 }
4561
shilu366312e2019-12-17 09:28:10 -08004562 /**
4563 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4564 * @param subId The subscription to use to check the configuration.
4565 * @param c The callback that will be used to send the result.
4566 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004567 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004568 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4569 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004570 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004571 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004572
4573 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4574 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4575 "IMS not available on device.");
4576 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004577 final long token = Binder.clearCallingIdentity();
4578 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004579 int slotId = getSlotIndexOrException(subId);
4580 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004581
4582 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4583 if (controller != null) {
4584 ImsManager imsManager = controller.getImsManager(subId);
4585 if (imsManager != null) {
4586 imsManager.addRegistrationCallbackForSubscription(c, subId);
4587 } else {
4588 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4589 }
4590 } else {
4591 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4592 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004593 } catch (ImsException e) {
4594 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004595 } finally {
4596 Binder.restoreCallingIdentity(token);
4597 }
4598 }
4599
shilu366312e2019-12-17 09:28:10 -08004600 /**
4601 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4602 * @param subId The subscription to use to check the configuration.
4603 * @param c The callback that will be used to send the result.
4604 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004605 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004606 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004607 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004608 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004609 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4610 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4611 }
Meng Wangafbc5852019-09-19 17:37:13 -07004612 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004613
Meng Wangafbc5852019-09-19 17:37:13 -07004614 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004615 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4616 if (controller != null) {
4617 ImsManager imsManager = controller.getImsManager(subId);
4618 if (imsManager != null) {
4619 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4620 } else {
4621 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4622 + "is inactive, ignoring unregister.");
4623 // If the ImsManager is not valid, just return, since the callback
4624 // will already have been removed internally.
4625 }
4626 }
Meng Wangafbc5852019-09-19 17:37:13 -07004627 } finally {
4628 Binder.restoreCallingIdentity(token);
4629 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 }
4631
Brad Ebingera34a6c22019-10-22 17:36:18 -07004632 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004633 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4634 * @param subId The subscription to use to check the configuration.
4635 * @param c The callback that will be used to send the result.
4636 */
4637 @Override
4638 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4639 throws RemoteException {
4640 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4641 mApp, subId, "registerImsEmergencyRegistrationCallback");
4642
4643 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4644 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4645 "IMS not available on device.");
4646 }
4647 final long token = Binder.clearCallingIdentity();
4648 try {
4649 int slotId = getSlotIndexOrException(subId);
4650 verifyImsMmTelConfiguredOrThrow(slotId);
4651
4652 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4653 if (controller != null) {
4654 ImsManager imsManager = controller.getImsManager(subId);
4655 if (imsManager != null) {
4656 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4657 } else {
4658 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4659 }
4660 } else {
4661 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4662 }
4663 } catch (ImsException e) {
4664 throw new ServiceSpecificException(e.getCode());
4665 } finally {
4666 Binder.restoreCallingIdentity(token);
4667 }
4668 }
4669
4670 /**
4671 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4672 * @param subId The subscription to use to check the configuration.
4673 * @param c The callback that will be used to send the result.
4674 */
4675 @Override
4676 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4677 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4678 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4679 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4680 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4681 }
4682 final long token = Binder.clearCallingIdentity();
4683
4684 try {
4685 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4686 if (controller != null) {
4687 ImsManager imsManager = controller.getImsManager(subId);
4688 if (imsManager != null) {
4689 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4690 } else {
4691 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4692 + "is inactive, ignoring unregister.");
4693 // If the ImsManager is not valid, just return, since the callback
4694 // will already have been removed internally.
4695 }
4696 }
4697 } finally {
4698 Binder.restoreCallingIdentity(token);
4699 }
4700 }
4701
4702 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004703 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4704 */
4705 @Override
4706 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4707 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4708 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4709 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4710 "IMS not available on device.");
4711 }
4712 final long token = Binder.clearCallingIdentity();
4713 try {
4714 Phone phone = getPhone(subId);
4715 if (phone == null) {
4716 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4717 + subId + "'");
4718 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4719 }
4720 phone.getImsRegistrationState(regState -> {
4721 try {
4722 consumer.accept((regState == null)
4723 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4724 } catch (RemoteException e) {
4725 // Ignore if the remote process is no longer available to call back.
4726 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4727 }
4728 });
4729 } finally {
4730 Binder.restoreCallingIdentity(token);
4731 }
4732 }
4733
4734 /**
4735 * Get the transport type for the IMS service registration state.
4736 */
4737 @Override
4738 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004739 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004740 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004741 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4742 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4743 "IMS not available on device.");
4744 }
4745 final long token = Binder.clearCallingIdentity();
4746 try {
4747 Phone phone = getPhone(subId);
4748 if (phone == null) {
4749 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4750 + subId + "'");
4751 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4752 }
4753 phone.getImsRegistrationTech(regTech -> {
4754 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4755 int regTechConverted = (regTech == null)
4756 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4757 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4758 regTechConverted);
4759 try {
4760 consumer.accept(regTechConverted);
4761 } catch (RemoteException e) {
4762 // Ignore if the remote process is no longer available to call back.
4763 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4764 }
4765 });
4766 } finally {
4767 Binder.restoreCallingIdentity(token);
4768 }
4769 }
4770
shilu366312e2019-12-17 09:28:10 -08004771 /**
4772 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4773 * @param subId The subscription to use to check the configuration.
4774 * @param c The callback that will be used to send the result.
4775 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004776 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004777 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4778 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004779 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004780 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004781 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4782 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4783 "IMS not available on device.");
4784 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 final long token = Binder.clearCallingIdentity();
4786 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004787 int slotId = getSlotIndexOrException(subId);
4788 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004789
4790 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4791 if (controller != null) {
4792 ImsManager imsManager = controller.getImsManager(subId);
4793 if (imsManager != null) {
4794 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4795 } else {
4796 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4797 }
4798 } else {
4799 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4800 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004801 } catch (ImsException e) {
4802 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004803 } finally {
4804 Binder.restoreCallingIdentity(token);
4805 }
4806 }
4807
shilu366312e2019-12-17 09:28:10 -08004808 /**
4809 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4810 * @param subId The subscription to use to check the configuration.
4811 * @param c The callback that will be used to send the result.
4812 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004813 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004814 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004815 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004816 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004817 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4818 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4819 }
Meng Wangafbc5852019-09-19 17:37:13 -07004820
4821 final long token = Binder.clearCallingIdentity();
4822 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004823 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4824 if (controller != null) {
4825 ImsManager imsManager = controller.getImsManager(subId);
4826 if (imsManager != null) {
4827 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4828 } else {
4829 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4830 + " is inactive, ignoring unregister.");
4831 // If the ImsManager is not valid, just return, since the callback
4832 // will already have been removed internally.
4833 }
4834 }
Meng Wangafbc5852019-09-19 17:37:13 -07004835 } finally {
4836 Binder.restoreCallingIdentity(token);
4837 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004838 }
4839
4840 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004841 public boolean isCapable(int subId, int capability, int regTech) {
4842 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004843
4844 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4845 FEATURE_TELEPHONY_IMS, "isCapable");
4846
Brad Ebinger35c841c2018-10-01 10:40:55 -07004847 final long token = Binder.clearCallingIdentity();
4848 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004849 int slotId = getSlotIndexOrException(subId);
4850 verifyImsMmTelConfiguredOrThrow(slotId);
4851 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4852 } catch (com.android.ims.ImsException e) {
4853 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4854 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004855 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004856 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4857 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004858 } finally {
4859 Binder.restoreCallingIdentity(token);
4860 }
4861 }
4862
4863 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004864 public boolean isAvailable(int subId, int capability, int regTech) {
4865 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004866
4867 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4868 FEATURE_TELEPHONY_IMS, "isAvailable");
4869
Brad Ebinger35c841c2018-10-01 10:40:55 -07004870 final long token = Binder.clearCallingIdentity();
4871 try {
4872 Phone phone = getPhone(subId);
4873 if (phone == null) return false;
4874 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004875 } catch (com.android.ims.ImsException e) {
4876 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4877 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004878 } finally {
4879 Binder.restoreCallingIdentity(token);
4880 }
4881 }
4882
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004883 /**
4884 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4885 * subscription.
4886 * @param subId The subscription to use to check the configuration.
4887 * @param callback The callback that will be used to send the result.
4888 * @param capability The MmTelFeature capability that will be used to send the result.
4889 * @param transportType The transport type of the MmTelFeature capability.
4890 */
4891 @Override
4892 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4893 int transportType) {
4894 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004895 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4896 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4897 "IMS not available on device.");
4898 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004899 final long token = Binder.clearCallingIdentity();
4900 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004901 int slotId = getSlotIndex(subId);
4902 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4903 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4904 + subId + "'");
4905 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4906 }
4907 verifyImsMmTelConfiguredOrThrow(slotId);
4908 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4909 transportType, aBoolean -> {
4910 try {
4911 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4912 } catch (RemoteException e) {
4913 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4914 + "running. Ignore");
4915 }
4916 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004917 } catch (ImsException e) {
4918 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004919 } finally {
4920 Binder.restoreCallingIdentity(token);
4921 }
4922 }
4923
shilu366312e2019-12-17 09:28:10 -08004924 /**
4925 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4926 * @param subId The subscription to use to check the configuration.
4927 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004928 @Override
4929 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004930 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004931 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004932
joonhunshin4ac60942023-11-15 15:23:39 +00004933 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4934 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4935
Brad Ebinger35c841c2018-10-01 10:40:55 -07004936 final long token = Binder.clearCallingIdentity();
4937 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004938 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004939 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004940 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004941 } catch (ImsException e) {
4942 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004943 } finally {
4944 Binder.restoreCallingIdentity(token);
4945 }
4946 }
4947
4948 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004949 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004951 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004952
4953 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4954 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4955
Brad Ebinger35c841c2018-10-01 10:40:55 -07004956 final long identity = Binder.clearCallingIdentity();
4957 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004958 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004959 // This setting doesn't require an active ImsService connection, so do not verify. The
4960 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004961 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004962 } catch (ImsException e) {
4963 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
4967 }
4968
shilu366312e2019-12-17 09:28:10 -08004969 /**
4970 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4971 * @param subId The subscription to use to check the configuration.
4972 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004973 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004974 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004975 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004976 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004977
4978 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4979 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4980
Brad Ebinger35c841c2018-10-01 10:40:55 -07004981 final long identity = Binder.clearCallingIdentity();
4982 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004983 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004984 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004985 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004986 } catch (ImsException e) {
4987 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004988 } finally {
4989 Binder.restoreCallingIdentity(identity);
4990 }
4991 }
4992
4993 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004994 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004996 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004997
4998 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4999 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
5000
Brad Ebinger35c841c2018-10-01 10:40:55 -07005001 final long identity = Binder.clearCallingIdentity();
5002 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005003 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005004 // This setting doesn't require an active ImsService connection, so do not verify. The
5005 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005006 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005007 } catch (ImsException e) {
5008 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
5011 }
5012 }
5013
shilu366312e2019-12-17 09:28:10 -08005014 /**
5015 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5016 * @param subId The subscription to use to check the configuration.
5017 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005018 @Override
5019 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005020 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005021 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005022
5023 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5024 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5025
Brad Ebinger35c841c2018-10-01 10:40:55 -07005026 final long identity = Binder.clearCallingIdentity();
5027 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005028 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005029 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005030 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005031 } catch (ImsException e) {
5032 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005033 } finally {
5034 Binder.restoreCallingIdentity(identity);
5035 }
5036 }
5037
5038 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005039 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005041 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005042
5043 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5044 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5045
Brad Ebinger35c841c2018-10-01 10:40:55 -07005046 final long identity = Binder.clearCallingIdentity();
5047 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005048 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005049 // This setting doesn't require an active ImsService connection, so do not verify. The
5050 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005051 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005052 } catch (ImsException e) {
5053 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005054 } finally {
5055 Binder.restoreCallingIdentity(identity);
5056 }
5057 }
5058
shilu366312e2019-12-17 09:28:10 -08005059 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005060 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5061 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5062 * @param subId The subscription to use to check the configuration.
5063 */
5064 @Override
5065 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005066 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005067 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005068
5069 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5070 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5071
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005072 final long identity = Binder.clearCallingIdentity();
5073 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005074 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005075 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005076 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005077 } catch (ImsException e) {
5078 throw new ServiceSpecificException(e.getCode());
5079 } finally {
5080 Binder.restoreCallingIdentity(identity);
5081 }
5082 }
5083
5084 /**
5085 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5086 * Requires MODIFY_PHONE_STATE permission.
5087 * @param subId The subscription to use to check the configuration.
5088 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5089 * false otherwise
5090 */
5091 @Override
5092 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5094 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005095
5096 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5097 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5098
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005099 final long identity = Binder.clearCallingIdentity();
5100 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005101 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005102 // This setting doesn't require an active ImsService connection, so do not verify. The
5103 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005104 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005105 } catch (ImsException e) {
5106 throw new ServiceSpecificException(e.getCode());
5107 } finally {
5108 Binder.restoreCallingIdentity(identity);
5109 }
5110 }
5111
5112 /**
shilu366312e2019-12-17 09:28:10 -08005113 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5114 * @param subId The subscription to use to check the configuration.
5115 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005116 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005117
Brad Ebinger35c841c2018-10-01 10:40:55 -07005118 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005119 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005120 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005121
5122 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5123 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5124
Brad Ebinger35c841c2018-10-01 10:40:55 -07005125 final long identity = Binder.clearCallingIdentity();
5126 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005127 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005128 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005129 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005130 } catch (ImsException e) {
5131 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005132 } finally {
5133 Binder.restoreCallingIdentity(identity);
5134 }
5135 }
5136
5137 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005138 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005140 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005141
5142 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5143 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5144
Brad Ebinger35c841c2018-10-01 10:40:55 -07005145 final long identity = Binder.clearCallingIdentity();
5146 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005147 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005148 // This setting doesn't require an active ImsService connection, so do not verify. The
5149 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005150 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005151 } catch (ImsException e) {
5152 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
5156 }
5157
5158 @Override
5159 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5161 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005162
5163 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5164 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5165
Brad Ebinger35c841c2018-10-01 10:40:55 -07005166 final long identity = Binder.clearCallingIdentity();
5167 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005168 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005169 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005170 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005171 } catch (ImsException e) {
5172 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
5176 }
5177
shilu366312e2019-12-17 09:28:10 -08005178 /**
5179 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5180 * @param subId The subscription to use to check the configuration.
5181 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005182 @Override
5183 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005184 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005185 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005186
5187 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5188 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5189
Brad Ebinger35c841c2018-10-01 10:40:55 -07005190 final long identity = Binder.clearCallingIdentity();
5191 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005192 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005193 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005194 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005195 } catch (ImsException e) {
5196 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005197 } finally {
5198 Binder.restoreCallingIdentity(identity);
5199 }
5200 }
5201
5202 @Override
5203 public void setVoWiFiModeSetting(int subId, int mode) {
5204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5205 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005206
5207 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5208 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5209
Brad Ebinger35c841c2018-10-01 10:40:55 -07005210 final long identity = Binder.clearCallingIdentity();
5211 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005212 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005213 // This setting doesn't require an active ImsService connection, so do not verify. The
5214 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005215 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005216 } catch (ImsException e) {
5217 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
5221 }
5222
5223 @Override
5224 public int getVoWiFiRoamingModeSetting(int subId) {
5225 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005226
5227 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5228 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5229
Brad Ebinger35c841c2018-10-01 10:40:55 -07005230 final long identity = Binder.clearCallingIdentity();
5231 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005232 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005233 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005234 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005235 } catch (ImsException e) {
5236 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
5240 }
5241
5242 @Override
5243 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5245 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005246
5247 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5248 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5249
Brad Ebinger35c841c2018-10-01 10:40:55 -07005250 final long identity = Binder.clearCallingIdentity();
5251 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005252 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005253 // This setting doesn't require an active ImsService connection, so do not verify. The
5254 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005255 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005256 } catch (ImsException e) {
5257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
5261 }
5262
5263 @Override
5264 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5266 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005267
5268 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5269 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5270
Brad Ebinger35c841c2018-10-01 10:40:55 -07005271 final long identity = Binder.clearCallingIdentity();
5272 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005273 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005274 // This setting doesn't require an active ImsService connection, so do not verify. The
5275 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005276 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005277 } catch (ImsException e) {
5278 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005279 } finally {
5280 Binder.restoreCallingIdentity(identity);
5281 }
5282 }
5283
shilu366312e2019-12-17 09:28:10 -08005284 /**
5285 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5286 * @param subId The subscription to use to check the configuration.
5287 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005288 @Override
5289 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005290 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005291 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005292
5293 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5294 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5295
Brad Ebinger35c841c2018-10-01 10:40:55 -07005296 final long identity = Binder.clearCallingIdentity();
5297 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005298 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005299 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005300 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005301 } catch (ImsException e) {
5302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
5306 }
5307
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005308 @Override
5309 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5310 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005311
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005312 final long identity = Binder.clearCallingIdentity();
5313 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005314 if (!isImsAvailableOnDevice()) {
5315 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5316 "IMS not available on device.");
5317 }
5318 int slotId = getSlotIndexOrException(subId);
5319 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005320
5321 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5322 if (controller != null) {
5323 ImsManager imsManager = controller.getImsManager(subId);
5324 if (imsManager != null) {
5325 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5326 } else {
5327 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5328 }
5329 } else {
5330 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5331 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005332 } catch (ImsException e) {
5333 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005334 } finally {
5335 Binder.restoreCallingIdentity(identity);
5336 }
5337 }
5338
5339 @Override
5340 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5341 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005342
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005343 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005344 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5345 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5346 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005347 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005348 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5349 if (controller != null) {
5350 ImsManager imsManager = controller.getImsManager(subId);
5351 if (imsManager != null) {
5352 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5353 } else {
5354 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5355 + " is inactive, ignoring unregister.");
5356 // If the ImsManager is not valid, just return, since the callback will already
5357 // have been removed internally.
5358 }
5359 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
5363 }
5364
joonhunshincffb7fc2021-11-28 07:32:01 +00005365 @Override
5366 public void registerFeatureProvisioningChangedCallback(int subId,
5367 IFeatureProvisioningCallback callback) {
5368 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5369 mApp, subId, "registerFeatureProvisioningChangedCallback");
5370
5371 final long identity = Binder.clearCallingIdentity();
5372 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5373 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5374 }
5375
joonhunshin91bc1952022-04-29 08:47:15 +00005376 try {
5377 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5378 if (controller == null) {
5379 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5380 "Device does not support IMS");
5381 }
5382 controller.addFeatureProvisioningChangedCallback(subId, callback);
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
5385 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005386 }
5387
5388 @Override
5389 public void unregisterFeatureProvisioningChangedCallback(int subId,
5390 IFeatureProvisioningCallback callback) {
5391 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5392 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5393
5394 final long identity = Binder.clearCallingIdentity();
5395 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5396 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5397 }
5398
joonhunshin91bc1952022-04-29 08:47:15 +00005399 try {
5400 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5401 if (controller == null) {
5402 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5403 return;
5404 }
5405 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5406 } finally {
5407 Binder.restoreCallingIdentity(identity);
5408 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005409 }
allenwtsu99c623b2020-01-03 18:24:23 +08005410
5411 private void checkModifyPhoneStatePermission(int subId, String message) {
5412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5413 message);
5414 }
5415
allenwtsu99c623b2020-01-03 18:24:23 +08005416 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005417 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005418 boolean isProvisioned) {
5419 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5420
joonhunshin4ac60942023-11-15 15:23:39 +00005421 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5422 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5423
allenwtsu99c623b2020-01-03 18:24:23 +08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005426 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5427 if (controller == null) {
5428 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5429 return;
5430 }
5431 controller.setRcsProvisioningStatusForCapability(
5432 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005433 } finally {
5434 Binder.restoreCallingIdentity(identity);
5435 }
allenwtsu99c623b2020-01-03 18:24:23 +08005436 }
5437
5438
5439 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005440 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5441 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5442 mApp, subId, "getRcsProvisioningStatusForCapability");
5443
joonhunshin4ac60942023-11-15 15:23:39 +00005444 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5445 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5446
allenwtsu99c623b2020-01-03 18:24:23 +08005447 final long identity = Binder.clearCallingIdentity();
5448 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005449 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5450 if (controller == null) {
5451 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5452
5453 // device does not support IMS, this method will return true always.
5454 return true;
5455 }
5456 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005457 } finally {
5458 Binder.restoreCallingIdentity(identity);
5459 }
5460 }
5461
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005462 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005463 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5464 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005465 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005466
joonhunshin4ac60942023-11-15 15:23:39 +00005467 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5468 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5469
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005470 final long identity = Binder.clearCallingIdentity();
5471 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005472 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5473 if (controller == null) {
5474 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5475 return;
5476 }
5477 controller.setImsProvisioningStatusForCapability(
5478 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005479 } finally {
5480 Binder.restoreCallingIdentity(identity);
5481 }
5482 }
5483
5484 @Override
5485 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005486 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5487 mApp, subId, "getProvisioningStatusForCapability");
5488
joonhunshin4ac60942023-11-15 15:23:39 +00005489 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5490 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5491
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005492 final long identity = Binder.clearCallingIdentity();
5493 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005494 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5495 if (controller == null) {
5496 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005497
joonhunshin91bc1952022-04-29 08:47:15 +00005498 // device does not support IMS, this method will return true always.
5499 return true;
5500 }
5501 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005502 } finally {
5503 Binder.restoreCallingIdentity(identity);
5504 }
5505 }
5506
5507 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005508 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5509 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5510 mApp, subId, "isProvisioningRequiredForCapability");
5511
joonhunshin4ac60942023-11-15 15:23:39 +00005512 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5513 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5514
joonhunshincffb7fc2021-11-28 07:32:01 +00005515 final long identity = Binder.clearCallingIdentity();
5516 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005517 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5518 if (controller == null) {
5519 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5520
5521 // device does not support IMS, this method will return false
5522 return false;
5523 }
5524 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005525 } finally {
5526 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005527 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005528 }
5529
5530 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005531 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5532 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5533 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005534
joonhunshin4ac60942023-11-15 15:23:39 +00005535 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5536 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5537
joonhunshincffb7fc2021-11-28 07:32:01 +00005538 final long identity = Binder.clearCallingIdentity();
5539 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005540 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5541 if (controller == null) {
5542 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5543
5544 // device does not support IMS, this method will return false
5545 return false;
5546 }
5547 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005551 }
5552
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005553 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005554 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005555 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5556 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5557 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005558 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5559 mApp, subId, "getImsProvisioningInt");
5560
joonhunshin4ac60942023-11-15 15:23:39 +00005561 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5562 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5563
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005564 final long identity = Binder.clearCallingIdentity();
5565 try {
5566 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005567 int slotId = getSlotIndex(subId);
5568 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5569 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5570 + subId + "' for key:" + key);
5571 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5572 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005573
joonhunshin91bc1952022-04-29 08:47:15 +00005574 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5575 if (controller == null) {
5576 loge("getImsProvisioningInt: Device does not support IMS");
5577
5578 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5579 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5580 }
5581 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005582 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5583 return retVal;
5584 }
5585
calvinpanb5a34062021-02-08 19:59:36 +08005586 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005587 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005588 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5589 + subId + "' for key:" + key);
5590 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005591 } finally {
5592 Binder.restoreCallingIdentity(identity);
5593 }
5594 }
5595
5596 @Override
5597 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005598 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5599 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5600 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005601 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5602 mApp, subId, "getImsProvisioningString");
5603
joonhunshin4ac60942023-11-15 15:23:39 +00005604 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5605 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5606
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005607 final long identity = Binder.clearCallingIdentity();
5608 try {
5609 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005610 int slotId = getSlotIndex(subId);
5611 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5612 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5613 + subId + "' for key:" + key);
5614 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5615 }
calvinpanb5a34062021-02-08 19:59:36 +08005616 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005617 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005618 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5619 + subId + "' for key:" + key);
5620 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
5624 }
5625
5626 @Override
5627 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005628 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5629 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5630 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5632 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005633
joonhunshin4ac60942023-11-15 15:23:39 +00005634 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5635 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5636
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005640 int slotId = getSlotIndex(subId);
5641 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5642 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5643 + subId + "' for key:" + key);
5644 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5645 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005646
joonhunshin91bc1952022-04-29 08:47:15 +00005647 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5648 if (controller == null) {
5649 loge("setImsProvisioningInt: Device does not support IMS");
5650
5651 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5652 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5653 }
5654 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005655 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5656 return retVal;
5657 }
5658
calvinpanb5a34062021-02-08 19:59:36 +08005659 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5660 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005661 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005662 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005663 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
5667 }
5668
5669 @Override
5670 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005671 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5672 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5673 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5675 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005676
5677 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5678 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5679
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005680 final long identity = Binder.clearCallingIdentity();
5681 try {
5682 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005683 int slotId = getSlotIndex(subId);
5684 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5685 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5686 + subId + "' for key:" + key);
5687 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5688 }
calvinpanb5a34062021-02-08 19:59:36 +08005689 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5690 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005691 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005692 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005693 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005694 } finally {
5695 Binder.restoreCallingIdentity(identity);
5696 }
5697 }
5698
Brad Ebinger919631e2021-06-02 17:46:35 -07005699 /**
5700 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5701 * for the given slot ID or no ImsResolver instance has been created.
5702 * @param slotId The slot ID that the IMS service is created for.
5703 * @throws ImsException If there is no ImsService configured for this slot.
5704 */
5705 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5706 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5707 ImsFeature.FEATURE_MMTEL)) {
5708 throw new ImsException("This subscription does not support MMTEL over IMS",
5709 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5710 }
5711 }
5712
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005713 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005714 int slotId = SubscriptionManager.getSlotIndex(subId);
5715 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005716 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5717 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005718 }
5719 return slotId;
5720 }
5721
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005722 private int getSlotIndex(int subId) {
5723 int slotId = SubscriptionManager.getSlotIndex(subId);
5724 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5725 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5726 }
5727 return slotId;
5728 }
5729
Wink Saville36469e72014-06-11 15:17:00 -07005730 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005731 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005732 */
5733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005734 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5735 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005736 try {
5737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5738 } catch (SecurityException se) {
5739 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5740 throw new SecurityException("Package " + callingPackage + " does not belong to "
5741 + Binder.getCallingUid());
5742 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005743 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005744 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005745 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005746 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005747 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005748 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005749 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005750 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5751 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005752
joonhunshin4ac60942023-11-15 15:23:39 +00005753 enforceTelephonyFeatureWithException(callingPackage,
5754 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 final Phone phone = getPhone(subId);
5759 if (phone != null) {
5760 return phone.getServiceState().getDataNetworkType();
5761 } else {
5762 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5763 }
5764 } finally {
5765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005767 }
5768
5769 /**
5770 * Returns the data network type
5771 */
5772 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005773 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005774 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005775 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005776 }
5777
5778 /**
5779 * Returns the data network type for a subId
5780 */
5781 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005782 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5783 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005784 String functionName = "getDataNetworkTypeForSubscriber";
5785 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5786 mApp, functionName)) {
5787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5788 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5789 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5790 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005791 }
5792
joonhunshin4ac60942023-11-15 15:23:39 +00005793 enforceTelephonyFeatureWithException(callingPackage,
5794 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796 final long identity = Binder.clearCallingIdentity();
5797 try {
5798 final Phone phone = getPhone(subId);
5799 if (phone != null) {
5800 return phone.getServiceState().getDataNetworkType();
5801 } else {
5802 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5803 }
5804 } finally {
5805 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005807 }
5808
5809 /**
Wink Saville36469e72014-06-11 15:17:00 -07005810 * Returns the Voice network type for a subId
5811 */
5812 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005813 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5814 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005815 String functionName = "getVoiceNetworkTypeForSubscriber";
5816 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5817 mApp, functionName)) {
5818 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5819 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5820 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5821 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005822 }
5823
joonhunshin4ac60942023-11-15 15:23:39 +00005824 enforceTelephonyFeatureWithException(callingPackage,
5825 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 final long identity = Binder.clearCallingIdentity();
5828 try {
5829 final Phone phone = getPhone(subId);
5830 if (phone != null) {
5831 return phone.getServiceState().getVoiceNetworkType();
5832 } else {
5833 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5834 }
5835 } finally {
5836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005838 }
5839
5840 /**
5841 * @return true if a ICC card is present
5842 */
5843 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005844 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005845 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005846 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005847 }
5848
5849 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005850 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005851 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005852 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005853 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07005854 if (!mApp.getResources().getBoolean(
5855 com.android.internal.R.bool.config_force_phone_globals_creation)) {
5856 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5857 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5858 }
joonhunshin4ac60942023-11-15 15:23:39 +00005859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 final long identity = Binder.clearCallingIdentity();
5861 try {
5862 final Phone phone = PhoneFactory.getPhone(slotIndex);
5863 if (phone != null) {
5864 return phone.getIccCard().hasIccCard();
5865 } else {
5866 return false;
5867 }
5868 } finally {
5869 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005871 }
5872
5873 /**
5874 * Return if the current radio is LTE on CDMA. This
5875 * is a tri-state return value as for a period of time
5876 * the mode may be unknown.
5877 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005878 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005879 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005880 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005881 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005883 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5884 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5885 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005886 }
5887
Sanket Padawe356d7632015-06-22 14:03:32 -07005888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005889 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5890 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005891 try {
5892 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5893 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005894 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5895 }
5896
joonhunshin4ac60942023-11-15 15:23:39 +00005897 enforceTelephonyFeatureWithException(callingPackage,
5898 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 final long identity = Binder.clearCallingIdentity();
5901 try {
5902 final Phone phone = getPhone(subId);
5903 if (phone == null) {
5904 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5905 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005906 return TelephonyProperties.lte_on_cdma_device()
5907 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 }
5909 } finally {
5910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005911 }
Wink Saville36469e72014-06-11 15:17:00 -07005912 }
5913
Wink Saville36469e72014-06-11 15:17:00 -07005914 /**
5915 * {@hide}
5916 * Returns Default subId, 0 in the case of single standby.
5917 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005918 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005919 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005920 }
5921
Shishir Agrawala9f32182016-04-12 12:00:16 -07005922 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005923 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005924 }
5925
Wink Savilleb564aae2014-10-23 10:18:09 -07005926 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005927 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005928 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005929
Pengquan Menge92a50d2018-09-21 15:54:48 -07005930 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005931 return getSubscriptionManagerService().isActiveSubId(subId,
5932 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005933 }
5934
Ihab Awadf2177b72013-11-25 13:33:23 -08005935 /**
5936 * @see android.telephony.TelephonyManager.WifiCallingChoices
5937 */
5938 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939 final long identity = Binder.clearCallingIdentity();
5940 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005941 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005942 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5943 getWhenToMakeWifiCallsDefaultPreference());
5944 } finally {
5945 Binder.restoreCallingIdentity(identity);
5946 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005947 }
5948
5949 /**
5950 * @see android.telephony.TelephonyManager.WifiCallingChoices
5951 */
5952 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 final long identity = Binder.clearCallingIdentity();
5954 try {
5955 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005956 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5958 } finally {
5959 Binder.restoreCallingIdentity(identity);
5960 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005961 }
5962
Sailesh Nepald1e68152013-12-12 19:08:02 -08005963 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005964 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005965 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005966 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005967
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005968 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5969 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5970 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005971 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005972 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005973 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005974 }
5975 return PhoneFactory.getPhone(phoneId);
5976 }
5977
Shishir Agrawal566b7612013-10-28 14:41:00 -07005978 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005979 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005980 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005981
Rambo Wanga1782702021-11-10 20:15:19 -08005982 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5983 /*message=*/ "iccOpenLogicalChannel");
5984
5985 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5986 // Verify that the callingPackage in the request belongs to the calling UID
5987 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5988
joonhunshin4ac60942023-11-15 15:23:39 +00005989 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5990 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5991
Rambo Wanga1782702021-11-10 20:15:19 -08005992 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005993 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005994
Rambo Wanga1782702021-11-10 20:15:19 -08005995 private Phone getPhoneFromValidIccLogicalChannelRequest(
5996 @NonNull IccLogicalChannelRequest request, String message) {
5997 Phone phone;
5998 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6000 mApp, request.subId, message);
6001 phone = getPhoneFromSubId(request.subId);
6002 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6003 enforceModifyPermission();
6004 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6005 } else {
6006 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006007 }
Rambo Wanga1782702021-11-10 20:15:19 -08006008 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006009 }
6010
6011 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006012 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 final long identity = Binder.clearCallingIdentity();
6014 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006015 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006017 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6018 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006019 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6020 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 loge("The calling package is not allowed to access ISD-R.");
6022 throw new SecurityException(
6023 "The calling package is not allowed to access ISD-R.");
6024 }
Derek Tan740e1672017-06-27 14:56:27 -07006025 }
Derek Tan740e1672017-06-27 14:56:27 -07006026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006028 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6029 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 return response;
6031 } finally {
6032 Binder.restoreCallingIdentity(identity);
6033 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006034 }
6035
6036 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006037 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006038 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6039 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6040
Rambo Wanga1782702021-11-10 20:15:19 -08006041 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6042 /*message=*/"iccCloseLogicalChannel");
6043
6044 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6045
6046 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006047 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006048
Rambo Wanga1782702021-11-10 20:15:19 -08006049 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6050 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006051 // before this feature is enabled, this API should only return false if
6052 // the operation fails instead of throwing runtime exception for
6053 // backward-compatibility.
6054 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6055 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 final long identity = Binder.clearCallingIdentity();
6057 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006058 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006059 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 }
Chen Xue9d737e2022-01-01 23:41:31 -08006061 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006062 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006063 Boolean success = false;
6064 if (result instanceof RuntimeException) {
6065 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006066 if (shouldThrowExceptionOnFailure) {
6067 throw (RuntimeException) result;
6068 } else {
6069 return false;
6070 }
Chen Xue9d737e2022-01-01 23:41:31 -08006071 } else if (result instanceof Boolean) {
6072 success = (Boolean) result;
6073 } else {
6074 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6075 }
Rambo Wanga1782702021-11-10 20:15:19 -08006076 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 return success;
6078 } finally {
6079 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006080 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006081 }
6082
6083 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006084 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006085 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6087 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006088
6089 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6090 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6091
Jordan Liu4c733742019-02-28 12:03:40 -08006092 if (DBG) {
6093 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6094 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6095 + p3 + " data=" + data);
6096 }
6097 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6098 command, p1, p2, p3, data);
6099 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006100
Jordan Liu4c733742019-02-28 12:03:40 -08006101 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006102 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006103 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006104 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006105
6106 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6107 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6108 "iccTransmitApduLogicalChannelBySlot");
6109
Jordan Liu4c733742019-02-28 12:03:40 -08006110 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006111 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006112 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6113 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006114 }
6115 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006116 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6117 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006118 }
6119
6120 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6121 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122 final long identity = Binder.clearCallingIdentity();
6123 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006124 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125 return "";
6126 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006129 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6130 null /* workSource */);
6131 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 // Append the returned status code to the end of the response payload.
6134 String s = Integer.toHexString(
6135 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6136 if (response.payload != null) {
6137 s = IccUtils.bytesToHexString(response.payload) + s;
6138 }
6139 return s;
6140 } finally {
6141 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006142 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006143 }
Jake Hambye994d462014-02-03 13:10:13 -08006144
Evan Charltonc66da362014-05-16 14:06:40 -07006145 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006146 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6147 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6149 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006150 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006151
6152 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6153 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6154
Jordan Liu4c733742019-02-28 12:03:40 -08006155 if (DBG) {
6156 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6157 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6158 }
6159 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6160 cla, command, p1, p2, p3, data);
6161 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006162
Jordan Liu4c733742019-02-28 12:03:40 -08006163 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006164 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006165 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006166 enforceModifyPermission();
6167 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006168
6169 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6170 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6171
Jordan Liu4c733742019-02-28 12:03:40 -08006172 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006173 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006174 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6175 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006176 }
6177
6178 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006179 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6180 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006181 }
6182
6183 // open APDU basic channel assuming the caller has sufficient permissions
6184 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6185 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 final long identity = Binder.clearCallingIdentity();
6187 try {
6188 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6189 && TextUtils.equals(ISDR_AID, data)) {
6190 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006191 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6192 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 if (bestComponent == null
6194 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6195 loge("The calling package is not allowed to select ISD-R.");
6196 throw new SecurityException(
6197 "The calling package is not allowed to select ISD-R.");
6198 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006199 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006201 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006202 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6203 null /* workSource */);
6204 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006205
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006206 // Append the returned status code to the end of the response payload.
6207 String s = Integer.toHexString(
6208 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6209 if (response.payload != null) {
6210 s = IccUtils.bytesToHexString(response.payload) + s;
6211 }
6212 return s;
6213 } finally {
6214 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006215 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006216 }
6217
6218 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006219 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006220 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6222 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006223
joonhunshin4ac60942023-11-15 15:23:39 +00006224 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6225 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 if (DBG) {
6230 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6231 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6232 }
6233
6234 IccIoResult response =
6235 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6236 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6237 subId);
6238
6239 if (DBG) {
6240 log("Exchange SIM_IO [R]" + response);
6241 }
6242
6243 byte[] result = null;
6244 int length = 2;
6245 if (response.payload != null) {
6246 length = 2 + response.payload.length;
6247 result = new byte[length];
6248 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6249 } else {
6250 result = new byte[length];
6251 }
6252
6253 result[length - 1] = (byte) response.sw2;
6254 result[length - 2] = (byte) response.sw1;
6255 return result;
6256 } finally {
6257 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006258 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006259 }
6260
Nathan Haroldb3014052017-01-25 15:57:32 -08006261 /**
6262 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6263 * on a particular subscription
6264 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006265 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6266 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006268 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006269 return null;
6270 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006271
joonhunshin4ac60942023-11-15 15:23:39 +00006272 enforceTelephonyFeatureWithException(callingPackage,
6273 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 final long identity = Binder.clearCallingIdentity();
6276 try {
6277 if (appType != TelephonyManager.APPTYPE_USIM
6278 && appType != TelephonyManager.APPTYPE_SIM) {
6279 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6280 return null;
6281 }
6282 Object response = sendRequest(
6283 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6284 if (response instanceof String[]) {
6285 return (String[]) response;
6286 }
yincheng zhao2737e882019-09-06 17:06:54 -07006287 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006289 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 } finally {
6291 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006292 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006293 }
6294
yincheng zhao2737e882019-09-06 17:06:54 -07006295 /**
6296 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6297 * subscription.
6298 *
6299 * @param subId the id of the subscription.
6300 * @param appType the uicc app type, must be USIM or SIM.
6301 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6302 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006303 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006304 * @return number of fplmns that is successfully written to the SIM.
6305 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006306 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6307 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6309 mApp, subId, "setForbiddenPlmns");
6310
joonhunshin4ac60942023-11-15 15:23:39 +00006311 enforceTelephonyFeatureWithException(callingPackage,
6312 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6313
yincheng zhao2737e882019-09-06 17:06:54 -07006314 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6315 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6316 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6317 }
6318 if (fplmns == null) {
6319 throw new IllegalArgumentException("Fplmn List provided is null");
6320 }
6321 for (String fplmn : fplmns) {
6322 if (!CellIdentity.isValidPlmn(fplmn)) {
6323 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6324 }
6325 }
6326 final long identity = Binder.clearCallingIdentity();
6327 try {
6328 Object response = sendRequest(
6329 CMD_SET_FORBIDDEN_PLMNS,
6330 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6331 subId);
6332 return (int) response;
6333 } finally {
6334 Binder.restoreCallingIdentity(identity);
6335 }
6336 }
6337
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006338 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006339 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6341 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006342
joonhunshin4ac60942023-11-15 15:23:39 +00006343 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6344 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 final long identity = Binder.clearCallingIdentity();
6347 try {
6348 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6349 if (response.payload == null) {
6350 return "";
6351 }
Evan Charltonc66da362014-05-16 14:06:40 -07006352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 // Append the returned status code to the end of the response payload.
6354 String s = Integer.toHexString(
6355 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6356 s = IccUtils.bytesToHexString(response.payload) + s;
6357 return s;
6358 } finally {
6359 Binder.restoreCallingIdentity(identity);
6360 }
Evan Charltonc66da362014-05-16 14:06:40 -07006361 }
6362
Jake Hambye994d462014-02-03 13:10:13 -08006363 /**
6364 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6365 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6366 *
6367 * @param itemID the ID of the item to read
6368 * @return the NV item as a String, or null on error.
6369 */
6370 @Override
6371 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006372 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6374 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375
6376 final long identity = Binder.clearCallingIdentity();
6377 try {
6378 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006379 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6381 return value;
6382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
Jake Hambye994d462014-02-03 13:10:13 -08006385 }
6386
6387 /**
6388 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6389 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6390 *
6391 * @param itemID the ID of the item to read
6392 * @param itemValue the value to write, as a String
6393 * @return true on success; false on any failure
6394 */
6395 @Override
6396 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006397 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6399 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400
6401 final long identity = Binder.clearCallingIdentity();
6402 try {
6403 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6404 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006405 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6407 return success;
6408 } finally {
6409 Binder.restoreCallingIdentity(identity);
6410 }
Jake Hambye994d462014-02-03 13:10:13 -08006411 }
6412
6413 /**
6414 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6415 * Used for device configuration by some CDMA operators.
6416 *
6417 * @param preferredRoamingList byte array containing the new PRL
6418 * @return true on success; false on any failure
6419 */
6420 @Override
6421 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6423 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424
6425 final long identity = Binder.clearCallingIdentity();
6426 try {
6427 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6428 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6429 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6430 return success;
6431 } finally {
6432 Binder.restoreCallingIdentity(identity);
6433 }
Jake Hambye994d462014-02-03 13:10:13 -08006434 }
6435
6436 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006437 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006438 * Used for device configuration by some CDMA operators.
6439 *
chen xu6dac5ab2018-10-26 17:39:23 -07006440 * @param slotIndex - device slot.
6441 *
Jake Hambye994d462014-02-03 13:10:13 -08006442 * @return true on success; false on any failure
6443 */
6444 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006445 public boolean resetModemConfig(int slotIndex) {
6446 Phone phone = PhoneFactory.getPhone(slotIndex);
6447 if (phone != null) {
6448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6449 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450
joonhunshin4ac60942023-11-15 15:23:39 +00006451 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6452 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6453
chen xu6dac5ab2018-10-26 17:39:23 -07006454 final long identity = Binder.clearCallingIdentity();
6455 try {
6456 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6457 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6458 return success;
6459 } finally {
6460 Binder.restoreCallingIdentity(identity);
6461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462 }
chen xu6dac5ab2018-10-26 17:39:23 -07006463 return false;
6464 }
6465
6466 /**
6467 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6468 *
6469 * @param slotIndex - device slot.
6470 *
6471 * @return true on success; false on any failure
6472 */
6473 @Override
6474 public boolean rebootModem(int slotIndex) {
6475 Phone phone = PhoneFactory.getPhone(slotIndex);
6476 if (phone != null) {
6477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6478 mApp, phone.getSubId(), "rebootModem");
6479
joonhunshin4ac60942023-11-15 15:23:39 +00006480 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6481 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6482
chen xu6dac5ab2018-10-26 17:39:23 -07006483 final long identity = Binder.clearCallingIdentity();
6484 try {
6485 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6486 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6487 return success;
6488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
6491 }
6492 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006493 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006494
Brad Ebinger51f743a2017-01-23 13:50:20 -08006495 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006496 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6497 * {@link #disableIms(int)}.
6498 * @param slotIndex device slot.
6499 */
6500 public void resetIms(int slotIndex) {
6501 enforceModifyPermission();
6502
joonhunshin4ac60942023-11-15 15:23:39 +00006503 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6504 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6505
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006506 final long identity = Binder.clearCallingIdentity();
6507 try {
6508 if (mImsResolver == null) {
6509 // may happen if the does not support IMS.
6510 return;
6511 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006512 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006513 } finally {
6514 Binder.restoreCallingIdentity(identity);
6515 }
6516 }
6517
6518 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006519 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6520 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006521 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006522 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006523 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006524
6525 final long identity = Binder.clearCallingIdentity();
6526 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006527 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006528 // may happen if the device does not support IMS.
6529 return;
6530 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006531 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006535 }
6536
6537 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006538 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6539 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006540 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006541 public void disableIms(int slotId) {
6542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006543
6544 final long identity = Binder.clearCallingIdentity();
6545 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006546 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006547 // may happen if the device does not support IMS.
6548 return;
6549 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006550 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 } finally {
6552 Binder.restoreCallingIdentity(identity);
6553 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006554 }
6555
6556 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006557 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6558 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006559 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006560 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006561 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006562 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563
6564 final long identity = Binder.clearCallingIdentity();
6565 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006566 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006567 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6568 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006569 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006570 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571 } finally {
6572 Binder.restoreCallingIdentity(identity);
6573 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006574 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006575 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006576 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6577 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006578 @Override
6579 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006580 enforceModifyPermission();
6581
6582 final long identity = Binder.clearCallingIdentity();
6583 try {
6584 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006585 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006586 } finally {
6587 Binder.restoreCallingIdentity(identity);
6588 }
6589 }
6590
6591 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006592 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006593 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006594 */
6595 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6596 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597
6598 final long identity = Binder.clearCallingIdentity();
6599 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006600 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006601 // may happen if the device does not support IMS.
6602 return null;
6603 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006604 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 } finally {
6606 Binder.restoreCallingIdentity(identity);
6607 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006608 }
6609
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006610 /**
6611 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006612 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006613 */
6614 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6615 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616
6617 final long identity = Binder.clearCallingIdentity();
6618 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006619 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006620 // may happen if the device does not support IMS.
6621 return null;
6622 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006623 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006624 } finally {
6625 Binder.restoreCallingIdentity(identity);
6626 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006627 }
6628
Brad Ebinger884c07b2018-02-15 16:17:40 -08006629 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006630 * Sets the ImsService Package Name that Telephony will bind to.
6631 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006632 * @param slotIndex the slot ID that the ImsService should bind for.
6633 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006634 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006635 * @param featureTypes An integer array of feature types associated with a packageName.
6636 * @param packageName The name of the package that the current configuration will be replaced
6637 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006638 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006639 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006640 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6641 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006644 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646 final long identity = Binder.clearCallingIdentity();
6647 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006648 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006649 // may happen if the device does not support IMS.
6650 return false;
6651 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006652 Map<Integer, String> featureConfig = new HashMap<>();
6653 for (int featureType : featureTypes) {
6654 featureConfig.put(featureType, packageName);
6655 }
6656 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6657 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 } finally {
6659 Binder.restoreCallingIdentity(identity);
6660 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006661 }
6662
6663 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006664 * Clears any carrier ImsService overrides for the slot index specified that were previously
6665 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6666 *
6667 * This should only be used for testing.
6668 *
6669 * @param slotIndex the slot ID that the ImsService should bind for.
6670 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6671 */
6672 @Override
6673 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006674 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6675 "clearCarrierImsServiceOverride");
6676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006677 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006678
6679 final long identity = Binder.clearCallingIdentity();
6680 try {
6681 if (mImsResolver == null) {
6682 // may happen if the device does not support IMS.
6683 return false;
6684 }
6685 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6686 } finally {
6687 Binder.restoreCallingIdentity(identity);
6688 }
6689 }
6690
6691 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006692 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006693 *
6694 * @param slotId The slot that the ImsService is associated with.
6695 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6696 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006697 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006698 * @return the package name of the ImsService configuration.
6699 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006700 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6701 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006702 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006703 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6704 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 final long identity = Binder.clearCallingIdentity();
6707 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006708 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006709 // may happen if the device does not support IMS.
6710 return "";
6711 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006712 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006713 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6714 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 } finally {
6716 Binder.restoreCallingIdentity(identity);
6717 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006718 }
6719
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006720 /**
6721 * Get the MmTelFeature state associated with the requested subscription id.
6722 * @param subId The subscription that the MmTelFeature is associated with.
6723 * @param callback A callback with an integer containing the
6724 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6725 */
6726 @Override
6727 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6728 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006729 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6730 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6731 "IMS not available on device.");
6732 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006733 final long token = Binder.clearCallingIdentity();
6734 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006735 int slotId = getSlotIndex(subId);
6736 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6737 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6738 + subId + "'");
6739 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6740 }
6741 verifyImsMmTelConfiguredOrThrow(slotId);
6742 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6743 try {
6744 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6745 } catch (RemoteException e) {
6746 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6747 + "Ignore");
6748 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006749 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006750 } catch (ImsException e) {
6751 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006752 } finally {
6753 Binder.restoreCallingIdentity(token);
6754 }
6755 }
6756
Daniel Brightbb5840b2021-01-12 15:48:18 -08006757 /**
6758 * Sets the ims registration state on all valid {@link Phone}s.
6759 */
6760 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762
6763 final long identity = Binder.clearCallingIdentity();
6764 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006765 // NOTE: Before S, this method only set the default phone.
6766 for (final Phone phone : PhoneFactory.getPhones()) {
6767 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6768 phone.setImsRegistrationState(registered);
6769 }
6770 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771 } finally {
6772 Binder.restoreCallingIdentity(identity);
6773 }
Wink Saville36469e72014-06-11 15:17:00 -07006774 }
6775
6776 /**
Stuart Scott54788802015-03-30 13:18:01 -07006777 * Set the network selection mode to automatic.
6778 *
6779 */
6780 @Override
6781 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6783 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784
joonhunshin4ac60942023-11-15 15:23:39 +00006785 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6786 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 final long identity = Binder.clearCallingIdentity();
6789 try {
shilufc958392020-01-20 11:36:01 -08006790 if (!isActiveSubscription(subId)) {
6791 return;
6792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006794 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6795 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 } finally {
6797 Binder.restoreCallingIdentity(identity);
6798 }
Stuart Scott54788802015-03-30 13:18:01 -07006799 }
6800
Jack Yud10cdd42020-09-28 20:28:01 -07006801 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006802 * Ask the radio to connect to the input network and change selection mode to manual.
6803 *
6804 * @param subId the id of the subscription.
6805 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6806 * the operator to attach to.
6807 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6808 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6809 * normal network selection next time.
6810 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006811 */
6812 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006813 public boolean setNetworkSelectionModeManual(
6814 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6816 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006817
joonhunshin4ac60942023-11-15 15:23:39 +00006818 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6819 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6820
Jack Yu285100e2022-12-02 22:48:35 -08006821 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006822 if (!isActiveSubscription(subId)) {
6823 return false;
6824 }
6825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006826 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006827 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006829 if (DBG) {
6830 log("setNetworkSelectionModeManual: subId: " + subId
6831 + " operator: " + operatorInfo);
6832 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6834 } finally {
6835 Binder.restoreCallingIdentity(identity);
6836 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006837 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006838 /**
shilu84f6e8b2019-12-19 13:58:01 -08006839 * Get the manual network selection
6840 *
6841 * @param subId the id of the subscription.
6842 *
6843 * @return the previously saved user selected PLMN
6844 */
6845 @Override
6846 public String getManualNetworkSelectionPlmn(int subId) {
6847 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006848 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6849 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006850
joonhunshin4ac60942023-11-15 15:23:39 +00006851 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6852 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6853
shilu84f6e8b2019-12-19 13:58:01 -08006854 final long identity = Binder.clearCallingIdentity();
6855 try {
6856 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006857 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006858 }
6859
6860 final Phone phone = getPhone(subId);
6861 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006862 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006863 }
6864 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6865 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006866 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006867 } finally {
6868 Binder.restoreCallingIdentity(identity);
6869 }
6870 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006871
6872 /**
6873 * Scans for available networks.
6874 */
6875 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006876 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6877 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6879 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006880 LocationAccessPolicy.LocationPermissionResult locationResult =
6881 LocationAccessPolicy.checkLocationPermission(mApp,
6882 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6883 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006884 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006885 .setCallingPid(Binder.getCallingPid())
6886 .setCallingUid(Binder.getCallingUid())
6887 .setMethod("getCellNetworkScanResults")
6888 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006889 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6890 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006891 .build());
6892 switch (locationResult) {
6893 case DENIED_HARD:
6894 throw new SecurityException("Not allowed to access scan results -- location");
6895 case DENIED_SOFT:
6896 return null;
6897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898
Pengquan Menga1bb6272018-09-06 09:59:22 -07006899 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006900 try {
6901 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006902 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 } finally {
6905 Binder.restoreCallingIdentity(identity);
6906 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006907 }
6908
6909 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006910 * Get the call forwarding info, given the call forwarding reason.
6911 */
6912 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006913 public void getCallForwarding(int subId, int callForwardingReason,
6914 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006915 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006916
6917 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6918 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6919
Shuo Qian4a594052020-01-23 11:59:30 -08006920 long identity = Binder.clearCallingIdentity();
6921 try {
6922 if (DBG) {
6923 log("getCallForwarding: subId " + subId
6924 + " callForwardingReason" + callForwardingReason);
6925 }
Hall Liu27d24262020-09-18 19:04:59 -07006926
6927 Phone phone = getPhone(subId);
6928 if (phone == null) {
6929 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006930 callback.onError(
6931 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006932 } catch (RemoteException e) {
6933 // ignore
6934 }
6935 return;
6936 }
6937
6938 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6939 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6940 @Override
6941 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6942 try {
6943 callback.onCallForwardingInfoAvailable(info);
6944 } catch (RemoteException e) {
6945 // ignore
6946 }
6947 }
6948
6949 @Override
6950 public void onError(int error) {
6951 try {
6952 callback.onError(error);
6953 } catch (RemoteException e) {
6954 // ignore
6955 }
6956 }
6957 });
6958 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006959 } finally {
6960 Binder.restoreCallingIdentity(identity);
6961 }
6962 }
6963
6964 /**
6965 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6966 * reason, the number to forward, and the timeout before the forwarding is attempted.
6967 */
6968 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006969 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6970 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006971 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006972
6973 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6974 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6975
Shuo Qian4a594052020-01-23 11:59:30 -08006976 long identity = Binder.clearCallingIdentity();
6977 try {
6978 if (DBG) {
6979 log("setCallForwarding: subId " + subId
6980 + " callForwardingInfo" + callForwardingInfo);
6981 }
Hall Liu27d24262020-09-18 19:04:59 -07006982
6983 Phone phone = getPhone(subId);
6984 if (phone == null) {
6985 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006986 callback.accept(
6987 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006988 } catch (RemoteException e) {
6989 // ignore
6990 }
6991 return;
6992 }
6993
6994 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6995 FunctionalUtils.ignoreRemoteException(callback::accept));
6996
6997 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006998 } finally {
6999 Binder.restoreCallingIdentity(identity);
7000 }
7001 }
7002
7003 /**
Hall Liu27d24262020-09-18 19:04:59 -07007004 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007005 */
7006 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007007 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007008 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007009
7010 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7011 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7012
Shuo Qian4a594052020-01-23 11:59:30 -08007013 long identity = Binder.clearCallingIdentity();
7014 try {
Hall Liu27d24262020-09-18 19:04:59 -07007015 Phone phone = getPhone(subId);
7016 if (phone == null) {
7017 try {
7018 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7019 } catch (RemoteException e) {
7020 // ignore
7021 }
7022 return;
7023 }
SongFerngWang0e767992021-03-31 22:08:45 +08007024 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7025 PersistableBundle c = configManager.getConfigForSubId(subId);
7026 boolean requireUssd = c.getBoolean(
7027 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007028
Shuo Qian4a594052020-01-23 11:59:30 -08007029 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007030 if (requireUssd) {
7031 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7032 getSubscriptionCarrierId(subId));
7033 String newUssdCommand = "";
7034 try {
7035 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007036 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007037 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7038 } catch (NullPointerException e) {
7039 loge("Failed to generate USSD number" + e);
7040 }
7041 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7042 mMainThreadHandler, callback, carrierXmlParser,
7043 CarrierXmlParser.SsEntry.SSAction.QUERY);
7044 final String ussdCommand = newUssdCommand;
7045 Executors.newSingleThreadExecutor().execute(() -> {
7046 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7047 });
7048 } else {
7049 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7050 callback::accept);
7051 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7052 }
Shuo Qian4a594052020-01-23 11:59:30 -08007053 } finally {
7054 Binder.restoreCallingIdentity(identity);
7055 }
7056 }
7057
7058 /**
Hall Liu27d24262020-09-18 19:04:59 -07007059 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007060 */
7061 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007062 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007063 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007064
7065 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7066 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7067
Shuo Qian4a594052020-01-23 11:59:30 -08007068 long identity = Binder.clearCallingIdentity();
7069 try {
Hall Liu27d24262020-09-18 19:04:59 -07007070 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7071
7072 Phone phone = getPhone(subId);
7073 if (phone == null) {
7074 try {
7075 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7076 } catch (RemoteException e) {
7077 // ignore
7078 }
7079 return;
7080 }
7081
SongFerngWang0e767992021-03-31 22:08:45 +08007082 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7083 PersistableBundle c = configManager.getConfigForSubId(subId);
7084 boolean requireUssd = c.getBoolean(
7085 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007086
SongFerngWang0e767992021-03-31 22:08:45 +08007087 if (DBG) log("getCallWaitingStatus: subId " + subId);
7088 if (requireUssd) {
7089 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7090 getSubscriptionCarrierId(subId));
7091 CarrierXmlParser.SsEntry.SSAction ssAction =
7092 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7093 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7094 String newUssdCommand = "";
7095 try {
7096 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007097 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007098 .makeCommand(ssAction, null);
7099 } catch (NullPointerException e) {
7100 loge("Failed to generate USSD number" + e);
7101 }
7102 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7103 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7104 final String ussdCommand = newUssdCommand;
7105 Executors.newSingleThreadExecutor().execute(() -> {
7106 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7107 });
7108 } else {
7109 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7110 FunctionalUtils.ignoreRemoteException(callback::accept));
7111
7112 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7113 }
Shuo Qian4a594052020-01-23 11:59:30 -08007114 } finally {
7115 Binder.restoreCallingIdentity(identity);
7116 }
7117 }
7118
7119 /**
yinxub1bed742017-04-17 11:45:04 -07007120 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007121 *
yinxub1bed742017-04-17 11:45:04 -07007122 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007123 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7124 * location related information which will be sent if the caller already possess
7125 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007126 * @param request contains the radio access networks with bands/channels to scan
7127 * @param messenger callback messenger for scan results or errors
7128 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007129 * @return the id of the requested scan which can be used to stop the scan.
7130 */
7131 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007132 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7133 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007134 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7136 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007137 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007138 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7139 if (!renounceFineLocationAccess) {
7140 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007141 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7142 .setCallingPackage(callingPackage)
7143 .setCallingFeatureId(callingFeatureId)
7144 .setCallingPid(Binder.getCallingPid())
7145 .setCallingUid(Binder.getCallingUid())
7146 .setMethod("requestNetworkScan")
7147 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7148 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7149 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7150 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007151 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007152 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007153 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7154 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007155 if (e != null) {
7156 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7157 throw e;
7158 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007159 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007160 return TelephonyScanManager.INVALID_SCAN_ID;
7161 }
7162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 }
joonhunshin4ac60942023-11-15 15:23:39 +00007164
7165 enforceTelephonyFeatureWithException(callingPackage,
7166 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7167
Hall Liu912dfd32019-04-25 14:02:26 -07007168 int callingUid = Binder.getCallingUid();
7169 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007173 renounceFineLocationAccess, request, messenger, binder,
7174 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007175 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007176 } finally {
7177 Binder.restoreCallingIdentity(identity);
7178 }
yinxu504e1392017-04-12 16:03:22 -07007179 }
7180
Hall Liub2ac8ef2019-02-28 15:56:23 -08007181 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007182 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007183 boolean hasCarrierPriv;
7184 final long identity = Binder.clearCallingIdentity();
7185 try {
7186 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7187 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7188 } finally {
7189 Binder.restoreCallingIdentity(identity);
7190 }
Hall Liu558027f2019-05-15 19:14:05 -07007191 boolean hasNetworkScanPermission =
7192 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007193 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007194
7195 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7196 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7197 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007198 }
7199
7200 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7201 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007202 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7203 return new SecurityException("Specific channels must not be"
7204 + " scanned without location access.");
7205 }
7206 }
7207 }
7208
Hall Liub2ac8ef2019-02-28 15:56:23 -08007209 return null;
7210 }
7211
yinxu504e1392017-04-12 16:03:22 -07007212 /**
7213 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007214 *
7215 * @param subId id of the subscription
7216 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007217 */
7218 @Override
7219 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7221 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007222
Hall Liu912dfd32019-04-25 14:02:26 -07007223 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 final long identity = Binder.clearCallingIdentity();
7225 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007226 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 } finally {
7228 Binder.restoreCallingIdentity(identity);
7229 }
yinxu504e1392017-04-12 16:03:22 -07007230 }
7231
7232 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007233 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007234 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007235 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007236 */
7237 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007238 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007239 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007240 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007241 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007242
joonhunshin4ac60942023-11-15 15:23:39 +00007243 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7244 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246 final long identity = Binder.clearCallingIdentity();
7247 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007248 if (DBG) log("getAllowedNetworkTypesBitmask");
7249 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7250 int networkTypesBitmask = (result != null ? result[0] : -1);
7251 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7252 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 } finally {
7254 Binder.restoreCallingIdentity(identity);
7255 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007256 }
7257
7258 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007259 * Get the allowed network types for certain reason.
7260 *
7261 * @param subId the id of the subscription.
7262 * @param reason the reason the allowed network type change is taking place
7263 * @return the allowed network types.
7264 */
7265 @Override
7266 public long getAllowedNetworkTypesForReason(int subId,
7267 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007268 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007269 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007270
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007271 if (!mApp.getResources().getBoolean(
7272 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7273 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7274 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7275 "getAllowedNetworkTypesForReason");
7276 }
joonhunshin4ac60942023-11-15 15:23:39 +00007277
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007278 final long identity = Binder.clearCallingIdentity();
7279 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007280 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007281 } finally {
7282 Binder.restoreCallingIdentity(identity);
7283 }
7284 }
7285
7286 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007287 * Enable/Disable E-UTRA-NR Dual Connectivity
7288 * @param subId subscription id of the sim card
7289 * @param nrDualConnectivityState expected NR dual connectivity state
7290 * This can be passed following states
7291 * <ol>
7292 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7293 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7294 * <li>Disable NR dual connectivity and force secondary cell to be released
7295 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7296 * </ol>
7297 * @return operation result.
7298 */
7299 @Override
7300 public int setNrDualConnectivityState(int subId,
7301 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7303 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007304 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007305 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7306 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7307 }
7308
Sooraj Sasindran37444802020-08-11 10:40:43 -07007309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7310 final long identity = Binder.clearCallingIdentity();
7311 try {
7312 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7313 nrDualConnectivityState, subId,
7314 workSource);
7315 if (DBG) log("enableNRDualConnectivity result: " + result);
7316 return result;
7317 } finally {
7318 Binder.restoreCallingIdentity(identity);
7319 }
7320 }
7321
7322 /**
7323 * Is E-UTRA-NR Dual Connectivity enabled
7324 * @return true if dual connectivity is enabled else false
7325 */
7326 @Override
7327 public boolean isNrDualConnectivityEnabled(int subId) {
7328 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007329 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007330 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007331 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007332 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7333 return false;
7334 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007335 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7336 final long identity = Binder.clearCallingIdentity();
7337 try {
7338 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7339 null, subId, workSource);
7340 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7341 return isEnabled;
7342 } finally {
7343 Binder.restoreCallingIdentity(identity);
7344 }
7345 }
7346
7347 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007348 * Set the allowed network types of the device and
7349 * provide the reason triggering the allowed network change.
7350 *
7351 * @param subId the id of the subscription.
7352 * @param reason the reason the allowed network type change is taking place
7353 * @param allowedNetworkTypes the allowed network types.
7354 * @return true on success; false on any failure.
7355 */
7356 @Override
7357 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007358 @TelephonyManager.AllowedNetworkTypesReason int reason,
7359 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7361 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007362 // If the caller only has carrier privileges, then they should not be able to override
7363 // any network types which were set for security reasons.
7364 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7365 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007366 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007367 throw new SecurityException(
7368 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007369 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007370 }
joonhunshin4ac60942023-11-15 15:23:39 +00007371
7372 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7373 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7374
SongFerngWang3ef3e072020-12-21 16:41:52 +08007375 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007376 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007377 return false;
7378 }
7379 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7380 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007381 return false;
7382 }
7383
Jack Yu5b494332023-01-23 18:18:04 +00007384 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7385 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007386
Jack Yue37dd262022-12-16 11:53:37 -08007387 Phone phone = getPhone(subId);
7388 if (phone == null) {
7389 return false;
7390 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007391
Jack Yue37dd262022-12-16 11:53:37 -08007392 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007393 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007394 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007395 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007396
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007397 final long identity = Binder.clearCallingIdentity();
7398 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007399 Boolean success = (Boolean) sendRequest(
7400 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7401 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7402
7403 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7404 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007405 } finally {
7406 Binder.restoreCallingIdentity(identity);
7407 }
7408 }
7409
7410 /**
Miaoa84611c2019-03-15 09:21:10 +08007411 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007412 *
Miaoa84611c2019-03-15 09:21:10 +08007413 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007414 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007415 * @hide
7416 */
7417 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007418 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007419 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007420
7421 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7422 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007425 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 try {
Miaoa84611c2019-03-15 09:21:10 +08007427 if (phone != null) {
7428 return phone.hasMatchedTetherApnSetting();
7429 } else {
7430 return false;
7431 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 } finally {
7433 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007434 }
Junda Liu475951f2014-11-07 16:45:03 -08007435 }
7436
7437 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007438 * Get the user enabled state of Mobile Data.
7439 *
7440 * TODO: remove and use isUserDataEnabled.
7441 * This can't be removed now because some vendor codes
7442 * calls through ITelephony directly while they should
7443 * use TelephonyManager.
7444 *
7445 * @return true on enabled
7446 */
7447 @Override
7448 public boolean getDataEnabled(int subId) {
7449 return isUserDataEnabled(subId);
7450 }
7451
7452 /**
7453 * Get whether mobile data is enabled per user setting.
7454 *
7455 * There are other factors deciding whether mobile data is actually enabled, but they are
7456 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007457 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007458 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7459 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007460 *
7461 * @return {@code true} if data is enabled else {@code false}
7462 */
7463 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007464 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007465 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007466 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007467 try {
7468 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7469 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007470 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007471 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7472 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007473 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007475 mApp, subId, functionName);
7476
Robert Greenwalt646120a2014-05-23 11:54:03 -07007477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478
7479 final long identity = Binder.clearCallingIdentity();
7480 try {
Jack Yu285100e2022-12-02 22:48:35 -08007481 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7483 Phone phone = PhoneFactory.getPhone(phoneId);
7484 if (phone != null) {
7485 boolean retVal = phone.isUserDataEnabled();
7486 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7487 return retVal;
7488 } else {
7489 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7490 return false;
7491 }
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007494 }
7495 }
7496
7497 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007498 * Checks if the device is capable of mobile data by considering whether whether the
7499 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7500 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007501 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007502 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007503 */
7504 @Override
7505 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007506 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007507 try {
7508 try {
7509 mApp.enforceCallingOrSelfPermission(
7510 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007511 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007512 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007513 try {
7514 mApp.enforceCallingOrSelfPermission(
7515 android.Manifest.permission.READ_PHONE_STATE,
7516 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007517 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007518 mApp.enforceCallingOrSelfPermission(
7519 permission.READ_BASIC_PHONE_STATE, functionName);
7520 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007521 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007522 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007523 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007524 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525
joonhunshin4ac60942023-11-15 15:23:39 +00007526 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7527 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 final long identity = Binder.clearCallingIdentity();
7530 try {
Jack Yu285100e2022-12-02 22:48:35 -08007531 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007533 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007534 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007535 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 return retVal;
7537 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007538 if (DBG) {
7539 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7540 + subId + " retVal=false");
7541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 return false;
7543 }
7544 } finally {
7545 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007546 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007547 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007548
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007549 /**
7550 * Check if data is enabled for a specific reason
7551 * @param subId Subscription index
7552 * @param reason the reason the data enable change is taking place
7553 * @return {@code true} if the overall data is enabled; {@code false} if not.
7554 */
7555 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007556 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007557 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007558 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007559 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007560 try {
7561 mApp.enforceCallingOrSelfPermission(
7562 android.Manifest.permission.ACCESS_NETWORK_STATE,
7563 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007564 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007565 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7566 functionName);
7567 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007568 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007569 try {
7570 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007571 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007572 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007574 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007575 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007576 }
7577
joonhunshin4ac60942023-11-15 15:23:39 +00007578 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7579 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007580
7581 final long identity = Binder.clearCallingIdentity();
7582 try {
Jack Yu285100e2022-12-02 22:48:35 -08007583 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007584 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007585 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007586 + " reason=" + reason);
7587 }
7588 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007589 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007590 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007591 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007592 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007593 return retVal;
7594 } else {
7595 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007596 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007597 + subId + " retVal=false");
7598 }
7599 return false;
7600 }
7601 } finally {
7602 Binder.restoreCallingIdentity(identity);
7603 }
7604 }
7605
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007606 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007607 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007608 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7609 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7610
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007611 // No permission needed; this only lets the caller inspect their own status.
7612 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007613 }
Junda Liu29340342014-07-10 15:23:27 -07007614
7615 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007616 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007617 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007618
7619 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7620 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7621
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007622 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7623 }
7624
7625 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7626 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007627 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007628 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007629 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7630 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007631 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7632 if (cpt == null) {
7633 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007634 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7635 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007636 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007637 }
7638
7639 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007640 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007641 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007642
7643 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7644 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7645
chen xuf7e9fe82019-05-09 19:31:02 -07007646 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007647 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007648 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007649 Phone phone = getPhone(subId);
7650 if (phone == null) {
7651 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7652 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7653 }
7654 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7655 if (cpt == null) {
7656 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007657 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7658 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007659 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007660 }
7661
7662 @Override
7663 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007664 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007665
7666 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7667 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7668 "checkCarrierPrivilegesForPackageAnyPhone");
7669
Rambo Wange7209ce2022-02-23 13:41:02 -08007670 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7671 }
7672
7673 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007674 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007675 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007676 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007677 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007678 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7679 Phone phone = PhoneFactory.getPhone(phoneId);
7680 if (phone == null) {
7681 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007682 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007683 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7684 if (cpt == null) {
7685 continue;
7686 }
7687 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007688 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7689 break;
7690 }
7691 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007692 return result;
Junda Liu29340342014-07-10 15:23:27 -07007693 }
Derek Tan89e89d42014-07-08 17:00:10 -07007694
7695 @Override
Junda Liue64de782015-04-16 17:19:16 -07007696 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007697 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007698
7699 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7700 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7701 "getCarrierPackageNamesForIntentAndPhone");
7702
Rambo Wang8a247eb2022-02-08 21:11:18 +00007703 Phone phone = PhoneFactory.getPhone(phoneId);
7704 if (phone == null) {
7705 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007706 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007707 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7708 if (cpt == null) {
7709 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007710 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007711 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007712 }
7713
Amith Yamasani6e118872016-02-19 12:53:51 -08007714 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007715 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007716 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007717 Phone phone = PhoneFactory.getPhone(phoneId);
7718 if (phone == null) {
7719 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007720 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007721 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7722 if (cpt == null) {
7723 return Collections.emptyList();
7724 }
7725 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007726 }
7727
chen xuf7e9fe82019-05-09 19:31:02 -07007728 @Override
7729 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007730 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007731
7732 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7733 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7734 "getPackagesWithCarrierPrivilegesForAllPhones");
7735
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007736 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007737 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007738 try {
7739 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7740 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7741 }
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007744 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007745 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007746 }
7747
Rambo Wang6812ffb2022-03-15 16:54:17 -07007748 @Override
7749 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7750 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7751
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007752 if (!mApp.getResources().getBoolean(
7753 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7754 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7755 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7756 "getCarrierServicePackageNameForLogicalSlot");
7757 }
joonhunshin4ac60942023-11-15 15:23:39 +00007758
Rambo Wang6812ffb2022-03-15 16:54:17 -07007759 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7760 if (phone == null) {
7761 return null;
7762 }
7763 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7764 if (cpt == null) {
7765 return null;
7766 }
7767 return cpt.getCarrierServicePackageName();
7768 }
7769
Wink Savilleb564aae2014-10-23 10:18:09 -07007770 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007771 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007772 UiccPort port = phone == null ? null : phone.getUiccPort();
7773 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007774 return null;
7775 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007776 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007777 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007778 return null;
7779 }
7780 return iccId;
7781 }
7782
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007783 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007784 public void setCallComposerStatus(int subId, int status) {
7785 enforceModifyPermission();
7786
joonhunshin4ac60942023-11-15 15:23:39 +00007787 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7788 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7789
Shuo Qiane4e11672020-12-15 22:15:33 -08007790 final long identity = Binder.clearCallingIdentity();
7791 try {
7792 Phone phone = getPhone(subId);
7793 if (phone != null) {
7794 Phone defaultPhone = phone.getImsPhone();
7795 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7796 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7797 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007798 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7799 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007800 }
7801 }
Shuo Qian284ae752020-12-22 19:10:14 -08007802 } catch (ImsException e) {
7803 throw new ServiceSpecificException(e.getCode());
7804 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007805 Binder.restoreCallingIdentity(identity);
7806 }
7807 }
7808
7809 @Override
7810 public int getCallComposerStatus(int subId) {
7811 enforceReadPrivilegedPermission("getCallComposerStatus");
7812
joonhunshin4ac60942023-11-15 15:23:39 +00007813 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7814 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7815
Shuo Qiane4e11672020-12-15 22:15:33 -08007816 final long identity = Binder.clearCallingIdentity();
7817 try {
7818 Phone phone = getPhone(subId);
7819 if (phone != null) {
7820 Phone defaultPhone = phone.getImsPhone();
7821 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7822 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7823 return imsPhone.getCallComposerStatus();
7824 }
7825 }
7826 } finally {
7827 Binder.restoreCallingIdentity(identity);
7828 }
7829 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7830 }
7831
7832 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007833 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7834 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007835 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007836 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007837
joonhunshin4ac60942023-11-15 15:23:39 +00007838 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7839 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7840 "setLine1NumberForDisplayForSubscriber");
7841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842 final long identity = Binder.clearCallingIdentity();
7843 try {
7844 final String iccId = getIccId(subId);
7845 final Phone phone = getPhone(subId);
7846 if (phone == null) {
7847 return false;
7848 }
7849 final String subscriberId = phone.getSubscriberId();
7850
7851 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007852 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 + subscriberId + " to " + number);
7854 }
7855
7856 if (TextUtils.isEmpty(iccId)) {
7857 return false;
7858 }
7859
7860 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7861
7862 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7863 if (alphaTag == null) {
7864 editor.remove(alphaTagPrefKey);
7865 } else {
7866 editor.putString(alphaTagPrefKey, alphaTag);
7867 }
7868
7869 // Record both the line number and IMSI for this ICCID, since we need to
7870 // track all merged IMSIs based on line number
7871 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7872 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7873 if (number == null) {
7874 editor.remove(numberPrefKey);
7875 editor.remove(subscriberPrefKey);
7876 } else {
7877 editor.putString(numberPrefKey, number);
7878 editor.putString(subscriberPrefKey, subscriberId);
7879 }
7880
7881 editor.commit();
7882 return true;
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007885 }
Derek Tan7226c842014-07-02 17:42:23 -07007886 }
7887
7888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007889 public String getLine1NumberForDisplay(int subId, String callingPackage,
7890 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007891 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007893 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007894 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007895 return null;
7896 }
Derek Tan97ebb422014-09-05 16:55:38 -07007897
joonhunshin4ac60942023-11-15 15:23:39 +00007898 enforceTelephonyFeatureWithException(callingPackage,
7899 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901 final long identity = Binder.clearCallingIdentity();
7902 try {
7903 String iccId = getIccId(subId);
7904 if (iccId != null) {
7905 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7906 if (DBG_MERGE) {
7907 log("getLine1NumberForDisplay returning "
7908 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7909 }
7910 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7913 return null;
7914 } finally {
7915 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007916 }
Derek Tan7226c842014-07-02 17:42:23 -07007917 }
7918
7919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007920 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7921 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007923 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007924 return null;
7925 }
Derek Tan97ebb422014-09-05 16:55:38 -07007926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007927 final long identity = Binder.clearCallingIdentity();
7928 try {
7929 String iccId = getIccId(subId);
7930 if (iccId != null) {
7931 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7932 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7933 }
7934 return null;
7935 } finally {
7936 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007937 }
Derek Tan7226c842014-07-02 17:42:23 -07007938 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007939
7940 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007941 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7942 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007943 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7944 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007946 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007947 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007948 return null;
7949 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007950
Jordan Liub49b04b2019-05-06 14:45:15 -07007951 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7952 // the process, where TelephonyManager was instantiated.
7953 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007954 final long identity = Binder.clearCallingIdentity();
7955 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007956 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 final TelephonyManager tele = TelephonyManager.from(context);
7958 final SubscriptionManager sub = SubscriptionManager.from(context);
7959
7960 // Figure out what subscribers are currently active
7961 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962
Jordan Liub49b04b2019-05-06 14:45:15 -07007963 // Only consider subs which match the current subId
7964 // This logic can be simplified. See b/131189269 for progress.
7965 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007966 activeSubscriberIds.add(tele.getSubscriberId(subId));
7967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968
7969 // First pass, find a number override for an active subscriber
7970 String mergeNumber = null;
7971 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7972 for (String key : prefs.keySet()) {
7973 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7974 final String subscriberId = (String) prefs.get(key);
7975 if (activeSubscriberIds.contains(subscriberId)) {
7976 final String iccId = key.substring(
7977 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7978 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7979 mergeNumber = (String) prefs.get(numberKey);
7980 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007981 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007982 + " for active subscriber " + subscriberId);
7983 }
7984 if (!TextUtils.isEmpty(mergeNumber)) {
7985 break;
7986 }
7987 }
7988 }
7989 }
7990
7991 // Shortcut when no active merged subscribers
7992 if (TextUtils.isEmpty(mergeNumber)) {
7993 return null;
7994 }
7995
7996 // Second pass, find all subscribers under that line override
7997 final ArraySet<String> result = new ArraySet<>();
7998 for (String key : prefs.keySet()) {
7999 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8000 final String number = (String) prefs.get(key);
8001 if (mergeNumber.equals(number)) {
8002 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8003 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8004 final String subscriberId = (String) prefs.get(subscriberKey);
8005 if (!TextUtils.isEmpty(subscriberId)) {
8006 result.add(subscriberId);
8007 }
8008 }
8009 }
8010 }
8011
8012 final String[] resultArray = result.toArray(new String[result.size()]);
8013 Arrays.sort(resultArray);
8014 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008015 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008016 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8017 }
8018 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008019 } finally {
8020 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008021 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008022 }
8023
8024 @Override
zoey chen38003472019-12-13 17:16:31 +08008025 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8026 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008027
joonhunshin4ac60942023-11-15 15:23:39 +00008028 enforceTelephonyFeatureWithException(callingPackage,
8029 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8030
Malcolm Chen6ca97372019-07-01 16:28:21 -07008031 final long identity = Binder.clearCallingIdentity();
8032 try {
8033 final TelephonyManager telephonyManager = mApp.getSystemService(
8034 TelephonyManager.class);
8035 String subscriberId = telephonyManager.getSubscriberId(subId);
8036 if (subscriberId == null) {
8037 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008038 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008039 + subId);
8040 }
8041 return null;
8042 }
8043
Jack Yu3beaf9d2023-04-14 09:17:27 -07008044 final SubscriptionInfo info = getSubscriptionManagerService()
8045 .getSubscriptionInfo(subId);
8046 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008047 // If it doesn't belong to any group, return just subscriberId of itself.
8048 if (groupUuid == null) {
8049 return new String[]{subscriberId};
8050 }
8051
8052 // Get all subscriberIds from the group.
8053 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008054 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8055 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8056 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008057 for (SubscriptionInfo subInfo : groupInfos) {
8058 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8059 if (subscriberId != null) {
8060 mergedSubscriberIds.add(subscriberId);
8061 }
8062 }
8063
8064 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8065 } finally {
8066 Binder.restoreCallingIdentity(identity);
8067
8068 }
8069 }
8070
8071 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008072 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008073 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008074 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075
joonhunshin4ac60942023-11-15 15:23:39 +00008076 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8077 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 final Phone phone = getPhone(subId);
8082 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8083 } finally {
8084 Binder.restoreCallingIdentity(identity);
8085 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008086 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008087
8088 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008089 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008090 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8091 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008092 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8093 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008094
8095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 final Phone phone = getPhone(subId);
8098 if (phone == null) {
8099 return false;
8100 }
8101 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8102 cdmaNonRoamingList);
8103 } finally {
8104 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008105 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008106 }
8107
8108 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008109 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008110 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008111 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008112 if (phone == null) {
8113 return raf;
8114 }
8115
Shuo Qiandee53402020-05-29 14:08:15 -07008116 try {
8117 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008118 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008119 mApp, phone.getSubId(), "getRadioAccessFamily");
8120 } catch (SecurityException e) {
8121 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8122 throw e;
8123 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008124
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008125 if (!mApp.getResources().getBoolean(
8126 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8127 enforceTelephonyFeatureWithException(callingPackage,
8128 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8129 }
joonhunshin4ac60942023-11-15 15:23:39 +00008130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008131 final long identity = Binder.clearCallingIdentity();
8132 try {
chen xub97461a2018-10-26 14:17:57 -07008133 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008134 } finally {
8135 Binder.restoreCallingIdentity(identity);
8136 }
chen xub97461a2018-10-26 14:17:57 -07008137 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008138 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008139
8140 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008141 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008142 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Rambo Wang7eb26962024-07-11 19:48:30 +00008143 if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) {
8144 enforceCallingPackage(callingPackage, Binder.getCallingUid(),
8145 "Invalid package:" + callingPackage);
8146 } else {
8147 try {
8148 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8149 Binder.getCallingUid())) {
8150 throw new SecurityException("Invalid package:" + callingPackage);
8151 }
8152 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008153 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008154 }
Hall Liu82694d52020-12-11 18:22:04 -08008155 }
joonhunshin4ac60942023-11-15 15:23:39 +00008156
8157 enforceTelephonyFeatureWithException(callingPackage,
8158 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8159
Hall Liu82694d52020-12-11 18:22:04 -08008160 RoleManager rm = mApp.getSystemService(RoleManager.class);
Rambo Wang7eb26962024-07-11 19:48:30 +00008161 List<String> dialerRoleHolders;
8162 if (com.android.internal.telephony.flags.Flags.supportPhoneUidCheckForMultiuser()) {
8163 dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
8164 UserHandle.of(ActivityManager.getCurrentUser()));
8165 } else {
8166 dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8167 }
Hall Liu82694d52020-12-11 18:22:04 -08008168 if (!dialerRoleHolders.contains(callingPackage)) {
8169 throw new SecurityException("App must be the dialer role holder to"
8170 + " upload a call composer pic");
8171 }
8172
8173 Executors.newSingleThreadExecutor().execute(() -> {
8174 ByteArrayOutputStream output = new ByteArrayOutputStream(
8175 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8176 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8177 boolean readUntilEnd = false;
8178 int totalBytesRead = 0;
8179 byte[] buffer = new byte[16 * 1024];
8180 while (true) {
8181 int numRead;
8182 try {
8183 numRead = input.read(buffer);
8184 } catch (IOException e) {
8185 try {
8186 fd.checkError();
8187 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8188 null);
8189 } catch (IOException e1) {
8190 // This means that the other side closed explicitly with an error. If this
8191 // happens, log and ignore.
8192 loge("Remote end of call composer picture pipe closed: " + e1);
8193 }
8194 break;
8195 }
8196 if (numRead == -1) {
8197 readUntilEnd = true;
8198 break;
8199 }
8200 totalBytesRead += numRead;
8201 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8202 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8203 try {
8204 input.close();
8205 } catch (IOException e) {
8206 // ignore
8207 }
8208 break;
8209 }
8210 output.write(buffer, 0, numRead);
8211 }
8212 // Generally, the remote end will close the file descriptors. The only case where we
8213 // close is above, where the picture size is too big.
8214
8215 try {
8216 fd.checkError();
8217 } catch (IOException e) {
8218 loge("Remote end for call composer closed with an error: " + e);
8219 return;
8220 }
8221
Hall Liuaa4211e2021-01-20 15:43:39 -08008222 if (!readUntilEnd) {
8223 loge("Did not finish reading entire image; aborting");
8224 return;
8225 }
Hall Liu82694d52020-12-11 18:22:04 -08008226
Hall Liuaa4211e2021-01-20 15:43:39 -08008227 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8228 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8229 new CallComposerPictureTransfer.Factory() {},
8230 imageData,
8231 (result) -> {
8232 if (result.first != null) {
8233 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8234 Bundle outputResult = new Bundle();
8235 outputResult.putParcelable(
8236 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8237 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8238 outputResult);
8239 } else {
8240 callback.send(result.second, null);
8241 }
8242 }
8243 );
Hall Liu82694d52020-12-11 18:22:04 -08008244 });
8245 }
8246
8247 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008248 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008249 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008250 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251
joonhunshin4ac60942023-11-15 15:23:39 +00008252 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8253 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255 final long identity = Binder.clearCallingIdentity();
8256 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008257 ImsManager.getInstance(defaultPhone.getContext(),
8258 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008259 } finally {
8260 Binder.restoreCallingIdentity(identity);
8261 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008262 }
8263
8264 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008265 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008266 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8268 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008269 return false;
8270 }
Svet Ganovb320e182015-04-16 12:30:10 -07008271
joonhunshin4ac60942023-11-15 15:23:39 +00008272 enforceTelephonyFeatureWithException(callingPackage,
8273 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275 final long identity = Binder.clearCallingIdentity();
8276 try {
8277 // Check the user preference and the system-level IMS setting. Even if the user has
8278 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8279 // In the long run, we may instead need to check if there exists a connection service
8280 // which can support video calling.
8281 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008282 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 return imsManager.isVtEnabledByPlatform()
8284 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8285 && imsManager.isVtEnabledByUser();
8286 } finally {
8287 Binder.restoreCallingIdentity(identity);
8288 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008289 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008290
Andrew Leea1239f22015-03-02 17:44:07 -08008291 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008292 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8293 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008295 mApp, subId, callingPackage, callingFeatureId,
8296 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 return false;
8298 }
8299
joonhunshin4ac60942023-11-15 15:23:39 +00008300 enforceTelephonyFeatureWithException(callingPackage,
8301 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 final long identity = Binder.clearCallingIdentity();
8304 try {
8305 CarrierConfigManager configManager =
8306 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008307 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8309 } finally {
8310 Binder.restoreCallingIdentity(identity);
8311 }
Andrew Leea1239f22015-03-02 17:44:07 -08008312 }
8313
8314 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008315 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008317 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008318 return false;
8319 }
8320
joonhunshin4ac60942023-11-15 15:23:39 +00008321 enforceTelephonyFeatureWithException(callingPackage,
8322 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008324 final long identity = Binder.clearCallingIdentity();
8325 try {
8326 CarrierConfigManager configManager =
8327 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008328 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8330 } finally {
8331 Binder.restoreCallingIdentity(identity);
8332 }
Andrew Leea1239f22015-03-02 17:44:07 -08008333 }
8334
Andrew Lee9431b832015-03-09 18:46:45 -07008335 @Override
8336 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008337 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008338 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008339 }
8340
8341 @Override
8342 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008343 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8344 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008346 final long identity = Binder.clearCallingIdentity();
8347 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008348 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008349 } finally {
8350 Binder.restoreCallingIdentity(identity);
8351 }
Andrew Lee9431b832015-03-09 18:46:45 -07008352 }
8353
Hall Liuf6668912018-10-31 17:05:23 -07008354 /**
8355 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8356 * support for the feature and device firmware support.
8357 *
8358 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8359 */
8360 @Override
8361 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008362 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8363 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008365 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008366 final Phone phone = getPhone(subscriptionId);
8367 if (phone == null) {
8368 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8369 return false;
8370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008371 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008372 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008373 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008374 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8375 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8376 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008377 return isCarrierSupported && isDeviceSupported;
8378 } finally {
8379 Binder.restoreCallingIdentity(identity);
8380 }
Hall Liu98187582018-01-22 19:15:32 -08008381 }
8382
Hall Liuf6668912018-10-31 17:05:23 -07008383 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008384 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8385 * RTT setting, will return true if the device and carrier both support RTT.
8386 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008387 */
8388 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008389 final long identity = Binder.clearCallingIdentity();
8390 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008391 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8392 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8393 return false;
8394 }
8395 }
8396
Hall Liu5bab75c2019-12-11 23:58:20 +00008397 boolean isRttSupported = isRttSupported(subscriptionId);
8398 boolean isUserRttSettingOn = Settings.Secure.getInt(
8399 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8400 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8401 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8402 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008403 } finally {
8404 Binder.restoreCallingIdentity(identity);
8405 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008406 }
8407
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008408 @Deprecated
8409 @Override
8410 public String getDeviceId(String callingPackage) {
8411 return getDeviceIdWithFeature(callingPackage, null);
8412 }
8413
Sanket Padawe7310cc72015-01-14 09:53:20 -08008414 /**
8415 * Returns the unique device ID of phone, for example, the IMEI for
8416 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8417 *
8418 * <p>Requires Permission:
8419 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8420 */
8421 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008422 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008423 try {
8424 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8425 } catch (SecurityException se) {
8426 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8427 throw new SecurityException("Package " + callingPackage + " does not belong to "
8428 + Binder.getCallingUid());
8429 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008430 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008431 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008432 return null;
8433 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008434 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008435 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008436 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008437 return null;
8438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008439
8440 final long identity = Binder.clearCallingIdentity();
8441 try {
8442 return phone.getDeviceId();
8443 } finally {
8444 Binder.restoreCallingIdentity(identity);
8445 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008446 }
8447
Ping Sunc67b7c22016-03-02 19:16:45 +08008448 /**
8449 * {@hide}
8450 * Returns the IMS Registration Status on a particular subid
8451 *
8452 * @param subId
8453 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008454 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008455 Phone phone = getPhone(subId);
8456 if (phone != null) {
8457 return phone.isImsRegistered();
8458 } else {
8459 return false;
8460 }
8461 }
8462
Santos Cordon7a1885b2015-02-03 11:15:19 -08008463 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008464 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008465 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008467 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008468 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8469 }
8470 final long identity = Binder.clearCallingIdentity();
8471 try {
8472 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
8475 }
8476 }
8477
8478 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008479 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008480 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008481 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008482 mApp,
8483 subscriptionId,
8484 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8485 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008486
8487 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8488 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8489
Tyler Gunnf70ed162019-04-03 15:28:53 -07008490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 Phone phone = getPhone(subscriptionId);
8493 if (phone == null) {
8494 return null;
8495 }
8496 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8497 } finally {
8498 Binder.restoreCallingIdentity(identity);
8499 }
8500 }
8501
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008502 /**
8503 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008504 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008505 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008506 final long identity = Binder.clearCallingIdentity();
8507 try {
8508 Phone phone = getPhone(subId);
8509 if (phone != null) {
8510 return phone.isWifiCallingEnabled();
8511 } else {
8512 return false;
8513 }
8514 } finally {
8515 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008516 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008517 }
8518
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008519 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008520 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008521 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008522 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008523 final long identity = Binder.clearCallingIdentity();
8524 try {
8525 Phone phone = getPhone(subId);
8526 if (phone != null) {
8527 return phone.isVideoEnabled();
8528 } else {
8529 return false;
8530 }
8531 } finally {
8532 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008533 }
8534 }
8535
8536 /**
8537 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8538 * defined in {@link ImsRegistrationImplBase}.
8539 */
8540 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008541 final long identity = Binder.clearCallingIdentity();
8542 try {
8543 Phone phone = getPhone(subId);
8544 if (phone != null) {
8545 return phone.getImsRegistrationTech();
8546 } else {
8547 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8548 }
8549 } finally {
8550 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008551 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008552 }
8553
Stuart Scott8eef64f2015-04-08 15:13:54 -07008554 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008555 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008556 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008557
8558 enforceTelephonyFeatureWithException(callingPackage,
8559 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8560
Stuart Scott981d8582015-04-21 14:09:50 -07008561 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8562 return;
8563 }
Kai Shif70f46f2021-03-03 13:59:46 -08008564 Phone defaultPhone = getDefaultPhone();
8565 if (defaultPhone != null) {
8566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8567 mApp, getDefaultPhone().getSubId(), "factoryReset");
8568 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008569 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008570
Svet Ganovcc087f82015-05-12 20:35:54 -07008571 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008572 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8573 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008574 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008575 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008576 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008577 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008578 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008579 setDataRoamingEnabled(subId, phone == null ? false
8580 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008581 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008582 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008583 // There has been issues when Sms raw table somehow stores orphan
8584 // fragments. They lead to garbled message when new fragments come
8585 // in and combined with those stale ones. In case this happens again,
8586 // user can reset all network settings which will clean up this table.
8587 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008588 // Clean up IMS settings as well here.
8589 int slotId = getSlotIndex(subId);
8590 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8591 ImsManager.getInstance(mApp, slotId).factoryReset();
8592 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008593
Kai Shif70f46f2021-03-03 13:59:46 -08008594 if (defaultPhone == null) {
8595 return;
8596 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008597 // Erase modem config if erase modem on network setting is enabled.
8598 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8599 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8600 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008601 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008602 }
Kai Shif70f46f2021-03-03 13:59:46 -08008603
8604 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008605 } finally {
8606 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008607 }
8608 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008609
SongFerngWangfd89b102021-05-27 22:44:54 +08008610 @VisibleForTesting
8611 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8612 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8613 return;
8614 }
8615 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8616 RILConstants.PREFERRED_NETWORK_MODE);
8617 SubscriptionManager.setSubscriptionProperty(subId,
8618 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8619 "user=" + defaultNetworkType);
8620 phone.loadAllowedNetworksFromSubscriptionDatabase();
8621 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8622 defaultNetworkType, null);
8623 }
8624
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008625 private void cleanUpSmsRawTable(Context context) {
8626 ContentResolver resolver = context.getContentResolver();
8627 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8628 resolver.delete(uri, null, null);
8629 }
8630
Narayan Kamath1c496c22015-04-16 14:40:19 +01008631 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008632 public String getSimLocaleForSubscriber(int subId) {
8633 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008634
8635 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8636 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8637
chen xu5d3637b2019-01-21 23:31:38 -08008638 final Phone phone = getPhone(subId);
8639 if (phone == null) {
8640 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008641 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008643 final long identity = Binder.clearCallingIdentity();
8644 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008645 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8646 phone.getContext().getOpPackageName(),
8647 phone.getContext().getAttributionTag());
8648 if (info == null) {
8649 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8650 return null;
chen xu6291c472019-02-04 12:55:53 -08008651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008652 // Try and fetch the locale from the carrier properties or from the SIM language
8653 // preferences (EF-PL and EF-LI)...
8654 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008655 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008656 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8657 if (localeFromDefaultSim != null) {
8658 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8659 if (DBG) log("Using locale from subId: " + subId + " locale: "
8660 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008661 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008662 } else {
8663 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008664 }
8665 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008667 // The SIM language preferences only store a language (e.g. fr = French), not an
8668 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8669 // the SIM and carrier preferences does not include a country we add the country
8670 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008671 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008672 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008673 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008674 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008675 }
8676
8677 if (DBG) log("No locale found - returning null");
8678 return null;
8679 } finally {
8680 Binder.restoreCallingIdentity(identity);
8681 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008682 }
8683
tom hsu0b59d292022-09-29 23:49:21 +08008684 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008685 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008686 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008687 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008688 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008689 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8690 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008691 Locale.forLanguageTag(localeTag).getCountry())) {
8692 return localeTag;
8693 }
8694 }
8695 return inputLocale.toLanguageTag();
8696 }
8697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008698 /**
8699 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8700 */
8701 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008702 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008703 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008704 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008705
Gary Jian3aa9a762022-01-24 16:41:19 +08008706 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8707 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008708
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008709 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008710 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8711 * representing the state of the modem.
8712 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008713 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8714 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008715 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008716 */
8717 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008718 public void requestModemActivityInfo(ResultReceiver result) {
8719 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008720
8721 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8722 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8723
vagdeviaf9a5b92018-08-15 16:01:53 -07008724 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008725
8726 final long identity = Binder.clearCallingIdentity();
8727 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008728 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008729 } finally {
8730 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008731 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008732 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008733
Gary Jian76280a42022-12-07 16:18:33 +08008734 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008735 // less than total activity duration.
8736 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8737 if (info == null) {
8738 return false;
8739 }
8740 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008741 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008742 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8743
Hall Liu49656c02020-10-09 19:00:11 -07008744 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8745
Siddharth Rayb8114062018-06-17 15:02:38 -07008746 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008747 && (info.getSleepTimeMillis() <= activityDurationMs)
8748 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008749 }
8750
Gary Jian3aa9a762022-01-24 16:41:19 +08008751 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8752 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8753 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8754 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8755
8756 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8757 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8758 }
8759
8760 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8761 mLastModemActivityInfo.setReceiveTimeMillis(
8762 rat,
8763 freq,
8764 info.getReceiveTimeMillis(rat, freq)
8765 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8766 }
8767
8768 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8769 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8770 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8771 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8772
8773 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8774 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8775 }
8776 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8777 mLastModemActivityInfo.setReceiveTimeMillis(
8778 rat,
8779 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8780 }
8781
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008782 /**
8783 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8784 * @param info recent ModemActivityInfo
8785 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008786 private void mergeModemActivityInfo(ModemActivityInfo info) {
8787 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008788 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008789 boolean matched;
8790 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8791 matched = false;
8792 int rat = info.getSpecificInfoRat(i);
8793 int freq = info.getSpecificInfoFrequencyRange(i);
8794 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8795 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8796 //if it already exists
8797 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8798 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8799 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8800 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8801 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8802 updateLastModemActivityInfo(info, rat, freq);
8803 matched = true;
8804 }
8805 } else {
8806 updateLastModemActivityInfo(info, rat);
8807 matched = true;
8808 }
8809 }
8810 }
8811
8812 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008813 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008814 new ActivityStatsTechSpecificInfo(
8815 rat,
8816 freq,
8817 info.getTransmitTimeMillis(rat, freq),
8818 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008819 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008820 }
8821 }
8822 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8823 mLastModemActivitySpecificInfo =
8824 new ActivityStatsTechSpecificInfo[merged.size()];
8825 merged.toArray(mLastModemActivitySpecificInfo);
8826
8827 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8828 mLastModemActivityInfo.setSleepTimeMillis(
8829 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008830 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008831 mLastModemActivityInfo.setIdleTimeMillis(
8832 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008833 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008834
8835 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008836 new ModemActivityInfo(
8837 mLastModemActivityInfo.getTimestampMillis(),
8838 mLastModemActivityInfo.getSleepTimeMillis(),
8839 mLastModemActivityInfo.getIdleTimeMillis(),
8840 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008841 }
8842
8843 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8844 ActivityStatsTechSpecificInfo[] info) {
8845 int infoSize = info.length;
8846 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8847 for (int i = 0; i < infoSize; i++) {
8848 ret[i] = new ActivityStatsTechSpecificInfo(
8849 info[i].getRat(), info[i].getFrequencyRange(),
8850 info[i].getTransmitTimeMillis(),
8851 (int) info[i].getReceiveTimeMillis());
8852 }
8853 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008854 }
8855
Jack Yu85bd38a2015-11-09 11:34:32 -08008856 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008857 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008858 */
8859 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008860 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8861 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8862 Phone phone = PhoneFactory.getPhone(slotIndex);
8863 if (phone == null) {
8864 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8865 return null;
8866 }
8867
8868 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008870 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008871 return null;
8872 }
8873
joonhunshin4ac60942023-11-15 15:23:39 +00008874 enforceTelephonyFeatureWithException(callingPackage,
8875 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8876
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008877 boolean hasFinePermission = false;
8878 boolean hasCoarsePermission = false;
8879 if (!renounceFineLocationAccess) {
8880 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8881 LocationAccessPolicy.checkLocationPermission(mApp,
8882 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8883 .setCallingPackage(callingPackage)
8884 .setCallingFeatureId(callingFeatureId)
8885 .setCallingPid(Binder.getCallingPid())
8886 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008887 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008888 .setLogAsInfo(true)
8889 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8890 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8891 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8892 .build());
8893 hasFinePermission =
8894 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8895 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008896
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008897 if (!renounceCoarseLocationAccess) {
8898 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8899 LocationAccessPolicy.checkLocationPermission(mApp,
8900 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8901 .setCallingPackage(callingPackage)
8902 .setCallingFeatureId(callingFeatureId)
8903 .setCallingPid(Binder.getCallingPid())
8904 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008905 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008906 .setLogAsInfo(true)
8907 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8908 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8909 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8910 .build());
8911 hasCoarsePermission =
8912 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8913 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008914
Jordan Liu0f2bc442020-11-18 16:47:37 -08008915 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008916 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008917 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8918 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008919 if (subInfo != null && !subInfo.isActive()) {
8920 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008921 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008922 }
8923
Hall Liuf19c44f2018-11-27 14:38:17 -08008924 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008925 boolean isCallingPackageDataService = phone.getDataServicePackages()
8926 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008927
8928 // Scrub out the location info in ServiceState depending on what level of access
8929 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008930 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008931 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8932 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008933 } finally {
8934 Binder.restoreCallingIdentity(identity);
8935 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008936 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008937
8938 /**
8939 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8940 *
8941 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8942 * voicemail ringtone.
8943 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8944 * PhoneAccount.
8945 */
8946 @Override
8947 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008948 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8949 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008951 final long identity = Binder.clearCallingIdentity();
8952 try {
8953 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8954 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008955 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008956 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008958 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8959 } finally {
8960 Binder.restoreCallingIdentity(identity);
8961 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008962 }
8963
8964 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008965 * Sets the per-account voicemail ringtone.
8966 *
8967 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8968 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8969 *
8970 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8971 * voicemail ringtone.
8972 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8973 * PhoneAccount.
8974 */
8975 @Override
8976 public void setVoicemailRingtoneUri(String callingPackage,
8977 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008978 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008979 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008980 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8981 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8983 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8984 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008986
joonhunshin4ac60942023-11-15 15:23:39 +00008987 enforceTelephonyFeatureWithException(callingPackage,
8988 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008990 final long identity = Binder.clearCallingIdentity();
8991 try {
8992 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8993 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008994 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008995 }
8996 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8997 } finally {
8998 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008999 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009000 }
9001
9002 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009003 * Returns whether vibration is set for voicemail notification in Phone settings.
9004 *
9005 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9006 * voicemail vibration setting.
9007 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9008 */
9009 @Override
9010 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009011 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9012 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009014 final long identity = Binder.clearCallingIdentity();
9015 try {
9016 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9017 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009018 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009019 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009021 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9022 } finally {
9023 Binder.restoreCallingIdentity(identity);
9024 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009025 }
9026
Youhan Wange64578a2016-05-02 15:32:42 -07009027 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009028 * Sets the per-account voicemail vibration.
9029 *
9030 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9031 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9032 *
9033 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9034 * voicemail vibration setting.
9035 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9036 * specific PhoneAccount.
9037 */
9038 @Override
9039 public void setVoicemailVibrationEnabled(String callingPackage,
9040 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009041 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009043 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9044 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9046 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9047 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009048 }
9049
joonhunshin4ac60942023-11-15 15:23:39 +00009050 enforceTelephonyFeatureWithException(callingPackage,
9051 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009053 final long identity = Binder.clearCallingIdentity();
9054 try {
9055 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9056 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009057 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009058 }
9059 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9060 } finally {
9061 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009062 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009063 }
9064
9065 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009066 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9067 *
9068 * @throws SecurityException if the caller does not have the required permission
9069 */
arunvoddud7401012022-12-15 16:08:12 +00009070 @VisibleForTesting
9071 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009072 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009073 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009074 }
9075
9076 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009077 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9078 * permission.
9079 *
9080 * @throws SecurityException if the caller does not have the required permission
9081 */
9082 private void enforceSendSmsPermission() {
9083 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9084 }
9085
9086 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009087 * Make sure either called from same process as self (phone) or IPC caller has interact across
9088 * users permission.
9089 *
9090 * @throws SecurityException if the caller does not have the required permission
9091 */
9092 private void enforceInteractAcrossUsersPermission(String message) {
9093 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9094 }
9095
9096 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009097 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009098 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009099 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009100 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009101 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009102 final long identity = Binder.clearCallingIdentity();
9103 try {
9104 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009105 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009106 if (componentName == null) {
9107 throw new SecurityException(
9108 "Caller not current active visual voicemail package[null]");
9109 }
9110 String vvmPackage = componentName.getPackageName();
9111 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009112 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009113 }
9114 } finally {
9115 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009116 }
9117 }
9118
9119 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009120 * Return the application ID for the app type.
9121 *
9122 * @param subId the subscription ID that this request applies to.
9123 * @param appType the uicc app type.
9124 * @return Application ID for specificied app type, or null if no uicc.
9125 */
9126 @Override
9127 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009128 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009129
9130 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9131 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9132
Youhan Wange64578a2016-05-02 15:32:42 -07009133 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009134
9135 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009136 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009137 if (phone == null) {
9138 return null;
9139 }
9140 String aid = null;
9141 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009142 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009143 .getApplicationByType(appType).getAid();
9144 } catch (Exception e) {
9145 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9146 }
9147 return aid;
9148 } finally {
9149 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009150 }
Youhan Wange64578a2016-05-02 15:32:42 -07009151 }
9152
Youhan Wang4001d252016-05-11 10:29:41 -07009153 /**
9154 * Return the Electronic Serial Number.
9155 *
9156 * @param subId the subscription ID that this request applies to.
9157 * @return ESN or null if error.
9158 */
9159 @Override
9160 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009161 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009162 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009163
9164 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009165 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009166 if (phone == null) {
9167 return null;
9168 }
9169 String esn = null;
9170 try {
9171 esn = phone.getEsn();
9172 } catch (Exception e) {
9173 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9174 }
9175 return esn;
9176 } finally {
9177 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009178 }
Youhan Wang4001d252016-05-11 10:29:41 -07009179 }
9180
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009181 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009182 * Return the Preferred Roaming List Version.
9183 *
9184 * @param subId the subscription ID that this request applies to.
9185 * @return PRLVersion or null if error.
9186 */
9187 @Override
9188 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009189 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009190
9191 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9192 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9193
Youhan Wang66ad5d72016-07-18 17:56:58 -07009194 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009195
9196 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009197 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009198 if (phone == null) {
9199 return null;
9200 }
9201 String cdmaPrlVersion = null;
9202 try {
9203 cdmaPrlVersion = phone.getCdmaPrlVersion();
9204 } catch (Exception e) {
9205 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9206 }
9207 return cdmaPrlVersion;
9208 } finally {
9209 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009210 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009211 }
9212
9213 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009214 * Get snapshot of Telephony histograms
9215 * @return List of Telephony histograms
9216 * @hide
9217 */
9218 @Override
9219 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9221 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009222
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
9225 return RIL.getTelephonyRILTimingHistograms();
9226 } finally {
9227 Binder.restoreCallingIdentity(identity);
9228 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009229 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009230
9231 /**
9232 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009233 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9234 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009235 * Require system privileges. In the future we may add this to carrier APIs.
9236 *
Michele Berionne482f8202018-11-27 18:57:59 -08009237 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009238 */
9239 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009240 @TelephonyManager.SetCarrierRestrictionResult
9241 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009242 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009243
9244 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9245 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9246
vagdeviaf9a5b92018-08-15 16:01:53 -07009247 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009248
Michele Berionne482f8202018-11-27 18:57:59 -08009249 if (carrierRestrictionRules == null) {
9250 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009251 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009253 final long identity = Binder.clearCallingIdentity();
9254 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009255 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009256 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009257 } finally {
9258 Binder.restoreCallingIdentity(identity);
9259 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009260 }
9261
9262 /**
9263 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009264 * Get the allowed carrier list and the excluded carrier list, including the priority between
9265 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009266 * Require system privileges. In the future we may add this to carrier APIs.
9267 *
Michele Berionne482f8202018-11-27 18:57:59 -08009268 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009269 */
9270 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009271 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009272 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009273
9274 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9275 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9276
vagdeviaf9a5b92018-08-15 16:01:53 -07009277 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009278
9279 final long identity = Binder.clearCallingIdentity();
9280 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009281 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9282 if (response instanceof CarrierRestrictionRules) {
9283 return (CarrierRestrictionRules) response;
9284 }
9285 // Response is an Exception of some kind,
9286 // which is signalled to the user as a NULL retval
9287 return null;
9288 } catch (Exception e) {
9289 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9290 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009291 } finally {
9292 Binder.restoreCallingIdentity(identity);
9293 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009294 }
9295
fionaxu59545b42016-05-25 15:53:37 -07009296 /**
arunvoddud7401012022-12-15 16:08:12 +00009297 * Fetches the carrier restriction status of the device and sends the status to the caller
9298 * through the callback.
9299 *
9300 * @param callback The callback that will be used to send the result.
9301 * @throws SecurityException if the caller does not have the required permission/privileges or
9302 * the caller is not allowlisted.
9303 */
9304 @Override
9305 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9306 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009307
9308 enforceTelephonyFeatureWithException(packageName,
9309 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9310
Steve Statia28b7cb32024-03-11 23:58:50 +00009311 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9312 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009313 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9314 throw new SecurityException("Not an authorized caller");
9315 }
9316 final long identity = Binder.clearCallingIdentity();
9317 try {
9318 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009319 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009320 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9321 } finally {
9322 Binder.restoreCallingIdentity(identity);
9323 }
9324 }
9325
arunvoddu567f2b42023-04-25 17:22:00 +00009326 @Override
9327 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9328 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9329 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9330 return allowListInfo.getShaIdList(pkgName, carrierId);
9331 }
9332
arunvoddud7401012022-12-15 16:08:12 +00009333 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009334 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009335 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009336 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009337 }
9338
9339 /**
fionaxu59545b42016-05-25 15:53:37 -07009340 * Action set from carrier signalling broadcast receivers to enable/disable radio
9341 * @param subId the subscription ID that this action applies to.
9342 * @param enabled control enable or disable radio.
9343 * {@hide}
9344 */
9345 @Override
9346 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9347 enforceModifyPermission();
9348 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009349
9350 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009351 if (phone == null) {
9352 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9353 return;
9354 }
9355 try {
9356 phone.carrierActionSetRadioEnabled(enabled);
9357 } catch (Exception e) {
9358 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009359 } finally {
9360 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009361 }
9362 }
9363
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009364 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009365 * Enable or disable Voice over NR (VoNR)
9366 * @param subId the subscription ID that this action applies to.
9367 * @param enabled enable or disable VoNR.
9368 * @return operation result.
9369 */
9370 @Override
9371 public int setVoNrEnabled(int subId, boolean enabled) {
9372 enforceModifyPermission();
9373 final Phone phone = getPhone(subId);
9374
9375 final long identity = Binder.clearCallingIdentity();
9376 if (phone == null) {
9377 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9378 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9379 }
9380
9381 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9382 try {
9383 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9384 workSource);
9385 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009386
9387 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9388 if (DBG) {
9389 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9390 }
9391 SubscriptionManager.setSubscriptionProperty(
9392 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9393 (enabled ? "1" : "0"));
9394 }
9395
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009396 return result;
9397 } finally {
9398 Binder.restoreCallingIdentity(identity);
9399 }
9400 }
9401
9402 /**
9403 * Is voice over NR enabled
9404 * @return true if VoNR is enabled else false
9405 */
9406 @Override
9407 public boolean isVoNrEnabled(int subId) {
9408 enforceReadPrivilegedPermission("isVoNrEnabled");
9409 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9410 final long identity = Binder.clearCallingIdentity();
9411 try {
9412 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9413 null, subId, workSource);
9414 if (DBG) log("isVoNrEnabled: " + isEnabled);
9415 return isEnabled;
9416 } finally {
9417 Binder.restoreCallingIdentity(identity);
9418 }
9419 }
9420
9421 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009422 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9423 * network status based on which carrier apps could apply actions accordingly,
9424 * enable/disable default url handler for example.
9425 *
9426 * @param subId the subscription ID that this action applies to.
9427 * @param report control start/stop reporting the default network status.
9428 * {@hide}
9429 */
9430 @Override
9431 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9432 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009433
9434 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9435 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9436 "carrierActionReportDefaultNetworkStatus");
9437
fionaxu8da9cb12017-05-23 15:02:46 -07009438 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009439
9440 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009441 if (phone == null) {
9442 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9443 return;
9444 }
9445 try {
9446 phone.carrierActionReportDefaultNetworkStatus(report);
9447 } catch (Exception e) {
9448 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009449 } finally {
9450 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009451 }
9452 }
9453
9454 /**
fionaxud9622282017-07-17 17:51:30 -07009455 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9456 * @param subId the subscription ID that this action applies to.
9457 * {@hide}
9458 */
9459 @Override
9460 public void carrierActionResetAll(int subId) {
9461 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009462
9463 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9464 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9465
fionaxud9622282017-07-17 17:51:30 -07009466 final Phone phone = getPhone(subId);
9467 if (phone == null) {
9468 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9469 return;
9470 }
9471 try {
9472 phone.carrierActionResetAll();
9473 } catch (Exception e) {
9474 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9475 }
9476 }
9477
9478 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009479 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9480 * bug report is being generated.
9481 */
9482 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009483 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009484 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9485 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009486 writer.println("Permission Denial: can't dump Phone from pid="
9487 + Binder.getCallingPid()
9488 + ", uid=" + Binder.getCallingUid()
9489 + "without permission "
9490 + android.Manifest.permission.DUMP);
9491 return;
9492 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009493 try {
9494 DumpsysHandler.dump(mApp, fd, writer, args);
9495 } catch (Exception e) {
9496 writer.println("Failed to dump phone information: " + e);
9497 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009498 }
Jack Yueb89b242016-06-22 13:27:47 -07009499
Brad Ebingerdac2f002018-04-03 15:17:52 -07009500 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009501 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9502 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9503 @NonNull String[] args) {
9504 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9505 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009506 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009507 }
9508
Jack Yueb89b242016-06-22 13:27:47 -07009509 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009510 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009511 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009512 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009513 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009514 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009515 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009516 */
9517 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009518 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009519 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009520 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9521 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9522 try {
9523 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009524 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009525 } catch (SecurityException se) {
9526 enforceModifyPermission();
9527 }
9528 } else {
9529 enforceModifyPermission();
9530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009531
joonhunshin4ac60942023-11-15 15:23:39 +00009532 enforceTelephonyFeatureWithException(callingPackage,
9533 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9534
Nate Myren116695d2024-02-09 09:36:01 -08009535 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009536 final long identity = Binder.clearCallingIdentity();
9537 try {
Nate Myren116695d2024-02-09 09:36:01 -08009538 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9539 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009540 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009541 callingUid, callingPackage, null, null);
9542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009543 Phone phone = getPhone(subId);
9544 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009545 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9546 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009547 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009548 phone.getDataSettingsManager().setDataEnabled(
9549 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009550 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009551 }
9552 } finally {
9553 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009554 }
9555 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009556
9557 /**
9558 * Get Client request stats
9559 * @return List of Client Request Stats
9560 * @hide
9561 */
9562 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009563 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9564 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009566 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009567 return null;
9568 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009569 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009571 final long identity = Binder.clearCallingIdentity();
9572 try {
9573 if (phone != null) {
9574 return phone.getClientRequestStats();
9575 }
9576
9577 return null;
9578 } finally {
9579 Binder.restoreCallingIdentity(identity);
9580 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009581 }
9582
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009583 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009584 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009585 if (uid == Process.ROOT_UID && packageName == null) {
9586 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9587 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9588 // exception. ROOT_UID seems not to have a valid package name returned by
9589 // PackageManager, so just fake it here to avoid issues when running telephony shell
9590 // commands that plumb through the RIL as root, like so:
9591 // $ adb root
9592 // $ adb shell cmd phone ...
9593 packageName = "root";
9594 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009595 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009596 }
Jack Yueb4124c2017-02-16 15:32:43 -08009597
9598 /**
Grace Chen70990072017-03-24 17:21:30 -07009599 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009600 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009601 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009602 * @param state State of SIM (power down, power up, pass through)
9603 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9604 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9605 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009606 *
9607 **/
9608 @Override
Grace Chen70990072017-03-24 17:21:30 -07009609 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009610 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009611
9612 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9613 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9614
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009615 Phone phone = PhoneFactory.getPhone(slotIndex);
9616
vagdeviaf9a5b92018-08-15 16:01:53 -07009617 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009619 final long identity = Binder.clearCallingIdentity();
9620 try {
9621 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009622 phone.setSimPowerState(state, null, workSource);
9623 }
9624 } finally {
9625 Binder.restoreCallingIdentity(identity);
9626 }
9627 }
9628
9629 /**
9630 * Set SIM card power state.
9631 *
9632 * @param slotIndex SIM slot id.
9633 * @param state State of SIM (power down, power up, pass through)
9634 * @param callback callback to trigger after success or failure
9635 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9636 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9637 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9638 *
9639 **/
9640 @Override
9641 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9642 IIntegerConsumer callback) {
9643 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009644
9645 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9646 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9647 "setSimPowerStateForSlotWithCallback");
9648
Jordan Liu109698e2020-11-24 14:50:34 -08009649 Phone phone = PhoneFactory.getPhone(slotIndex);
9650
9651 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9652
9653 final long identity = Binder.clearCallingIdentity();
9654 try {
9655 if (phone != null) {
9656 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9657 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009658 }
9659 } finally {
9660 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009661 }
9662 }
Shuo Qiandd210312017-04-12 22:11:33 +00009663
Tyler Gunn65d45c22017-06-05 11:22:26 -07009664 private boolean isUssdApiAllowed(int subId) {
9665 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009666 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009667 if (configManager == null) {
9668 return false;
9669 }
9670 PersistableBundle pb = configManager.getConfigForSubId(subId);
9671 if (pb == null) {
9672 return false;
9673 }
9674 return pb.getBoolean(
9675 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9676 }
9677
Shuo Qiandd210312017-04-12 22:11:33 +00009678 /**
Ling Mac28f0212023-03-24 16:07:15 -07009679 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009680 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009681 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009682 */
goneil9c5f4872017-12-05 14:07:56 -08009683 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009684 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009685 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009686
9687 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9688 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009690 final long identity = Binder.clearCallingIdentity();
9691 try {
Ling Mac28f0212023-03-24 16:07:15 -07009692 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009693 } finally {
9694 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009695 }
9696 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009697
9698 /**
9699 * Get the current signal strength information for the given subscription.
9700 * Because this information is not updated when the device is in a low power state
9701 * it should not be relied-upon to be current.
9702 * @param subId Subscription index
9703 * @return the most recent cached signal strength info from the modem
9704 */
9705 @Override
9706 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009707 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9708 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009710 final long identity = Binder.clearCallingIdentity();
9711 try {
9712 Phone p = getPhone(subId);
9713 if (p == null) {
9714 return null;
9715 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009717 return p.getSignalStrength();
9718 } finally {
9719 Binder.restoreCallingIdentity(identity);
9720 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009721 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009722
Pengquan Meng77b7f132018-08-22 14:49:57 -07009723 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009724 * Get the current modem radio state for the given slot.
9725 * @param slotIndex slot index.
9726 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009727 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009728 * @return the current radio power state from the modem
9729 */
9730 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009731 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009732 Phone phone = PhoneFactory.getPhone(slotIndex);
9733 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9735 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009736 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9737 }
9738
joonhunshin4ac60942023-11-15 15:23:39 +00009739 enforceTelephonyFeatureWithException(callingPackage,
9740 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9741
Chen Xuf792fd62018-10-17 17:54:36 +00009742 final long identity = Binder.clearCallingIdentity();
9743 try {
9744 return phone.getRadioPowerState();
9745 } finally {
9746 Binder.restoreCallingIdentity(identity);
9747 }
9748 }
9749 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9750 }
9751
9752 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009753 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9754 *
9755 * <p>Requires one of the following permissions:
9756 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009757 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009758 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9759 * privileges.
9760 *
9761 * @param subId subscription id
9762 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9763 * {@code false}.
9764 */
9765 @Override
9766 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009767 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009768 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009769 try {
9770 mApp.enforceCallingOrSelfPermission(
9771 android.Manifest.permission.ACCESS_NETWORK_STATE,
9772 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009773 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009774 mApp.enforceCallingOrSelfPermission(
9775 permission.READ_BASIC_PHONE_STATE, functionName);
9776 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009777 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009778 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009779 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009780 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009781
joonhunshin4ac60942023-11-15 15:23:39 +00009782 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9783 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9784
Pengquan Menga1bb6272018-09-06 09:59:22 -07009785 boolean isEnabled = false;
9786 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009787 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009788 Phone phone = getPhone(subId);
9789 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009790 } finally {
9791 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009792 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009793 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009794 }
9795
9796
9797 /**
9798 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9799 *
9800 * <p> Requires permission:
9801 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9802 * privileges.
9803 *
9804 * @param subId subscription id
9805 * @param isEnabled {@code true} means enable, {@code false} means disable.
9806 */
9807 @Override
9808 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9810 mApp, subId, "setDataRoamingEnabled");
9811
joonhunshin4ac60942023-11-15 15:23:39 +00009812 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9813 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9814
Pengquan Menga1bb6272018-09-06 09:59:22 -07009815 final long identity = Binder.clearCallingIdentity();
9816 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009817 Phone phone = getPhone(subId);
9818 if (phone != null) {
9819 phone.setDataRoamingEnabled(isEnabled);
9820 }
9821 } finally {
9822 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009823 }
9824 }
9825
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009826 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009827 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009828 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009829 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009830 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009831
joonhunshin4ac60942023-11-15 15:23:39 +00009832 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9833 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9834
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009835 boolean isAllowed = true;
9836 final long identity = Binder.clearCallingIdentity();
9837 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009838 Phone phone = getPhone(subId);
9839 if (phone != null) {
9840 isAllowed = phone.isCspPlmnEnabled();
9841 }
9842 } finally {
9843 Binder.restoreCallingIdentity(identity);
9844 }
9845 return isAllowed;
9846 }
9847
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009848 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9849 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009850 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009851 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009852 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009853 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9854 if (phone == null) {
9855 return false;
9856 }
9857 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9858 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9859 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009860 }
9861
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009862 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009863 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009864 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009865 mApp.getSystemService(AppOpsManager.class)
9866 .checkPackage(Binder.getCallingUid(), callingPackage);
9867
Jordan Liu1e142fc2019-04-22 15:10:43 -07009868 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009869 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009870 try {
9871 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009872 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009873 } catch (SecurityException e) {
9874 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9875 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009876 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009877 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009878 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009879 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009880 }
joonhunshin4ac60942023-11-15 15:23:39 +00009881
9882 enforceTelephonyFeatureWithException(callingPackage,
9883 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9884
sandeepjsb6c87872021-09-27 15:34:44 +00009885 // checking compatibility, if calling app's target SDK is T and beyond.
9886 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9887 Binder.getCallingUid())) {
9888 isIccIdAccessRestricted = true;
9889 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009890 final long identity = Binder.clearCallingIdentity();
9891 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009892 UiccController uiccController = UiccController.getInstance();
9893 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009894 if (hasReadPermission) {
9895 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009896 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009897
9898 // Remove private info if the caller doesn't have access
9899 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9900 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009901 //setting the value after compatibility check
9902 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009903 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9904 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009905 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009906 if (card == null) {
9907 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009908 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009909 continue;
9910 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009911 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9912 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009913 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009914 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009915 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009916 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9917 for (UiccPortInfo portInfo : portInfos) {
9918 UiccPort port = uiccController.getUiccPortForSlot(
9919 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9920 if (port == null) {
9921 // assume no access if port is null
9922 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9923 continue;
9924 }
9925 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9926 uiccPortInfos.add(portInfo);
9927 } else {
9928 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9929 }
9930 }
9931 filteredInfos.add(new UiccCardInfo(
9932 cardInfo.isEuicc(),
9933 cardInfo.getCardId(),
9934 null,
9935 cardInfo.getPhysicalSlotIndex(),
9936 cardInfo.isRemovable(),
9937 cardInfo.isMultipleEnabledProfilesSupported(),
9938 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009939 }
9940 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009941 } finally {
9942 Binder.restoreCallingIdentity(identity);
9943 }
9944 }
9945
sandeepjsb6c87872021-09-27 15:34:44 +00009946 /**
9947 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9948 * generally private and require carrier privileges to view.
9949 *
9950 * @hide
9951 */
9952 @NonNull
9953 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9954 List<UiccPortInfo> portinfo = new ArrayList<>();
9955 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9956 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9957 }
9958 return new UiccCardInfo(
9959 cardInfo.isEuicc(),
9960 cardInfo.getCardId(),
9961 null,
9962 cardInfo.getPhysicalSlotIndex(),
9963 cardInfo.isRemovable(),
9964 cardInfo.isMultipleEnabledProfilesSupported(),
9965 portinfo
9966 );
9967 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009968
sandeepjsb6c87872021-09-27 15:34:44 +00009969 /**
9970 * @hide
9971 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9972 * These values are generally private and require carrier privileges to view.
9973 */
9974 @NonNull
9975 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9976 return new UiccPortInfo(
9977 UiccPortInfo.ICCID_REDACTED,
9978 portInfo.getPortIndex(),
9979 portInfo.getLogicalSlotIndex(),
9980 portInfo.isActive()
9981 );
9982 }
9983 @Override
9984 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009985 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009986 mApp.getSystemService(AppOpsManager.class)
9987 .checkPackage(Binder.getCallingUid(), callingPackage);
9988
sandeepjsb6c87872021-09-27 15:34:44 +00009989 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009990
Aman Guptaf3c90b32022-03-17 04:54:16 +00009991 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9992 // we are reading iccId which is PII data.
9993 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009994
joonhunshin4ac60942023-11-15 15:23:39 +00009995 enforceTelephonyFeatureWithException(callingPackage,
9996 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9997
sandeepjsb6c87872021-09-27 15:34:44 +00009998 // checking compatibility, if calling app's target SDK is T and beyond.
9999 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10000 Binder.getCallingUid())) {
10001 isLogicalSlotAccessRestricted = true;
10002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010003 final long identity = Binder.clearCallingIdentity();
10004 try {
10005 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010006 if (slots == null || slots.length == 0) {
10007 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010008 return null;
10009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010010 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10011 for (int i = 0; i < slots.length; i++) {
10012 UiccSlot slot = slots[i];
10013 if (slot == null) {
10014 continue;
10015 }
10016
Jordan Liu7be7e652019-05-06 18:55:02 +000010017 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010018 UiccCard card = slot.getUiccCard();
10019 if (card != null) {
10020 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010021 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010022 cardId = slot.getEid();
10023 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010024 // If cardId is null, use iccId of default port as cardId.
10025 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010027 }
10028
Jordan Liu857451f2019-05-09 16:35:35 -070010029 if (cardId != null) {
10030 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10031 // if cardId is an EID, it's all digits so this is fine
10032 cardId = IccUtils.stripTrailingFs(cardId);
10033 }
10034
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010035 int cardState = 0;
10036 switch (slot.getCardState()) {
10037 case CARDSTATE_ABSENT:
10038 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10039 break;
10040 case CARDSTATE_PRESENT:
10041 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10042 break;
10043 case CARDSTATE_ERROR:
10044 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10045 break;
10046 case CARDSTATE_RESTRICTED:
10047 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10048 break;
10049 default:
10050 break;
10051
10052 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010053 List<UiccPortInfo> portInfos = new ArrayList<>();
10054 int[] portIndexes = slot.getPortList();
10055 for (int portIdx : portIndexes) {
10056 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010057 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010058 portInfos.add(new UiccPortInfo(iccId, portIdx,
10059 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010060 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010061 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010062 slot.isEuicc(),
10063 cardId,
10064 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010065 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010066 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010067 //setting the value after compatibility check
10068 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010069 }
10070 return infos;
10071 } finally {
10072 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010073 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010074 }
10075
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010076 /* Returns null if doesn't have read permission or carrier privilege access. */
10077 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10078 boolean hasReadPermission) {
10079 String iccId = slot.getIccId(portIndex);
10080 if (hasReadPermission) { // if has read permission
10081 return iccId;
10082 } else {
10083 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10084 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10085 // if no read permission, checking carrier privilege access
10086 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10087 return iccId;
10088 }
10089 }
10090 }
10091 // No read permission or carrier privilege access.
10092 return UiccPortInfo.ICCID_REDACTED;
10093 }
10094
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010095 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010096 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010097 public boolean switchSlots(int[] physicalSlots) {
10098 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010099
joonhunshin4ac60942023-11-15 15:23:39 +000010100 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10101 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10102
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010103 final long identity = Binder.clearCallingIdentity();
10104 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010105 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10106 for (int i = 0; i < physicalSlots.length; i++) {
10107 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10108 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10109 physicalSlots[i], i));
10110 }
10111 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010112 } finally {
10113 Binder.restoreCallingIdentity(identity);
10114 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010115 }
Jack Yu4c988042018-02-27 15:30:01 -080010116
10117 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010118 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10119 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10120 enforceModifyPermission();
10121
joonhunshin4ac60942023-11-15 15:23:39 +000010122 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10123 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10124
sandeepjsb6c87872021-09-27 15:34:44 +000010125 final long identity = Binder.clearCallingIdentity();
10126 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010127 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010128 } finally {
10129 Binder.restoreCallingIdentity(identity);
10130 }
10131 }
10132
10133 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010134 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010135 enforceTelephonyFeatureWithException(callingPackage,
10136 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10137
Jordan Liu7de49fa2018-12-06 14:48:49 -080010138 final long identity = Binder.clearCallingIdentity();
10139 try {
10140 return UiccController.getInstance().getCardIdForDefaultEuicc();
10141 } finally {
10142 Binder.restoreCallingIdentity(identity);
10143 }
10144 }
10145
Pengquan Meng85728fb2018-03-12 16:31:21 -070010146 /**
goneil47ffb6e2018-04-06 15:40:58 -070010147 * A test API to reload the UICC profile.
10148 *
10149 * <p>Requires that the calling app has permission
10150 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10151 * @hide
10152 */
10153 @Override
10154 public void refreshUiccProfile(int subId) {
10155 enforceModifyPermission();
10156
10157 final long identity = Binder.clearCallingIdentity();
10158 try {
10159 Phone phone = getPhone(subId);
10160 if (phone == null) {
10161 return;
10162 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010163 UiccPort uiccPort = phone.getUiccPort();
10164 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010165 return;
10166 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010167 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010168 if (uiccProfile == null) {
10169 return;
10170 }
10171 uiccProfile.refresh();
10172 } finally {
10173 Binder.restoreCallingIdentity(identity);
10174 }
10175 }
10176
10177 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010178 * Returns false if the mobile data is disabled by default, otherwise return true.
10179 */
10180 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010181 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010182 }
10183
10184 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010185 * Returns the default network type for the given {@code subId}, if the default network type is
10186 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10187 */
10188 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010189 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010190 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010191 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10192 return list.get(phoneId);
10193 }
10194 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010195 }
fionaxua13278b2018-03-21 00:08:13 -070010196
10197 @Override
10198 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010199 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010200 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010201
10202 final long identity = Binder.clearCallingIdentity();
10203 try {
10204 final Phone phone = getPhone(subId);
10205 if (phone == null) {
10206 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10207 return;
10208 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010209 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10210 if (cpt != null) {
10211 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10212 }
10213 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010214 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10215 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010216 if (carrierPrivilegeRules == null) {
10217 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10218 } else {
10219 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10220 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010221 } finally {
10222 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010223 }
fionaxua13278b2018-03-21 00:08:13 -070010224 }
10225
10226 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010227 public void setCarrierServicePackageOverride(
10228 int subId, String carrierServicePackage, String callingPackage) {
10229 TelephonyPermissions.enforceShellOnly(
10230 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10231
Benedict Wong66477622023-02-03 23:30:57 +000010232 final long identity = Binder.clearCallingIdentity();
10233 try {
10234 final Phone phone = getPhone(subId);
10235 if (phone == null || phone.getSubId() != subId) {
10236 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10237 throw new IllegalArgumentException("No phone for subid");
10238 }
10239 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10240 if (cpt == null) {
10241 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10242 throw new IllegalStateException("No CPT for phone");
10243 }
10244 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10245 } finally {
10246 Binder.restoreCallingIdentity(identity);
10247 }
10248 }
10249
10250 @Override
fionaxua13278b2018-03-21 00:08:13 -070010251 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010252 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010253
10254 final long identity = Binder.clearCallingIdentity();
10255 try {
10256 final Phone phone = getPhone(subId);
10257 if (phone == null) {
10258 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10259 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10260 }
10261 return phone.getCarrierIdListVersion();
10262 } finally {
10263 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010264 }
fionaxua13278b2018-03-21 00:08:13 -070010265 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010266
10267 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010268 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10269 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010271 mApp, subId, callingPackage, callingFeatureId,
10272 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010273 return -1;
10274 }
10275
10276 final long identity = Binder.clearCallingIdentity();
10277 try {
10278 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10279 } finally {
10280 Binder.restoreCallingIdentity(identity);
10281 }
10282 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010283
10284 @Override
10285 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010286 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010287 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010288 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010289
joonhunshin4ac60942023-11-15 15:23:39 +000010290 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10291 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10292
Pengquan Menga1bb6272018-09-06 09:59:22 -070010293 final long identity = Binder.clearCallingIdentity();
10294 try {
10295 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10296 } finally {
10297 Binder.restoreCallingIdentity(identity);
10298 }
10299 }
10300
10301 @Override
10302 public boolean setCdmaRoamingMode(int subId, int mode) {
10303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10304 mApp, subId, "setCdmaRoamingMode");
10305
joonhunshin4ac60942023-11-15 15:23:39 +000010306 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10307 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10308
Pengquan Menga1bb6272018-09-06 09:59:22 -070010309 final long identity = Binder.clearCallingIdentity();
10310 try {
10311 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10312 } finally {
10313 Binder.restoreCallingIdentity(identity);
10314 }
10315 }
10316
10317 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010318 public int getCdmaSubscriptionMode(int subId) {
10319 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010320 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010321 mApp, subId, "getCdmaSubscriptionMode");
10322
joonhunshin4ac60942023-11-15 15:23:39 +000010323 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10324 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10325
Sarah Chinbaab1432020-10-28 13:46:24 -070010326 final long identity = Binder.clearCallingIdentity();
10327 try {
10328 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10329 } finally {
10330 Binder.restoreCallingIdentity(identity);
10331 }
10332 }
10333
10334 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010335 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10337 mApp, subId, "setCdmaSubscriptionMode");
10338
joonhunshin4ac60942023-11-15 15:23:39 +000010339 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10340 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10341
Pengquan Menga1bb6272018-09-06 09:59:22 -070010342 final long identity = Binder.clearCallingIdentity();
10343 try {
10344 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10345 } finally {
10346 Binder.restoreCallingIdentity(identity);
10347 }
10348 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010349
sqianc5eccab2018-10-19 18:46:41 -070010350 @Override
sqian8c685422019-02-22 15:55:18 -080010351 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010352 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010353 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010354 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10355 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010356 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10357 }
joonhunshin4ac60942023-11-15 15:23:39 +000010358
10359 enforceTelephonyFeatureWithException(callingPackage,
10360 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10361
sqian11b7a0e2018-12-05 18:48:28 -080010362 final long identity = Binder.clearCallingIdentity();
10363 try {
sqian854d44b2018-12-12 16:48:18 -080010364 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10365 for (Phone phone: PhoneFactory.getPhones()) {
10366 if (phone.getEmergencyNumberTracker() != null
10367 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10368 emergencyNumberListInternal.put(
10369 phone.getSubId(),
10370 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10371 }
sqian11b7a0e2018-12-05 18:48:28 -080010372 }
sqian854d44b2018-12-12 16:48:18 -080010373 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010374 } finally {
10375 Binder.restoreCallingIdentity(identity);
10376 }
sqianc5eccab2018-10-19 18:46:41 -070010377 }
10378
10379 @Override
sqian8c685422019-02-22 15:55:18 -080010380 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010381 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010382 if (!exactMatch) {
10383 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010384 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010385 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010386 }
joonhunshin4ac60942023-11-15 15:23:39 +000010387
10388 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10389 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10390
sqian11b7a0e2018-12-05 18:48:28 -080010391 final long identity = Binder.clearCallingIdentity();
10392 try {
sqian854d44b2018-12-12 16:48:18 -080010393 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010394 //Note: we ignore passed in param exactMatch. We can remove it once
10395 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010396 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010397 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010398 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010399 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010400 }
sqian11b7a0e2018-12-05 18:48:28 -080010401 }
10402 return false;
10403 } finally {
10404 Binder.restoreCallingIdentity(identity);
10405 }
10406 }
10407
sqianf4ca7ed2019-01-15 18:32:07 -080010408 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010409 * Start emergency callback mode for GsmCdmaPhone for testing.
10410 */
10411 @Override
10412 public void startEmergencyCallbackMode() {
10413 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10414 "startEmergencyCallbackMode");
10415 enforceModifyPermission();
10416 final long identity = Binder.clearCallingIdentity();
10417 try {
10418 for (Phone phone : PhoneFactory.getPhones()) {
10419 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10420 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10421 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10422 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10423 gsmCdmaPhone.obtainMessage(
10424 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10425 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10426 }
10427 }
10428 } finally {
10429 Binder.restoreCallingIdentity(identity);
10430 }
10431 }
10432
10433 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010434 * Update emergency number list for test mode.
10435 */
10436 @Override
10437 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10438 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10439 "updateEmergencyNumberListTestMode");
10440
10441 final long identity = Binder.clearCallingIdentity();
10442 try {
10443 for (Phone phone: PhoneFactory.getPhones()) {
10444 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10445 if (tracker != null) {
10446 tracker.executeEmergencyNumberTestModeCommand(action, num);
10447 }
10448 }
10449 } finally {
10450 Binder.restoreCallingIdentity(identity);
10451 }
10452 }
10453
10454 /**
10455 * Get the full emergency number list for test mode.
10456 */
10457 @Override
10458 public List<String> getEmergencyNumberListTestMode() {
10459 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10460 "getEmergencyNumberListTestMode");
10461
10462 final long identity = Binder.clearCallingIdentity();
10463 try {
10464 Set<String> emergencyNumbers = new HashSet<>();
10465 for (Phone phone: PhoneFactory.getPhones()) {
10466 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10467 if (tracker != null) {
10468 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10469 emergencyNumbers.add(num.getNumber());
10470 }
10471 }
10472 }
10473 return new ArrayList<>(emergencyNumbers);
10474 } finally {
10475 Binder.restoreCallingIdentity(identity);
10476 }
10477 }
10478
chen xud6b45bd2018-10-30 22:27:10 -070010479 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010480 public int getEmergencyNumberDbVersion(int subId) {
10481 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10482
joonhunshin4ac60942023-11-15 15:23:39 +000010483 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10484 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10485
Shuo Qian3b6ee772019-11-13 17:43:31 -080010486 final long identity = Binder.clearCallingIdentity();
10487 try {
10488 final Phone phone = getPhone(subId);
10489 if (phone == null) {
10490 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10491 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10492 }
10493 return phone.getEmergencyNumberDbVersion();
10494 } finally {
10495 Binder.restoreCallingIdentity(identity);
10496 }
10497 }
10498
10499 @Override
10500 public void notifyOtaEmergencyNumberDbInstalled() {
10501 enforceModifyPermission();
10502
joonhunshin4ac60942023-11-15 15:23:39 +000010503 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10504 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10505
Shuo Qian3b6ee772019-11-13 17:43:31 -080010506 final long identity = Binder.clearCallingIdentity();
10507 try {
10508 for (Phone phone: PhoneFactory.getPhones()) {
10509 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10510 if (tracker != null) {
10511 tracker.updateOtaEmergencyNumberDatabase();
10512 }
10513 }
10514 } finally {
10515 Binder.restoreCallingIdentity(identity);
10516 }
10517 }
10518
10519 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010520 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010521 enforceActiveEmergencySessionPermission();
10522
joonhunshin4ac60942023-11-15 15:23:39 +000010523 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10524 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10525
Shuo Qian3b6ee772019-11-13 17:43:31 -080010526 final long identity = Binder.clearCallingIdentity();
10527 try {
10528 for (Phone phone: PhoneFactory.getPhones()) {
10529 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10530 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010531 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10532 }
10533 }
10534 } finally {
10535 Binder.restoreCallingIdentity(identity);
10536 }
10537 }
10538
10539 @Override
10540 public void resetOtaEmergencyNumberDbFilePath() {
10541 enforceActiveEmergencySessionPermission();
10542
joonhunshin4ac60942023-11-15 15:23:39 +000010543 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10544 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10545
Shuo Qianc373f112020-03-05 17:55:34 -080010546 final long identity = Binder.clearCallingIdentity();
10547 try {
10548 for (Phone phone: PhoneFactory.getPhones()) {
10549 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10550 if (tracker != null) {
10551 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010552 }
10553 }
10554 } finally {
10555 Binder.restoreCallingIdentity(identity);
10556 }
10557 }
10558
10559 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010560 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10561 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10562 Phone phone = getPhone(subId);
10563 if (phone == null) {
10564 return null;
10565 }
10566 final long identity = Binder.clearCallingIdentity();
10567 try {
10568 UiccProfile profile = UiccController.getInstance()
10569 .getUiccProfileForPhone(phone.getPhoneId());
10570 if (profile != null) {
10571 return profile.getCertsFromCarrierPrivilegeAccessRules();
10572 }
10573 } finally {
10574 Binder.restoreCallingIdentity(identity);
10575 }
10576 return null;
10577 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010578
10579 /**
10580 * Enable or disable a modem stack.
10581 */
10582 @Override
10583 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10584 enforceModifyPermission();
10585
joonhunshin4ac60942023-11-15 15:23:39 +000010586 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10587 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10588
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010589 final long identity = Binder.clearCallingIdentity();
10590 try {
10591 Phone phone = PhoneFactory.getPhone(slotIndex);
10592 if (phone == null) {
10593 return false;
10594 } else {
10595 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10596 }
10597 } finally {
10598 Binder.restoreCallingIdentity(identity);
10599 }
10600 }
Michelecea4cf22018-12-21 15:00:11 -080010601
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010602 /**
10603 * Whether a modem stack is enabled or not.
10604 */
10605 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010606 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10607 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010608 Phone phone = PhoneFactory.getPhone(slotIndex);
10609 if (phone == null) return false;
10610
10611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010612 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10613 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010614 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10615 }
10616
joonhunshin4ac60942023-11-15 15:23:39 +000010617 enforceTelephonyFeatureWithException(callingPackage,
10618 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10619
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010620 final long identity = Binder.clearCallingIdentity();
10621 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010622 try {
10623 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10624 } catch (NoSuchElementException ex) {
10625 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10626 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010627 } finally {
10628 Binder.restoreCallingIdentity(identity);
10629 }
10630 }
10631
Michelecea4cf22018-12-21 15:00:11 -080010632 @Override
Michele0ea7d782019-03-19 14:58:42 -070010633 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010634 enforceModifyPermission();
10635
joonhunshin4ac60942023-11-15 15:23:39 +000010636 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10637 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10638
Michelecea4cf22018-12-21 15:00:11 -080010639 final long identity = Binder.clearCallingIdentity();
10640 try {
10641 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010642 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010643 .commit();
10644 } finally {
10645 Binder.restoreCallingIdentity(identity);
10646 }
10647 }
10648
10649 @Override
Michele0ea7d782019-03-19 14:58:42 -070010650 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010651 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010652 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010653 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10654 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010655 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010656 }
Michelecea4cf22018-12-21 15:00:11 -080010657
joonhunshin4ac60942023-11-15 15:23:39 +000010658 enforceTelephonyFeatureWithException(callingPackage,
10659 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10660
Michelecea4cf22018-12-21 15:00:11 -080010661 final long identity = Binder.clearCallingIdentity();
10662 try {
Michele0ea7d782019-03-19 14:58:42 -070010663 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010664 } finally {
10665 Binder.restoreCallingIdentity(identity);
10666 }
10667 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010668
Michele0ea7d782019-03-19 14:58:42 -070010669 @TelephonyManager.IsMultiSimSupportedResult
10670 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010671 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10672 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10673 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010674 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10675 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010676 }
10677 // Check if the hardware supports multisim functionality. If usage of multisim is not
10678 // supported by the modem, indicate that it is restricted.
10679 PhoneCapability staticCapability =
10680 mPhoneConfigurationManager.getStaticPhoneCapability();
10681 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010682 loge("isMultiSimSupportedInternal: no static configuration available");
10683 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010684 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010685 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010686 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10687 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010688 }
10689 // Check if support of multiple SIMs is restricted by carrier
10690 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010691 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010692 }
10693
Michele0ea7d782019-03-19 14:58:42 -070010694 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010695 }
10696
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010697 /**
10698 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010699 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10700 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10701 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010702 * @param numOfSims number of active sims we want to switch to
10703 */
10704 @Override
10705 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010706 if (numOfSims == 1) {
10707 enforceModifyPermission();
10708 } else {
10709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10710 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10711 }
joonhunshin4ac60942023-11-15 15:23:39 +000010712
10713 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10714 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10715
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010716 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010717
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010718 try {
Michele30b57b22019-03-01 12:01:14 -080010719 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010720 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010721 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10722 return;
10723 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010724 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10725 } finally {
10726 Binder.restoreCallingIdentity(identity);
10727 }
10728 }
10729
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010730 @Override
10731 public boolean isApplicationOnUicc(int subId, int appType) {
10732 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010733
10734 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10735 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10736
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010737 Phone phone = getPhone(subId);
10738 if (phone == null) {
10739 return false;
10740 }
10741 final long identity = Binder.clearCallingIdentity();
10742 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010743 UiccPort uiccPort = phone.getUiccPort();
10744 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010745 return false;
10746 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010747 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010748 if (uiccProfile == null) {
10749 return false;
10750 }
10751 if (TelephonyManager.APPTYPE_SIM <= appType
10752 && appType <= TelephonyManager.APPTYPE_ISIM) {
10753 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10754 }
10755 return false;
10756 } finally {
10757 Binder.restoreCallingIdentity(identity);
10758 }
10759 }
10760
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010761 /**
chen xub4baa772019-04-03 10:23:41 -070010762 * Get whether making changes to modem configurations will trigger reboot.
10763 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010764 */
10765 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010766 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10767 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010769 mApp, subId, callingPackage, callingFeatureId,
10770 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010771 return false;
10772 }
joonhunshin4ac60942023-11-15 15:23:39 +000010773
10774 enforceTelephonyFeatureWithException(callingPackage,
10775 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10776 "doesSwitchMultiSimConfigTriggerReboot");
10777
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010778 final long identity = Binder.clearCallingIdentity();
10779 try {
10780 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10781 } finally {
10782 Binder.restoreCallingIdentity(identity);
10783 }
10784 }
10785
Nathan Harold29f5f052019-02-15 13:41:57 -080010786 private void updateModemStateMetrics() {
10787 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10788 // TODO: check the state for each modem if the api is ready.
10789 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10790 }
10791
Pengquan Meng3889a572019-01-23 11:16:29 -080010792 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010793 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010794 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010795 // Verify that the callingPackage belongs to the calling UID
10796 mApp.getSystemService(AppOpsManager.class)
10797 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010798
10799 enforceTelephonyFeatureWithException(callingPackage,
10800 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10801
Pengquan Meng3889a572019-01-23 11:16:29 -080010802 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010803 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010804 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010805 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10806 if (slotInfos != null) {
10807 for (int i = 0; i < slotInfos.length; i++) {
10808 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10809 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10810 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10811 portInfo.getLogicalSlotIndex()));
10812 }
10813 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010814 }
10815 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010816 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010817 } finally {
10818 Binder.restoreCallingIdentity(identity);
10819 }
10820 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010821
10822 /**
10823 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010824 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010825 */
jimsunf9ec1622022-09-13 21:18:43 +080010826 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010827 @Override
10828 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010829 return getHalVersion(HAL_SERVICE_RADIO);
10830 }
10831
10832 /**
10833 * Get the HAL Version of a specific service
10834 */
10835 @Override
10836 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010837 Phone phone = getDefaultPhone();
10838 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010839 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010840 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10841 return hv.major * 100 + hv.minor;
10842 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010843
10844 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010845 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010846 *
10847 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010848 */
10849 @Override
sangyun097dcf72024-01-04 10:35:49 +090010850 public @Nullable String getCurrentPackageName() {
10851 PackageManager pm = mApp.getPackageManager();
10852 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10853 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010854 }
10855
10856 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010857 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10858 * corresponding network requests on a subId.
10859 *
10860 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010861 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010862 * 2) APN is un-metered for this subscription, or
10863 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010864 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010865 *
10866 * @return whether data is allowed for a apn type.
10867 *
10868 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010869 */
10870 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010871 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010872 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10873 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010874
joonhunshin4ac60942023-11-15 15:23:39 +000010875 enforceTelephonyFeatureWithException(callingPackage,
10876 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10877
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010878 // Now that all security checks passes, perform the operation as ourselves.
10879 final long identity = Binder.clearCallingIdentity();
10880 try {
10881 Phone phone = getPhone(subId);
10882 if (phone == null) return false;
10883
Jack Yu27422a52022-03-21 10:38:05 -070010884 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010885 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010886 isMetered = phone.getDataNetworkController().getDataConfigManager()
10887 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10888 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010889 isDataEnabled = (phone.getDataSettingsManager() != null)
10890 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010891 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010892 } finally {
10893 Binder.restoreCallingIdentity(identity);
10894 }
10895 }
10896
10897 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010898 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010899 enforceReadPrivilegedPermission("isApnMetered");
10900
joonhunshin4ac60942023-11-15 15:23:39 +000010901 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10902 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10903
Malcolm Chene5ad5792019-04-18 13:51:02 -070010904 // Now that all security checks passes, perform the operation as ourselves.
10905 final long identity = Binder.clearCallingIdentity();
10906 try {
10907 Phone phone = getPhone(subId);
10908 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010909 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10910 DataUtils.apnTypeToNetworkCapability(apnType),
10911 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010912 } finally {
10913 Binder.restoreCallingIdentity(identity);
10914 }
10915 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010916
10917 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010918 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10919 int subscriptionId, IBooleanConsumer resultCallback) {
10920 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010921
10922 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10923 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10924
Hall Liu73f5d362020-01-20 13:42:00 -080010925 long token = Binder.clearCallingIdentity();
10926 try {
10927 Phone phone = getPhone(subscriptionId);
10928 if (phone == null) {
10929 try {
10930 if (resultCallback != null) {
10931 resultCallback.accept(false);
10932 }
10933 } catch (RemoteException e) {
10934 // ignore
10935 }
10936 return;
10937 }
10938 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10939 Pair.create(specifiers, (x) -> {
10940 try {
10941 if (resultCallback != null) {
10942 resultCallback.accept(x);
10943 }
10944 } catch (RemoteException e) {
10945 // ignore
10946 }
10947 });
10948 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10949 } finally {
10950 Binder.restoreCallingIdentity(token);
10951 }
10952 }
10953
10954 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010955 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10956 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010957 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010958 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010959
10960 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10961 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10962
Sarah Chin679c08a2020-11-18 13:39:35 -080010963 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10964 final long identity = Binder.clearCallingIdentity();
10965 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010966 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10967 if (result instanceof IllegalStateException) {
10968 throw (IllegalStateException) result;
10969 }
10970 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010971 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10972 return specifiers;
10973 } finally {
10974 Binder.restoreCallingIdentity(identity);
10975 }
10976 }
10977
10978 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010979 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010980 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010981
10982 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10983 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10984
Jack Yu8b766fc2022-03-21 09:42:33 -070010985 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010986 }
10987
10988 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010989 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10990 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010991 if (callingPackage == null) {
10992 callingPackage = getCurrentPackageName();
10993 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010994 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10995 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010996 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10997 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010998 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10999 }
11000 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
11001 Intent intent = new Intent();
11002 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
11003 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11004 // Bring up choose default SMS subscription dialog right now
11005 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
11006 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
11007 mApp.startActivity(intent);
11008 }
chen xud5ca2d52019-05-28 15:20:57 -070011009
11010 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011011 public void showSwitchToManagedProfileDialog() {
11012 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011013 try {
11014 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11015 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11016 // for work telephony.
11017 Intent intent = new Intent(Intent.ACTION_SENDTO);
11018 intent.setData(Uri.parse("smsto:"));
11019 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11020 mApp.startActivity(intent);
11021 } catch (ActivityNotFoundException e) {
11022 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11023 Intent intent = new Intent();
11024 intent.setClass(mApp, ErrorDialogActivity.class);
11025 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11026 mApp.startActivity(intent);
11027 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011028 }
11029
11030 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011031 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011032 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11033 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11034
chen xud5ca2d52019-05-28 15:20:57 -070011035 //TODO investigate if this API should require proper permission check in R b/133791609
11036 final long identity = Binder.clearCallingIdentity();
11037 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011038 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11039 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11040 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11041 return carrierUAProfUrl;
11042 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011043 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11044 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011045 } finally {
11046 Binder.restoreCallingIdentity(identity);
11047 }
11048 }
11049
11050 @Override
11051 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011052 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11053 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11054
chen xud5ca2d52019-05-28 15:20:57 -070011055 //TODO investigate if this API should require proper permission check in R b/133791609
11056 final long identity = Binder.clearCallingIdentity();
11057 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011058 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11059 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11060 if (!TextUtils.isEmpty(carrierUserAgent)) {
11061 return carrierUserAgent;
11062 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011063 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11064 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011065 } finally {
11066 Binder.restoreCallingIdentity(identity);
11067 }
11068 }
Jack Yub07d4972019-05-28 16:12:25 -070011069
11070 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011071 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11072 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011073
joonhunshin4ac60942023-11-15 15:23:39 +000011074 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11075 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11076
Jack Yub07d4972019-05-28 16:12:25 -070011077 final long identity = Binder.clearCallingIdentity();
11078 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011079 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011080 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011081
Ling Maf188d502022-09-16 15:22:36 -070011082 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011083 } finally {
11084 Binder.restoreCallingIdentity(identity);
11085 }
11086 }
11087
11088 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011089 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011090 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011091 enforceModifyPermission();
11092
joonhunshin4ac60942023-11-15 15:23:39 +000011093 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11094 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11095
changbettyd5c246e2019-12-24 15:40:37 +080011096 final long identity = Binder.clearCallingIdentity();
11097 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011098 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011099 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011100
Ling Maf188d502022-09-16 15:22:36 -070011101 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011102 } finally {
11103 Binder.restoreCallingIdentity(identity);
11104 }
11105 }
11106
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011107 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011108 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011109 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11110 * otherwise.
11111 */
11112 @Override
11113 public void setCepEnabled(boolean isCepEnabled) {
11114 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11115
11116 final long identity = Binder.clearCallingIdentity();
11117 try {
11118 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11119 for (Phone phone : PhoneFactory.getPhones()) {
11120 Phone defaultPhone = phone.getImsPhone();
11121 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11122 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11123 ImsPhoneCallTracker imsPhoneCallTracker =
11124 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11125 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11126 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11127 + imsPhone.getMsisdn());
11128 }
11129 }
11130 } finally {
11131 Binder.restoreCallingIdentity(identity);
11132 }
11133 }
allenwtsu46dcc572020-01-08 18:24:03 +080011134
11135 /**
11136 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11137 *
11138 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11139 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11140 * before being read.
11141 */
11142 @Override
11143 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11144 isCompressed) {
11145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11146 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011147 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11148 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11149 }
joonhunshin4ac60942023-11-15 15:23:39 +000011150
11151 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11152 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11153 Binder.getCallingUserHandle())) {
11154 if (!isImsAvailableOnDevice()) {
11155 // ProvisioningManager can not handle ServiceSpecificException.
11156 // Throw the IllegalStateException and annotate ProvisioningManager.
11157 throw new IllegalStateException("IMS not available on device.");
11158 }
11159 } else {
11160 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11161 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11162 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011163 }
11164
11165 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011166 try {
Hui Wang761a6682020-10-31 05:12:53 +000011167 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11168 } finally {
11169 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011170 }
11171 }
zoey chene02881a2019-12-30 16:11:23 +080011172
11173 @Override
11174 public boolean isIccLockEnabled(int subId) {
11175 enforceReadPrivilegedPermission("isIccLockEnabled");
11176
joonhunshin4ac60942023-11-15 15:23:39 +000011177 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11178 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11179
zoey chene02881a2019-12-30 16:11:23 +080011180 // Now that all security checks passes, perform the operation as ourselves.
11181 final long identity = Binder.clearCallingIdentity();
11182 try {
11183 Phone phone = getPhone(subId);
11184 if (phone != null && phone.getIccCard() != null) {
11185 return phone.getIccCard().getIccLockEnabled();
11186 } else {
11187 return false;
11188 }
11189 } finally {
11190 Binder.restoreCallingIdentity(identity);
11191 }
11192 }
11193
11194 /**
11195 * Set the ICC pin lock enabled or disabled.
11196 *
11197 * @return an integer representing the status of IccLock enabled or disabled in the following
11198 * three cases:
11199 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11200 * successfully.
11201 * - Positive number and zero for remaining password attempts.
11202 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11203 *
11204 */
11205 @Override
11206 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11207 enforceModifyPermission();
11208
joonhunshin4ac60942023-11-15 15:23:39 +000011209 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11210 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11211
zoey chene02881a2019-12-30 16:11:23 +080011212 Phone phone = getPhone(subId);
11213 if (phone == null) {
11214 return 0;
11215 }
11216 // Now that all security checks passes, perform the operation as ourselves.
11217 final long identity = Binder.clearCallingIdentity();
11218 try {
11219 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11220 new Pair<Boolean, String>(enabled, password), phone, null);
11221 return attemptsRemaining;
11222
11223 } catch (Exception e) {
11224 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11225 } finally {
11226 Binder.restoreCallingIdentity(identity);
11227 }
11228 return 0;
11229 }
11230
11231 /**
11232 * Change the ICC password used in ICC pin lock.
11233 *
11234 * @return an integer representing the status of IccLock changed in the following three cases:
11235 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11236 * - Positive number and zero for remaining password attempts.
11237 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11238 *
11239 */
11240 @Override
11241 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11242 enforceModifyPermission();
11243
joonhunshin4ac60942023-11-15 15:23:39 +000011244 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11245 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11246
zoey chene02881a2019-12-30 16:11:23 +080011247 Phone phone = getPhone(subId);
11248 if (phone == null) {
11249 return 0;
11250 }
11251 // Now that all security checks passes, perform the operation as ourselves.
11252 final long identity = Binder.clearCallingIdentity();
11253 try {
11254 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11255 new Pair<String, String>(oldPassword, newPassword), phone, null);
11256 return attemptsRemaining;
11257
11258 } catch (Exception e) {
11259 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11260 } finally {
11261 Binder.restoreCallingIdentity(identity);
11262 }
11263 return 0;
11264 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011265
11266 /**
11267 * Request for receiving user activity notification
11268 */
11269 @Override
11270 public void requestUserActivityNotification() {
11271 if (!mNotifyUserActivity.get()
11272 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11273 mNotifyUserActivity.set(true);
11274 }
11275 }
11276
11277 /**
11278 * Called when userActivity is signalled in the power manager.
11279 * This is safe to call from any thread, with any window manager locks held or not.
11280 */
11281 @Override
11282 public void userActivity() {
11283 // ***************************************
11284 // * Inherited from PhoneWindowManager *
11285 // ***************************************
11286 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11287 // WITH ITS LOCKS HELD.
11288 //
11289 // This code must be VERY careful about the locks
11290 // it acquires.
11291 // In fact, the current code acquires way too many,
11292 // and probably has lurking deadlocks.
11293
11294 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11295 throw new SecurityException("Only the OS may call notifyUserActivity()");
11296 }
11297
11298 if (mNotifyUserActivity.getAndSet(false)) {
11299 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11300 USER_ACTIVITY_NOTIFICATION_DELAY);
11301 }
11302 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011303
11304 @Override
11305 public boolean canConnectTo5GInDsdsMode() {
11306 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11307 }
Jack Yud10cdd42020-09-28 20:28:01 -070011308
11309 @Override
11310 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11311 String callingFeatureId) {
11312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11313 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11314 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11315 }
11316
joonhunshin4ac60942023-11-15 15:23:39 +000011317 enforceTelephonyFeatureWithException(callingPackage,
11318 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11319
Jack Yud10cdd42020-09-28 20:28:01 -070011320 Phone phone = getPhone(subId);
11321 if (phone == null) {
11322 throw new RuntimeException("phone is not available");
11323 }
11324 // Now that all security checks passes, perform the operation as ourselves.
11325 final long identity = Binder.clearCallingIdentity();
11326 try {
11327 return phone.getEquivalentHomePlmns();
11328 } finally {
11329 Binder.restoreCallingIdentity(identity);
11330 }
11331 }
Daniel Bright59e67312020-11-13 11:49:37 -080011332
11333 @Override
11334 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011335 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011336 if (!mApp.getResources().getBoolean(
11337 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11338 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11339 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11340 "isRadioInterfaceCapabilitySupported");
11341 }
joonhunshin4ac60942023-11-15 15:23:39 +000011342
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011343 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011344 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011345 if (radioInterfaceCapabilities == null) {
11346 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011347 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011348 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011349 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011350
Hui Wang641e81c2020-10-12 12:14:23 -070011351 @Override
11352 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11353 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011354 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11355 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11356 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11357 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11358 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011359
11360 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11361 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11362
Hui Wang641e81c2020-10-12 12:14:23 -070011363 if (DBG) {
11364 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11365 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11366 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11367 }
11368
11369 if (!SubscriptionManager.isValidSubscriptionId(subId)
11370 || appType < TelephonyManager.APPTYPE_UNKNOWN
11371 || appType > TelephonyManager.APPTYPE_ISIM
11372 || nafUrl == null || securityProtocol == null || callback == null) {
11373 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11374 if (callback != null) {
11375 try {
11376 callback.onAuthenticationFailure(
11377 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11378 } catch (RemoteException exception) {
11379 log("Fail to notify onAuthenticationFailure due to " + exception);
11380 }
11381 return;
11382 }
11383 }
11384
11385 final long token = Binder.clearCallingIdentity();
11386 try {
11387 getGbaManager(subId).bootstrapAuthenticationRequest(
11388 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011389 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011390 } finally {
11391 Binder.restoreCallingIdentity(token);
11392 }
11393 }
11394
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011395 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011396 * Attempts to set the radio power state for all phones for thermal reason.
11397 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011398 * requested radio power state will actually be set. See {@link
11399 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11400 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011401 * @param enable {@code true} if trying to turn radio on.
11402 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11403 * false}.
11404 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011405 private boolean setRadioPowerForThermal(boolean enable) {
11406 boolean isPhoneAvailable = false;
11407 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11408 Phone phone = PhoneFactory.getPhone(i);
11409 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011410 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011411 isPhoneAvailable = true;
11412 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011413 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011414
11415 // return true if successfully informed the phone object about the thermal radio power
11416 // request.
11417 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011418 }
11419
11420 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011421 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011422 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11423 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11424 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11425 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11426 throw new IllegalArgumentException("modem does not support data throttling");
11427 }
11428
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011429 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11430 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011431 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011432 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11433 }
11434
Sarah Chinecc78c42022-03-31 21:16:48 -070011435 setDataEnabledForReason(
11436 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011437
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011438 if (isDataThrottlingSupported) {
11439 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011440 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011441 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11442 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11443 } else if (thermalMitigationResult
11444 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011445 log("Modem likely does not support data throttling on secondary carrier. Data " +
11446 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11447 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011448 }
11449 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011450 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011451
11452 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011453 }
11454
Jack Nudelman644b91a2021-03-12 14:09:48 -080011455 private static List<String> getThermalMitigationAllowlist(Context context) {
11456 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11457 for (String pckg : context.getResources()
11458 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11459 sThermalMitigationAllowlistedPackages.add(pckg);
11460 }
11461 }
11462
11463 return sThermalMitigationAllowlistedPackages;
11464 }
11465
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011466 private boolean isAnyPhoneInEmergencyState() {
11467 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11468 if (tm.isInEmergencyCall()) {
11469 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11470 return true;
11471 }
11472 for (Phone phone : PhoneFactory.getPhones()) {
11473 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11474 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011475 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11476 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011477 return true;
11478 }
11479 }
11480
11481 return false;
11482 }
11483
Jack Nudelman644b91a2021-03-12 14:09:48 -080011484 /**
11485 * Used by shell commands to add an authorized package name for thermal mitigation.
11486 * @param packageName name of package to be allowlisted
11487 * @param context
11488 */
11489 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11490 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11491 sThermalMitigationAllowlistedPackages.add(packageName);
11492 }
11493
11494 /**
11495 * Used by shell commands to remove an authorized package name for thermal mitigation.
11496 * @param packageName name of package to remove from allowlist
11497 * @param context
11498 */
11499 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11500 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11501 sThermalMitigationAllowlistedPackages.remove(packageName);
11502 }
11503
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011504 /**
11505 * Thermal mitigation request to control functionalities at modem.
11506 *
11507 * @param subId the id of the subscription.
11508 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011509 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011510 *
11511 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11512 */
11513 @Override
11514 @ThermalMitigationResult
11515 public int sendThermalMitigationRequest(
11516 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011517 ThermalMitigationRequest thermalMitigationRequest,
11518 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011519 enforceModifyPermission();
11520
Jack Nudelman644b91a2021-03-12 14:09:48 -080011521 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011522
11523 enforceTelephonyFeatureWithException(callingPackage,
11524 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11525
Jack Nudelman644b91a2021-03-12 14:09:48 -080011526 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11527 .contains(callingPackage)) {
11528 throw new SecurityException("Calling package must be configured in the device config. "
11529 + "calling package: " + callingPackage);
11530 }
11531
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011532 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11533 final long identity = Binder.clearCallingIdentity();
11534
11535 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11536 try {
11537 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11538 switch (thermalMitigationAction) {
11539 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11540 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011541 handleDataThrottlingRequest(subId,
11542 thermalMitigationRequest.getDataThrottlingRequest(),
11543 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011544 break;
11545 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11546 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11547 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11548 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11549 }
11550
11551 // Ensure that radio is on. If not able to power on due to phone being
11552 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011553 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011554 thermalMitigationResult =
11555 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11556 break;
11557 }
11558
11559 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011560 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011561 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11562 break;
11563 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11564 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11565 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11566 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11567 }
11568
11569 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11570 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011571 Phone phone = getPhone(subId);
11572 if (phone == null) {
11573 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011574 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011575 break;
11576 }
11577
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011578 TelephonyConnectionService service =
11579 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011580 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011581 Log.e(LOG_TAG, "An emergency call is pending");
11582 thermalMitigationResult =
11583 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11584 break;
11585 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011586 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011587 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011588 break;
11589 }
11590 } else {
11591 thermalMitigationResult =
11592 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11593 break;
11594 }
11595
11596 // Turn radio off. If not able to power off due to phone being unavailable,
11597 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011598 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011599 thermalMitigationResult =
11600 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11601 break;
11602 }
11603 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011604 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011605 break;
11606 default:
11607 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11608 + "not exist. Requested action: " + thermalMitigationAction);
11609 }
11610 } catch (IllegalArgumentException e) {
11611 throw e;
11612 } catch (Exception e) {
11613 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11614 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11615 } finally {
11616 Binder.restoreCallingIdentity(identity);
11617 }
11618
11619 if (DBG) {
11620 log("thermalMitigationRequest returning with thermalMitigationResult: "
11621 + thermalMitigationResult);
11622 }
11623
11624 return thermalMitigationResult;
11625 }
Hui Wang641e81c2020-10-12 12:14:23 -070011626
11627 /**
11628 * Set the GbaService Package Name that Telephony will bind to.
11629 *
11630 * @param subId The sim that the GbaService is associated with.
11631 * @param packageName The name of the package to be replaced with.
11632 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11633 */
11634 @Override
11635 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11636 enforceModifyPermission();
11637
11638 final long identity = Binder.clearCallingIdentity();
11639 try {
11640 return getGbaManager(subId).overrideServicePackage(packageName);
11641 } finally {
11642 Binder.restoreCallingIdentity(identity);
11643 }
11644 }
11645
11646 /**
11647 * Return the package name of the currently bound GbaService.
11648 *
11649 * @param subId The sim that the GbaService is associated with.
11650 * @return the package name of the GbaService configuration, null if GBA is not supported.
11651 */
11652 @Override
11653 public String getBoundGbaService(int subId) {
11654 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11655
11656 final long identity = Binder.clearCallingIdentity();
11657 try {
11658 return getGbaManager(subId).getServicePackage();
11659 } finally {
11660 Binder.restoreCallingIdentity(identity);
11661 }
11662 }
11663
11664 /**
11665 * Set the release time for telephony to unbind GbaService.
11666 *
11667 * @param subId The sim that the GbaService is associated with.
11668 * @param interval The release time to unbind GbaService by millisecond.
11669 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11670 */
11671 @Override
11672 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11673 enforceModifyPermission();
11674
11675 final long identity = Binder.clearCallingIdentity();
11676 try {
11677 return getGbaManager(subId).overrideReleaseTime(interval);
11678 } finally {
11679 Binder.restoreCallingIdentity(identity);
11680 }
11681 }
11682
11683 /**
11684 * Return the release time for telephony to unbind GbaService.
11685 *
11686 * @param subId The sim that the GbaService is associated with.
11687 * @return The release time to unbind GbaService by millisecond.
11688 */
11689 @Override
11690 public int getGbaReleaseTime(int subId) {
11691 enforceReadPrivilegedPermission("getGbaReleaseTime");
11692
11693 final long identity = Binder.clearCallingIdentity();
11694 try {
11695 return getGbaManager(subId).getReleaseTime();
11696 } finally {
11697 Binder.restoreCallingIdentity(identity);
11698 }
11699 }
11700
11701 private GbaManager getGbaManager(int subId) {
11702 GbaManager instance = GbaManager.getInstance(subId);
11703 if (instance == null) {
11704 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11705 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11706 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11707 }
11708 return instance;
11709 }
Hui Wang761a6682020-10-31 05:12:53 +000011710
11711 /**
11712 * indicate whether the device and the carrier can support
11713 * RCS VoLTE single registration.
11714 */
11715 @Override
11716 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011717 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11718 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11719 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11720 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011721
11722 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11723 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11724 }
11725
11726 final long identity = Binder.clearCallingIdentity();
11727 try {
11728 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11729 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011730 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11731 if (isCapable != null) {
11732 return isCapable;
11733 }
Hui Wang761a6682020-10-31 05:12:53 +000011734 }
Hui Wang67af90e2021-06-04 16:57:15 -070011735 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11736 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011737 } finally {
11738 Binder.restoreCallingIdentity(identity);
11739 }
11740 }
11741
11742 /**
11743 * Register RCS provisioning callback.
11744 */
11745 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011746 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011747 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011748 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011749 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011750 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11751 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011752
11753 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11754 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11755 }
joonhunshin4ac60942023-11-15 15:23:39 +000011756 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11757 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11758 Binder.getCallingUserHandle())) {
11759 if (!isImsAvailableOnDevice()) {
11760 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11761 "IMS not available on device.");
11762 }
11763 } else {
11764 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11765 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011766 }
11767
11768 final long identity = Binder.clearCallingIdentity();
11769 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011770 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011771 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011772 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11773 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011774 }
Hui Wang761a6682020-10-31 05:12:53 +000011775 } finally {
11776 Binder.restoreCallingIdentity(identity);
11777 }
11778 }
11779
11780 /**
11781 * Unregister RCS provisioning callback.
11782 */
11783 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011784 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011785 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011786 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011787 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011788 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11789 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011790
11791 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11792 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11793 }
joonhunshin4ac60942023-11-15 15:23:39 +000011794
11795 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11796 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11797 Binder.getCallingUserHandle())) {
11798 if (!isImsAvailableOnDevice()) {
11799 // operation failed silently
11800 Rlog.w(LOG_TAG, "IMS not available on device.");
11801 return;
11802 }
11803 } else {
11804 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11805 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11806 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011807 }
11808
11809 final long identity = Binder.clearCallingIdentity();
11810 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011811 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011812 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011813 } finally {
11814 Binder.restoreCallingIdentity(identity);
11815 }
11816 }
11817
11818 /**
11819 * trigger RCS reconfiguration.
11820 */
11821 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011822 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11823 "triggerRcsReconfiguration",
11824 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011825
11826 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11827 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11828 }
joonhunshin4ac60942023-11-15 15:23:39 +000011829 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11830 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11831 Binder.getCallingUserHandle())) {
11832 if (!isImsAvailableOnDevice()) {
11833 // ProvisioningManager can not handle ServiceSpecificException.
11834 // Throw the IllegalStateException and annotate ProvisioningManager.
11835 throw new IllegalStateException("IMS not available on device.");
11836 }
11837 } else {
11838 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11839 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011840 }
11841
11842 final long identity = Binder.clearCallingIdentity();
11843 try {
11844 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11845 } finally {
11846 Binder.restoreCallingIdentity(identity);
11847 }
11848 }
11849
11850 /**
11851 * Provide the client configuration parameters of the RCS application.
11852 */
11853 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011854 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11855 "setRcsClientConfiguration",
11856 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011857
11858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11859 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11860 }
joonhunshin4ac60942023-11-15 15:23:39 +000011861 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11862 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11863 Binder.getCallingUserHandle())) {
11864 if (!isImsAvailableOnDevice()) {
11865 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11866 "IMS not available on device.");
11867 }
11868 } else {
11869 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11870 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011871 }
11872
11873 final long identity = Binder.clearCallingIdentity();
11874
11875 try {
11876 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11877 if (configBinder == null) {
11878 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011879 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11880 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011881 } else {
11882 configBinder.setRcsClientConfiguration(rcc);
11883 }
joonhunshin3e154242021-09-17 06:33:39 +000011884
11885 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11886 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011887 } catch (RemoteException e) {
11888 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011889 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11890 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011891 } finally {
11892 Binder.restoreCallingIdentity(identity);
11893 }
11894 }
11895
11896 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011897 * Enables or disables the test mode for RCS VoLTE single registration.
11898 */
11899 @Override
11900 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11901 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11902 "setRcsSingleRegistrationTestModeEnabled");
11903
11904 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11905 }
11906
11907 /**
11908 * Gets the test mode for RCS VoLTE single registration.
11909 */
11910 @Override
11911 public boolean getRcsSingleRegistrationTestModeEnabled() {
11912 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11913 "getRcsSingleRegistrationTestModeEnabled");
11914
11915 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11916 }
11917
11918 /**
Hui Wang761a6682020-10-31 05:12:53 +000011919 * Overrides the config of RCS VoLTE single registration enabled for the device.
11920 */
11921 @Override
11922 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11923 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11924 "setDeviceSingleRegistrationEnabledOverride");
11925 enforceModifyPermission();
11926
11927 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11928 : Boolean.parseBoolean(enabledStr);
11929 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011930 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011931 }
11932
11933 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011934 * Sends a device to device communication message. Only usable via shell.
11935 * @param message message to send.
11936 * @param value message value.
11937 */
11938 @Override
11939 public void sendDeviceToDeviceMessage(int message, int value) {
11940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011941 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011942 enforceModifyPermission();
11943
11944 final long identity = Binder.clearCallingIdentity();
11945 try {
11946 TelephonyConnectionService service =
11947 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11948 if (service == null) {
11949 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11950 return;
11951 }
11952 service.sendTestDeviceToDeviceMessage(message, value);
11953 } finally {
11954 Binder.restoreCallingIdentity(identity);
11955 }
11956 }
11957
Tyler Gunnbabbda02021-02-10 11:05:02 -080011958 /**
11959 * Sets the specified device to device transport active.
11960 * @param transport The transport to set active.
11961 */
11962 @Override
11963 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11964 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11965 "setActiveDeviceToDeviceTransport");
11966 enforceModifyPermission();
11967
11968 final long identity = Binder.clearCallingIdentity();
11969 try {
11970 TelephonyConnectionService service =
11971 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11972 if (service == null) {
11973 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11974 return;
11975 }
11976 service.setActiveDeviceToDeviceTransport(transport);
11977 } finally {
11978 Binder.restoreCallingIdentity(identity);
11979 }
11980 }
Tyler Gunn92479152021-01-20 16:30:10 -080011981
Tyler Gunnd4339262021-05-03 14:46:49 -070011982 @Override
11983 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11984 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11985 "setDeviceToDeviceForceEnabled");
11986
11987 final long identity = Binder.clearCallingIdentity();
11988 try {
11989 Arrays.stream(PhoneFactory.getPhones()).forEach(
11990 p -> {
11991 Phone thePhone = p.getImsPhone();
11992 if (thePhone != null && thePhone instanceof ImsPhone) {
11993 ImsPhone imsPhone = (ImsPhone) thePhone;
11994 CallTracker tracker = imsPhone.getCallTracker();
11995 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11996 ImsPhoneCallTracker imsPhoneCallTracker =
11997 (ImsPhoneCallTracker) tracker;
11998 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11999 }
12000 }
12001 }
12002 );
12003 } finally {
12004 Binder.restoreCallingIdentity(identity);
12005 }
12006 }
12007
Tyler Gunn92479152021-01-20 16:30:10 -080012008 /**
Hui Wang761a6682020-10-31 05:12:53 +000012009 * Gets the config of RCS VoLTE single registration enabled for the device.
12010 */
12011 @Override
12012 public boolean getDeviceSingleRegistrationEnabled() {
12013 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12014 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12015 }
12016
12017 /**
12018 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12019 */
12020 @Override
12021 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12022 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12023 "setCarrierSingleRegistrationEnabledOverride");
12024 enforceModifyPermission();
12025
12026 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12027 : Boolean.parseBoolean(enabledStr);
12028 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12029 subId, enabled);
12030 }
12031
12032 /**
12033 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12034 */
12035 @Override
12036 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12037 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12038 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12039 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012040
12041 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012042 * Overrides the ims feature validation result
12043 */
12044 @Override
12045 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12046 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12047 "setImsFeatureValidationOverride");
12048
12049 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12050 : Boolean.parseBoolean(enabledStr);
12051 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12052 subId, enabled);
12053 }
12054
12055 /**
12056 * Gets the ims feature validation override value
12057 */
12058 @Override
12059 public boolean getImsFeatureValidationOverride(int subId) {
12060 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12061 "getImsFeatureValidationOverride");
12062 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12063 }
12064
12065 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012066 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12067 * their mobile plan.
12068 */
12069 @Override
12070 public String getMobileProvisioningUrl() {
12071 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12072 final long identity = Binder.clearCallingIdentity();
12073 try {
12074 return getDefaultPhone().getMobileProvisioningUrl();
12075 } finally {
12076 Binder.restoreCallingIdentity(identity);
12077 }
12078 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012079
James.cf Linbcdf8b32021-01-14 16:44:13 +080012080 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012081 * Get the EAB contact from the EAB database.
12082 */
12083 @Override
12084 public String getContactFromEab(String contact) {
12085 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12086 enforceModifyPermission();
12087 final long identity = Binder.clearCallingIdentity();
12088 try {
12089 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12090 } finally {
12091 Binder.restoreCallingIdentity(identity);
12092 }
12093 }
12094
12095 /**
Calvin Pana1434322021-07-01 19:27:01 +080012096 * Get the EAB capability from the EAB database.
12097 */
12098 @Override
12099 public String getCapabilityFromEab(String contact) {
12100 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12101 enforceModifyPermission();
12102 final long identity = Binder.clearCallingIdentity();
12103 try {
12104 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12105 } finally {
12106 Binder.restoreCallingIdentity(identity);
12107 }
12108 }
12109
12110 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012111 * Remove the EAB contacts from the EAB database.
12112 */
12113 @Override
12114 public int removeContactFromEab(int subId, String contacts) {
12115 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12116 enforceModifyPermission();
12117 final long identity = Binder.clearCallingIdentity();
12118 try {
12119 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12120 } finally {
12121 Binder.restoreCallingIdentity(identity);
12122 }
12123 }
12124
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012125 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012126 public boolean getDeviceUceEnabled() {
12127 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12128 final long identity = Binder.clearCallingIdentity();
12129 try {
12130 return mApp.getDeviceUceEnabled();
12131 } finally {
12132 Binder.restoreCallingIdentity(identity);
12133 }
12134 }
12135
12136 @Override
12137 public void setDeviceUceEnabled(boolean isEnabled) {
12138 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12139 final long identity = Binder.clearCallingIdentity();
12140 try {
12141 mApp.setDeviceUceEnabled(isEnabled);
12142 } finally {
12143 Binder.restoreCallingIdentity(identity);
12144 }
12145 }
12146
Brad Ebinger14d467f2021-02-12 06:18:28 +000012147 /**
12148 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12149 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12150 */
12151 // Used for SHELL command only right now.
12152 @Override
12153 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12154 List<String> featureTags) {
12155 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12156 "addUceRegistrationOverrideShell");
12157 final long identity = Binder.clearCallingIdentity();
12158 try {
12159 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12160 new ArraySet<>(featureTags));
12161 } catch (ImsException e) {
12162 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12163 } finally {
12164 Binder.restoreCallingIdentity(identity);
12165 }
12166 }
12167
12168 /**
12169 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12170 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12171 */
12172 // Used for SHELL command only right now.
12173 @Override
12174 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12175 List<String> featureTags) {
12176 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12177 "removeUceRegistrationOverrideShell");
12178 final long identity = Binder.clearCallingIdentity();
12179 try {
12180 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12181 new ArraySet<>(featureTags));
12182 } catch (ImsException e) {
12183 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12184 } finally {
12185 Binder.restoreCallingIdentity(identity);
12186 }
12187 }
12188
12189 /**
12190 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12191 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12192 */
12193 // Used for SHELL command only right now.
12194 @Override
12195 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12197 "clearUceRegistrationOverrideShell");
12198 final long identity = Binder.clearCallingIdentity();
12199 try {
12200 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12201 } catch (ImsException e) {
12202 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12203 } finally {
12204 Binder.restoreCallingIdentity(identity);
12205 }
12206 }
12207
12208 /**
12209 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12210 */
12211 // Used for SHELL command only right now.
12212 @Override
12213 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12214 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12215 "getLatestRcsContactUceCapabilityShell");
12216 final long identity = Binder.clearCallingIdentity();
12217 try {
12218 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12219 } catch (ImsException e) {
12220 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12221 } finally {
12222 Binder.restoreCallingIdentity(identity);
12223 }
12224 }
12225
12226 /**
12227 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12228 * device does not have an active PUBLISH.
12229 */
12230 // Used for SHELL command only right now.
12231 @Override
12232 public String getLastUcePidfXmlShell(int subId) {
12233 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12234 final long identity = Binder.clearCallingIdentity();
12235 try {
12236 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12237 } catch (ImsException e) {
12238 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12239 } finally {
12240 Binder.restoreCallingIdentity(identity);
12241 }
12242 }
12243
James.cf Line8713a42021-04-29 16:04:26 +080012244 /**
12245 * Remove UCE requests cannot be sent to the network status.
12246 */
12247 // Used for SHELL command only right now.
12248 @Override
12249 public boolean removeUceRequestDisallowedStatus(int subId) {
12250 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12251 final long identity = Binder.clearCallingIdentity();
12252 try {
12253 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12254 } catch (ImsException e) {
12255 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12256 } finally {
12257 Binder.restoreCallingIdentity(identity);
12258 }
12259 }
12260
James.cf Lin18bb9002021-05-25 01:37:38 +080012261 /**
12262 * Remove UCE requests cannot be sent to the network status.
12263 */
12264 // Used for SHELL command only.
12265 @Override
12266 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12267 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12268 final long identity = Binder.clearCallingIdentity();
12269 try {
12270 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12271 } catch (ImsException e) {
12272 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12273 } finally {
12274 Binder.restoreCallingIdentity(identity);
12275 }
12276 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012277
James.cf Lin4b784aa2021-01-31 03:25:15 +080012278 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012279 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12280 String callingPackage) {
12281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12282 mApp, subId, "setSignalStrengthUpdateRequest");
12283
joonhunshin4ac60942023-11-15 15:23:39 +000012284 enforceTelephonyFeatureWithException(callingPackage,
12285 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12286
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012287 final int callingUid = Binder.getCallingUid();
12288 // Verify that tha callingPackage belongs to the calling UID
12289 mApp.getSystemService(AppOpsManager.class)
12290 .checkPackage(callingUid, callingPackage);
12291
Rambo Wang3607f502021-02-01 21:51:40 -080012292 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012293
12294 final long identity = Binder.clearCallingIdentity();
12295 try {
12296 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12297 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12298
12299 if (result instanceof IllegalStateException) {
12300 throw (IllegalStateException) result;
12301 }
12302 } finally {
12303 Binder.restoreCallingIdentity(identity);
12304 }
12305 }
12306
12307 @Override
12308 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12309 String callingPackage) {
12310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12311 mApp, subId, "clearSignalStrengthUpdateRequest");
12312
joonhunshin4ac60942023-11-15 15:23:39 +000012313 enforceTelephonyFeatureWithException(callingPackage,
12314 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12315
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012316 final int callingUid = Binder.getCallingUid();
12317 // Verify that tha callingPackage belongs to the calling UID
12318 mApp.getSystemService(AppOpsManager.class)
12319 .checkPackage(callingUid, callingPackage);
12320
12321 final long identity = Binder.clearCallingIdentity();
12322 try {
12323 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12324 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12325
12326 if (result instanceof IllegalStateException) {
12327 throw (IllegalStateException) result;
12328 }
12329 } finally {
12330 Binder.restoreCallingIdentity(identity);
12331 }
12332 }
12333
Rambo Wang3607f502021-02-01 21:51:40 -080012334 private static void validateSignalStrengthUpdateRequest(Context context,
12335 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012336 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012337 // phone/system process do not have further restriction on request
12338 return;
12339 }
12340
12341 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012342 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012343 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012344 context.enforceCallingOrSelfPermission(
12345 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12346 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012347 }
12348
12349 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012350 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012351 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012352 || info.isEnabled()) {
12353 throw new IllegalArgumentException(
12354 "Only system can set hide fields in SignalThresholdInfo");
12355 }
12356
12357 // Thresholds length for each RAN need in range. This has been validated in
12358 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12359 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12360 final int[] thresholds = info.getThresholds();
12361 Objects.requireNonNull(thresholds);
12362 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12363 || thresholds.length
12364 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12365 throw new IllegalArgumentException(
12366 "thresholds length is out of range: " + thresholds.length);
12367 }
12368 }
12369 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012370
12371 /**
12372 * Gets the current phone capability.
12373 *
12374 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12375 * @return the PhoneCapability which describes the data connection capability of modem.
12376 * It's used to evaluate possible phone config change, for example from single
12377 * SIM device to multi-SIM device.
12378 */
12379 @Override
12380 public PhoneCapability getPhoneCapability() {
12381 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012382
12383 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12384 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12385
SongFerngWang8236caa2021-01-17 21:51:44 +080012386 final long identity = Binder.clearCallingIdentity();
12387 try {
12388 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12389 } finally {
12390 Binder.restoreCallingIdentity(identity);
12391 }
12392 }
Michele Berionne5e411512020-11-13 02:36:59 +000012393
12394 /**
12395 * Prepare TelephonyManager for an unattended reboot. The reboot is
12396 * required to be done shortly after the API is invoked.
12397 */
12398 @Override
12399 @TelephonyManager.PrepareUnattendedRebootResult
12400 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012401 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012402 enforceRebootPermission();
12403
joonhunshin4ac60942023-11-15 15:23:39 +000012404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12405 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12406
Michele Berionne5e411512020-11-13 02:36:59 +000012407 final long identity = Binder.clearCallingIdentity();
12408 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012409 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012410 } finally {
12411 Binder.restoreCallingIdentity(identity);
12412 }
12413 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012414
12415 /**
12416 * Request to get the current slicing configuration including URSP rules and
12417 * NSSAIs (configured, allowed and rejected).
12418 *
12419 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12420 */
12421 @Override
12422 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012423 TelephonyPermissions
12424 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12425 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012426
joonhunshin4ac60942023-11-15 15:23:39 +000012427 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12428 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12429 "getSlicingConfig");
12430
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012431 final long identity = Binder.clearCallingIdentity();
12432 try {
12433 Phone phone = getDefaultPhone();
12434 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12435 } finally {
12436 Binder.restoreCallingIdentity(identity);
12437 }
12438 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012439
12440 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012441 * Check whether the given premium capability is available for purchase from the carrier.
12442 *
12443 * @param capability The premium capability to check.
12444 * @param subId The subId to check the premium capability for.
12445 *
12446 * @return Whether the given premium capability is available to purchase.
12447 */
12448 @Override
12449 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12450 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12451 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12452 log("Premium capability "
12453 + TelephonyManager.convertPremiumCapabilityToString(capability)
12454 + " is not available for purchase due to missing permissions.");
12455 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12456 + "permission READ_BASIC_PHONE_STATE.");
12457 }
12458
joonhunshin4ac60942023-11-15 15:23:39 +000012459 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12460 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12461
Sarah Chin2ec39f62022-08-31 17:03:26 -070012462 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012463 if (phone == null) {
12464 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12465 return false;
12466 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012467 final long identity = Binder.clearCallingIdentity();
12468 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012469 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012470 .isPremiumCapabilityAvailableForPurchase(capability);
12471 } finally {
12472 Binder.restoreCallingIdentity(identity);
12473 }
12474 }
12475
12476 /**
12477 * Purchase the given premium capability from the carrier.
12478 *
12479 * @param capability The premium capability to purchase.
12480 * @param callback The result of the purchase request.
12481 * @param subId The subId to purchase the premium capability for.
12482 */
12483 @Override
12484 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12485 log("purchasePremiumCapability: capability="
12486 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12487 + getCurrentPackageName());
12488
12489 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12490 mApp, "purchasePremiumCapability")) {
12491 log("purchasePremiumCapability "
12492 + TelephonyManager.convertPremiumCapabilityToString(capability)
12493 + " failed due to missing permissions.");
12494 throw new SecurityException("purchasePremiumCapability requires permission "
12495 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012496 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12497 mApp, "purchasePremiumCapability")) {
12498 log("purchasePremiumCapability "
12499 + TelephonyManager.convertPremiumCapabilityToString(capability)
12500 + " failed due to missing permissions.");
12501 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012502 }
12503
joonhunshin4ac60942023-11-15 15:23:39 +000012504 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12505 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12506
Sarah Chin2ec39f62022-08-31 17:03:26 -070012507 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012508 if (phone == null) {
12509 try {
12510 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12511 callback.accept(result);
12512 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12513 } catch (RemoteException e) {
12514 String logStr = "Purchase premium capability "
12515 + TelephonyManager.convertPremiumCapabilityToString(capability)
12516 + " failed due to RemoteException handling null phone: " + e;
12517 if (DBG) log(logStr);
12518 AnomalyReporter.reportAnomaly(
12519 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12520 }
12521 return;
12522 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012523
12524 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012525 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012526 callingProcess = mApp.getPackageManager().getApplicationInfo(
12527 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012528 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012529 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012530 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012531
12532 boolean isVisible = false;
12533 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12534 if (am != null) {
12535 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12536 if (processes != null) {
12537 for (ActivityManager.RunningAppProcessInfo process : processes) {
12538 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012539 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012540 if (process.processName.equals(callingProcess) && process.importance
12541 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12542 isVisible = true;
12543 break;
12544 }
12545 }
12546 }
12547 }
12548
12549 if (!isVisible) {
12550 try {
12551 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12552 callback.accept(result);
12553 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12554 } catch (RemoteException e) {
12555 String logStr = "Purchase premium capability "
12556 + TelephonyManager.convertPremiumCapabilityToString(capability)
12557 + " failed due to RemoteException handling background application: " + e;
12558 if (DBG) log(logStr);
12559 AnomalyReporter.reportAnomaly(
12560 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12561 }
12562 return;
12563 }
12564
Sarah Chin71b3a852022-09-28 15:54:19 -070012565 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012566 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012567 }
12568
12569 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012570 * Register an IMS connection state callback
12571 */
12572 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012573 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12574 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012575 if (feature == ImsFeature.FEATURE_MMTEL) {
12576 // ImsMmTelManager
12577 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12578 TelephonyPermissions
12579 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12580 mApp, subId, "registerImsStateCallback");
12581 } else if (feature == ImsFeature.FEATURE_RCS) {
12582 // ImsRcsManager or SipDelegateManager
12583 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12584 Binder.getCallingUid(), "registerImsStateCallback",
12585 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12586 Manifest.permission.READ_PRECISE_PHONE_STATE,
12587 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12588 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12589 }
12590
12591 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12592 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12593 "IMS not available on device.");
12594 }
12595
12596 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12597 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12598 }
12599
12600 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12601 if (controller == null) {
12602 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12603 "IMS not available on device.");
12604 }
12605
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012606 if (callingPackage == null) {
12607 callingPackage = getCurrentPackageName();
12608 }
12609
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012610 final long token = Binder.clearCallingIdentity();
12611 try {
12612 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012613 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012614 } catch (ImsException e) {
12615 throw new ServiceSpecificException(e.getCode());
12616 } finally {
12617 Binder.restoreCallingIdentity(token);
12618 }
12619 }
12620
12621 /**
12622 * Unregister an IMS connection state callback
12623 */
12624 @Override
12625 public void unregisterImsStateCallback(IImsStateCallback cb) {
12626 final long token = Binder.clearCallingIdentity();
12627 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12628 if (controller == null) {
12629 return;
12630 }
12631 try {
12632 controller.unregisterImsStateCallback(cb);
12633 } finally {
12634 Binder.restoreCallingIdentity(token);
12635 }
12636 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012637
12638 /**
12639 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12640 *
12641 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012642 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012643 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012644 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012645 * If there is current registered network this value will be same as the registered cell
12646 * identity. If the device goes out of service the previous cell identity is cached and
12647 * will be returned. If the cache age of the Cell identity is more than 24 hours
12648 * it will be cleared and null will be returned.
12649 *
12650 */
12651 @Override
12652 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12653 String callingFeatureId) {
12654 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12655 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12656 LocationAccessPolicy.checkLocationPermission(mApp,
12657 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12658 .setCallingPackage(callingPackage)
12659 .setCallingFeatureId(callingFeatureId)
12660 .setCallingPid(Binder.getCallingPid())
12661 .setCallingUid(Binder.getCallingUid())
12662 .setMethod("getLastKnownCellIdentity")
12663 .setLogAsInfo(true)
12664 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12665 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12666 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12667 .build());
12668
12669 boolean hasFinePermission =
12670 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12671 if (!hasFinePermission
12672 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12673 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012674 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012675 }
12676
12677 final long identity = Binder.clearCallingIdentity();
12678 try {
Ling Mac28f0212023-03-24 16:07:15 -070012679 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012680 if (sst == null) return null;
12681 return sst.getLastKnownCellIdentity();
12682 } finally {
12683 Binder.restoreCallingIdentity(identity);
12684 }
12685 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012686
jimsun3b9ccac2021-10-26 15:01:23 +080012687 /**
12688 * Sets the modem service class Name that Telephony will bind to.
12689 *
12690 * @param serviceName The class name of the modem service.
12691 * @return true if the operation is succeed, otherwise false.
12692 */
12693 public boolean setModemService(String serviceName) {
12694 Log.d(LOG_TAG, "setModemService - " + serviceName);
12695 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012697 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12698 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012699 return mPhoneConfigurationManager.setModemService(serviceName);
12700 }
12701
12702 /**
12703 * Return the class name of the currently bounded modem service.
12704 *
12705 * @return the class name of the modem service.
12706 */
12707 public String getModemService() {
12708 String result;
12709 Log.d(LOG_TAG, "getModemService");
12710 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12711 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012712 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012713 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12714 "getModemService");
12715 result = mPhoneConfigurationManager.getModemService();
12716 Log.d(LOG_TAG, "result = " + result);
12717 return result;
12718 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012719
Hakjun Choi3ee81112023-12-19 15:40:58 +000012720 /**
12721 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12722 * including carrier config, entitlement server, and config update.
12723 *
12724 * @param subId subId The subscription ID of the carrier.
12725 *
12726 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12727 * be returned.
12728 *
12729 * @throws SecurityException if the caller doesn't have the required permission.
12730 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012731 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12732 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012733 final long identity = Binder.clearCallingIdentity();
12734 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012735 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012736 } finally {
12737 Binder.restoreCallingIdentity(identity);
12738 }
12739 }
12740
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012741 @Override
12742 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12743 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12744 mApp.enforceCallingOrSelfPermission(
12745 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12747
12748 final long identity = Binder.clearCallingIdentity();
12749 try {
12750 Phone phone = getPhone(subId);
12751 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012752 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12753 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012754 phone.setVoiceServiceStateOverride(hasService);
12755 } finally {
12756 Binder.restoreCallingIdentity(identity);
12757 }
12758 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012759
12760 /**
12761 * set removable eSIM as default eUICC.
12762 *
12763 * @hide
12764 */
12765 @Override
12766 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12767 enforceModifyPermission();
12768 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12769
12770 final long identity = Binder.clearCallingIdentity();
12771 try {
12772 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12773 } finally {
12774 Binder.restoreCallingIdentity(identity);
12775 }
12776 }
12777
12778 /**
12779 * Returns whether the removable eSIM is default eUICC or not.
12780 *
12781 * @hide
12782 */
12783 @Override
12784 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12785 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12786 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12787
12788 final long identity = Binder.clearCallingIdentity();
12789 try {
12790 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12791 } finally {
12792 Binder.restoreCallingIdentity(identity);
12793 }
12794 }
12795
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012796 /**
12797 * Get the component name of the default app to direct respond-via-message intent for the
12798 * user associated with this subscription, update the cache if there is no respond-via-message
12799 * application currently configured for this user.
12800 * @return component name of the app and class to direct Respond Via Message intent to, or
12801 * {@code null} if the functionality is not supported.
12802 * @hide
12803 */
12804 @Override
12805 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12806 boolean updateIfNeeded) {
12807 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012808
joonhunshin4ac60942023-11-15 15:23:39 +000012809 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12810 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12811 "getDefaultRespondViaMessageApplication");
12812
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012813 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12814
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012815 UserHandle userHandle = null;
12816 final long identity = Binder.clearCallingIdentity();
12817 try {
12818 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12819 } finally {
12820 Binder.restoreCallingIdentity(identity);
12821 }
12822 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12823 updateIfNeeded, userHandle);
12824 }
Jack Yuf5badd92022-12-08 00:50:53 -080012825
12826 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012827 * Set whether the device is able to connect with null ciphering or integrity
12828 * algorithms. This is a global setting and will apply to all active subscriptions
12829 * and all new subscriptions after this.
12830 *
12831 * @param enabled when true, null cipher and integrity algorithms are allowed.
12832 * @hide
12833 */
12834 @Override
12835 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12836 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12837 enforceModifyPermission();
12838 checkForNullCipherAndIntegritySupport();
12839
12840 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12841 // for listening to these preference changes and applying them immediately.
12842 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12843 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12844 editor.apply();
12845
12846 for (Phone phone: PhoneFactory.getPhones()) {
12847 phone.handleNullCipherEnabledChange();
12848 }
12849 }
12850
12851
12852 /**
12853 * Get whether the device is able to connect with null ciphering or integrity
12854 * algorithms. Note that this retrieves the phone-global preference and not
12855 * the state of the radio.
12856 *
12857 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12858 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12859 * version for this feature.
12860 * @hide
12861 */
12862 @Override
12863 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12864 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12865 enforceReadPermission();
12866 checkForNullCipherAndIntegritySupport();
12867 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12868 }
12869
12870 private void checkForNullCipherAndIntegritySupport() {
12871 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12872 throw new UnsupportedOperationException(
12873 "Null cipher and integrity operations require HAL 2.1 or above");
12874 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012875 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12876 throw new UnsupportedOperationException(
12877 "Null cipher and integrity operations unsupported by modem");
12878 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012879 }
12880
Gil Cukierman06403e12023-11-29 16:33:03 +000012881 private void checkForIdentifierDisclosureNotificationSupport() {
12882 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12883 throw new UnsupportedOperationException(
12884 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12885 + "above");
12886 }
12887 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12888 throw new UnsupportedOperationException(
12889 "Cellular identifier disclosure transparency operations unsupported by modem");
12890 }
12891 }
12892
Michael Groover826b71d2023-12-21 22:08:06 -060012893 private void checkForNullCipherNotificationSupport() {
12894 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12895 throw new UnsupportedOperationException(
12896 "Null cipher notification operations require HAL 2.2 or above");
12897 }
12898 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12899 throw new UnsupportedOperationException(
12900 "Null cipher notification operations unsupported by modem");
12901 }
12902 }
12903
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012904 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012905 * Get the SIM state for the slot index.
12906 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12907 *
12908 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12909 */
12910 @Override
12911 @SimState
12912 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070012913 if (!mApp.getResources().getBoolean(
12914 com.android.internal.R.bool.config_force_phone_globals_creation)) {
12915 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12916 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12917 }
joonhunshin4ac60942023-11-15 15:23:39 +000012918
Jack Yuf5badd92022-12-08 00:50:53 -080012919 IccCardConstants.State simState;
12920 if (slotIndex < 0) {
12921 simState = IccCardConstants.State.UNKNOWN;
12922 } else {
12923 Phone phone = null;
12924 try {
12925 phone = PhoneFactory.getPhone(slotIndex);
12926 } catch (IllegalStateException e) {
12927 // ignore
12928 }
12929 if (phone == null) {
12930 simState = IccCardConstants.State.UNKNOWN;
12931 } else {
12932 IccCard icc = phone.getIccCard();
12933 if (icc == null) {
12934 simState = IccCardConstants.State.UNKNOWN;
12935 } else {
12936 simState = icc.getState();
12937 }
12938 }
12939 }
12940 return simState.ordinal();
12941 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012942
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012943 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12944 boolean enableLogcat,
12945 long logcatStartTimestampMillis, boolean enableTelecomDump,
12946 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012947 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012948 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12949 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12950 ecdDataBuilder
12951 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12952 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012953 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012954 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012955 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012956 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12957 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012958 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12959 Executors.newCachedThreadPool(), db,
12960 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012961 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012962 }
12963
12964 /**
12965 * Request telephony to persist state for debugging emergency call failures.
12966 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012967 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012968 * @param enableLogcat whether to collect logcat output
12969 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12970 * @param enableTelecomDump whether to collect telecom dumpsys
12971 * @param enableTelephonyDump whether to collect telephony dumpsys
12972 */
12973 @Override
12974 @RequiresPermission(android.Manifest.permission.DUMP)
12975 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12976 long logcatStartTimestampMillis, boolean enableTelecomDump,
12977 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012978 // Verify that the caller has READ_DROPBOX_DATA permission.
12979 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12980 && Flags.enableReadDropboxPermission()) {
12981 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12982 "persistEmergencyCallDiagnosticData");
12983 } else {
12984 // Otherwise, enforce legacy permission.
12985 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12986 "persistEmergencyCallDiagnosticData");
12987 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012988 final long identity = Binder.clearCallingIdentity();
12989 try {
12990 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12991 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12992
12993 } finally {
12994 Binder.restoreCallingIdentity(identity);
12995 }
12996 }
12997
Hui Wang9b5793a2022-12-05 14:38:06 -060012998 /**
12999 * Get current cell broadcast ranges.
13000 */
13001 @Override
13002 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13003 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
13004 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13005 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013006
13007 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13008 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
13009
Hui Wang9b5793a2022-12-05 14:38:06 -060013010 final long identity = Binder.clearCallingIdentity();
13011 try {
13012 return getPhone(subId).getCellBroadcastIdRanges();
13013 } finally {
13014 Binder.restoreCallingIdentity(identity);
13015 }
13016 }
13017
13018 /**
13019 * Set reception of cell broadcast messages with the list of the given ranges
13020 *
13021 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13022 */
13023 @Override
13024 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13025 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13026 @Nullable IIntegerConsumer callback) {
13027 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13028 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013029
13030 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13031 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13032
Hui Wang9b5793a2022-12-05 14:38:06 -060013033 final long identity = Binder.clearCallingIdentity();
13034 try {
13035 Phone phone = getPhoneFromSubId(subId);
13036 if (DBG) {
13037 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13038 }
13039 phone.setCellBroadcastIdRanges(ranges, result -> {
13040 if (callback != null) {
13041 try {
13042 callback.accept(result);
13043 } catch (RemoteException e) {
13044 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13045 }
13046 }
13047 });
13048 } finally {
13049 Binder.restoreCallingIdentity(identity);
13050 }
13051 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013052
13053 /**
13054 * Returns whether the device supports the domain selection service.
13055 *
13056 * @return {@code true} if the device supports the domain selection service.
13057 */
13058 @Override
13059 public boolean isDomainSelectionSupported() {
13060 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13061 "isDomainSelectionSupported");
13062
13063 final long identity = Binder.clearCallingIdentity();
13064 try {
13065 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13066 } finally {
13067 Binder.restoreCallingIdentity(identity);
13068 }
13069 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013070
13071 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013072 * Returns whether the AOSP domain selection service is supported.
13073 *
13074 * @return {@code true} if the AOSP domain selection service is supported,
13075 * {@code false} otherwise.
13076 */
13077 @Override
13078 public boolean isAospDomainSelectionService() {
13079 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13080 "isAospDomainSelectionService");
13081
13082 final long identity = Binder.clearCallingIdentity();
13083 try {
13084 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13085 String dssComponentName = mApp.getResources().getString(
13086 R.string.config_domain_selection_service_component_name);
13087 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13088 TelephonyDomainSelectionService.class.getName());
13089 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13090 + ", aosp=" + componentName.flattenToString());
13091 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13092 }
13093 } finally {
13094 Binder.restoreCallingIdentity(identity);
13095 }
13096 return false;
13097 }
13098
13099 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013100 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13101 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13102 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013103 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013104 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013105 * @param enableSatellite {@code true} to enable the satellite modem and
13106 * {@code false} to disable.
13107 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013108 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013109 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013110 *
13111 * @throws SecurityException if the caller doesn't have the required permission.
13112 */
13113 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013114 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013115 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013116 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013117 if (enableSatellite) {
13118 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13119 @Override
13120 protected void onReceiveResult(int resultCode, Bundle resultData) {
13121 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13122 + ", resultData=" + resultData);
13123 boolean isAllowed = false;
13124 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13125 callback::accept);
13126 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13127 if (resultData != null
13128 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13129 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13130 } else {
13131 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13132 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013133 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013134 result.accept(resultCode);
13135 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013136 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013137 if (isAllowed) {
13138 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013139 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013140 } else {
13141 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13142 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013143 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013144 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013145 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013146 subId, resultReceiver);
13147 } else {
13148 // No need to check if satellite is allowed at current location when disabling satellite
13149 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013150 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013151 }
Sarah Chin503828c2023-02-01 23:54:20 -080013152 }
13153
13154 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013155 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013156 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013157 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013158 * @param result The result receiver that returns whether the satellite modem is enabled
13159 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013160 *
13161 * @throws SecurityException if the caller doesn't have the required permission.
13162 */
13163 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013164 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13165 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013166 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013167 }
13168
13169 /**
Sarah Chin43457982023-02-15 17:50:38 -080013170 * Request to get whether the satellite service demo mode is enabled.
13171 *
13172 * @param subId The subId of the subscription to check whether the satellite demo mode
13173 * is enabled for.
13174 * @param result The result receiver that returns whether the satellite demo mode is enabled
13175 * if the request is successful or an error code if the request failed.
13176 *
13177 * @throws SecurityException if the caller doesn't have the required permission.
13178 */
13179 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013180 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13181 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13182 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013183 }
13184
13185 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013186 * Request to get whether the satellite service is enabled with emergency mode.
13187 *
13188 * @param subId The subId of the subscription to check whether the satellite demo mode
13189 * is enabled for.
13190 * @param result The result receiver that returns whether the satellite emergency mode is
13191 * enabled if the request is successful or an error code if the request failed.
13192 *
13193 * @throws SecurityException if the caller doesn't have the required permission.
13194 */
13195 @Override
13196 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13197 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13198 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13199 }
13200
13201 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013202 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013203 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013204 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013205 * @param result The result receiver that returns whether the satellite service is supported on
13206 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013207 */
13208 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013209 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013210 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013211 }
13212
13213 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013214 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013215 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013216 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013217 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13218 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013219 *
13220 * @throws SecurityException if the caller doesn't have required permission.
13221 */
13222 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013223 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13224 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013225 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013226 }
13227
13228 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013229 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013230 * This can be called by the pointing UI when the user starts pointing to the satellite.
13231 * Modem should continue to report the pointing input as the device or satellite moves.
13232 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013233 * @param subId The subId of the subscription to start satellite transmission updates for.
13234 * @param resultCallback The callback to get the result of the request.
13235 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013236 *
13237 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013238 */
13239 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013240 public void startSatelliteTransmissionUpdates(int subId,
13241 @NonNull IIntegerConsumer resultCallback,
13242 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13243 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13244 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013245 }
13246
13247 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013248 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013249 * This can be called by the pointing UI when the user stops pointing to the satellite.
13250 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013251 * @param subId The subId of the subscription to stop satellite transmission updates for.
13252 * @param resultCallback The callback to get the result of the request.
13253 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13254 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013255 *
13256 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013257 */
13258 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013259 public void stopSatelliteTransmissionUpdates(int subId,
13260 @NonNull IIntegerConsumer resultCallback,
13261 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13262 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13263 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013264 }
13265
13266 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013267 * Register the subscription with a satellite provider.
13268 * This is needed to register the subscription if the provider allows dynamic registration.
13269 *
13270 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013271 * @param token The token to be used as a unique identifier for provisioning with satellite
13272 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013273 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013274 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013275 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013276 * @return The signal transport used by the caller to cancel the provision request,
13277 * or {@code null} if the request failed.
13278 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013279 * @throws SecurityException if the caller doesn't have the required permission.
13280 */
13281 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013282 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013283 @NonNull String token, @NonNull byte[] provisionData,
13284 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013285 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013286 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13287 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013288 }
13289
13290 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013291 * Unregister the device/subscription with the satellite provider.
13292 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013293 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013294 * should report as deprovisioned.
13295 *
13296 * @param subId The subId of the subscription to be deprovisioned.
13297 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013298 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013299 *
13300 * @throws SecurityException if the caller doesn't have the required permission.
13301 */
13302 @Override
13303 public void deprovisionSatelliteService(int subId,
13304 @NonNull String token, @NonNull IIntegerConsumer callback) {
13305 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013306 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013307 }
13308
13309 /**
Sarah Chin43457982023-02-15 17:50:38 -080013310 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013311 *
Sarah Chin43457982023-02-15 17:50:38 -080013312 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013313 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013314 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013315 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013316 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013317 * @throws SecurityException if the caller doesn't have the required permission.
13318 */
13319 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013320 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13321 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013322 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013323 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013324 }
13325
13326 /**
Sarah Chin43457982023-02-15 17:50:38 -080013327 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013328 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013329 *
Sarah Chin43457982023-02-15 17:50:38 -080013330 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013331 * @param callback The callback that was passed to
13332 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013333 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013334 * @throws SecurityException if the caller doesn't have the required permission.
13335 */
13336 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013337 public void unregisterForSatelliteProvisionStateChanged(
13338 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013339 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013340 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013341 }
13342
13343 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013344 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013345 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013346 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013347 * @param result The result receiver that returns whether the device is provisioned with a
13348 * satellite provider if the request is successful or an error code if the
13349 * request failed.
13350 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013351 * @throws SecurityException if the caller doesn't have the required permission.
13352 */
13353 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013354 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13355 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013356 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013357 }
13358
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013359 /**
Sarah Chin43457982023-02-15 17:50:38 -080013360 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013361 *
Sarah Chin43457982023-02-15 17:50:38 -080013362 * @param subId The subId of the subscription to register for satellite modem state changed.
13363 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013364 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013365 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013366 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013367 * @throws SecurityException if the caller doesn't have the required permission.
13368 */
13369 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013370 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013371 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013372 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013373 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013374 }
13375
13376 /**
Sarah Chin43457982023-02-15 17:50:38 -080013377 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013378 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013379 *
Sarah Chin43457982023-02-15 17:50:38 -080013380 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013381 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013382 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013383 *
13384 * @throws SecurityException if the caller doesn't have the required permission.
13385 */
13386 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013387 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013388 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013389 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13390 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013391 }
13392
13393 /**
13394 * Register to receive incoming datagrams over satellite.
13395 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013396 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013397 * @param callback The callback to handle incoming datagrams over satellite.
13398 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013399 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013400 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013401 * @throws SecurityException if the caller doesn't have the required permission.
13402 */
13403 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013404 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013405 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013406 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13407 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013408 }
13409
13410 /**
13411 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013412 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013413 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013414 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13415 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013416 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013417 *
13418 * @throws SecurityException if the caller doesn't have the required permission.
13419 */
13420 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013421 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013422 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013423 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13424 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013425 }
13426
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013427 /**
13428 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013429 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013430 * This method requests modem to check if there are any pending datagrams to be received over
13431 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013432 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013433 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013434 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013435 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013436 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013437 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013438 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013439 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13440 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13441 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013442 }
13443
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013444 /**
13445 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013446 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013447 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13448 * input to this method. Datagram received here will be passed down to modem without any
13449 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013450 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013451 * @param subId The subId of the subscription to send satellite datagrams for.
13452 * @param datagramType datagram type indicating whether the datagram is of type
13453 * SOS_SMS or LOCATION_SHARING.
13454 * @param datagram encoded gateway datagram which is encrypted by the caller.
13455 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013456 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13457 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013458 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013459 *
13460 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013461 */
13462 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013463 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013464 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13465 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013466 enforceSatelliteCommunicationPermission("sendDatagram");
13467 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13468 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013469 }
13470
Sarah Chindf715ec2023-02-13 13:46:24 -080013471 /**
13472 * Request to get whether satellite communication is allowed for the current location.
13473 *
13474 * @param subId The subId of the subscription to check whether satellite communication is
13475 * allowed for the current location for.
13476 * @param result The result receiver that returns whether satellite communication is allowed
13477 * for the current location if the request is successful or an error code
13478 * if the request failed.
13479 *
13480 * @throws SecurityException if the caller doesn't have the required permission.
13481 */
13482 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013483 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013484 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013485 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13486 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13487 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013488 }
13489
13490 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013491 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013492 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013493 * @param subId The subId to get the time after which the satellite will be visible for.
13494 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013495 * be visible if the request is successful or an error code if the request failed.
13496 *
13497 * @throws SecurityException if the caller doesn't have the required permission.
13498 */
13499 @Override
13500 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13501 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013502 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013503 }
13504
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013505 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013506 * Inform that Device is aligned to satellite for demo mode.
13507 *
13508 * @param subId The subId to get the time after which the satellite will be visible for.
13509 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13510 * {@code false} Device fails to align with the satellite for demo mode.
13511 *
13512 * @throws SecurityException if the caller doesn't have required permission.
13513 */
13514 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13515
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013516 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013517 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013518 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013519 }
13520
13521 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013522 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13523 * by modem.
13524 *
13525 * @param subId The subId of the subscription to request for.
13526 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013527 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013528 * operation.
13529 *
13530 * @throws SecurityException if the caller doesn't have required permission.
13531 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013532 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013533 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13534 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013535 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013536 final long identity = Binder.clearCallingIdentity();
13537 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013538 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013539 } finally {
13540 Binder.restoreCallingIdentity(identity);
13541 }
13542 }
13543
13544 /**
13545 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13546 * by modem.
13547 *
13548 * @param subId The subId of the subscription to request for.
13549 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013550 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013551 * operation.
13552 *
13553 * @throws SecurityException if the caller doesn't have required permission.
13554 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013555 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013556 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13557 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013558 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013559 final long identity = Binder.clearCallingIdentity();
13560 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013561 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013562 } finally {
13563 Binder.restoreCallingIdentity(identity);
13564 }
13565 }
13566
13567 /**
13568 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013569 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013570 *
13571 * @param subId The subId of the subscription to request for.
13572 *
13573 * @return Integer array of reasons for disallowing satellite communication.
13574 *
13575 * @throws SecurityException if the caller doesn't have the required permission.
13576 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013577 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013578 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013579 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013580 final long identity = Binder.clearCallingIdentity();
13581 try {
13582 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013583 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013584 return reasonSet.stream().mapToInt(i->i).toArray();
13585 } finally {
13586 Binder.restoreCallingIdentity(identity);
13587 }
13588 }
13589
13590 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013591 * Request to get the signal strength of the satellite connection.
13592 *
13593 * @param subId The subId of the subscription to request for.
13594 * @param result Result receiver to get the error code of the request and the current signal
13595 * strength of the satellite connection.
13596 *
13597 * @throws SecurityException if the caller doesn't have required permission.
13598 */
13599 @Override
13600 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13601 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13602 final long identity = Binder.clearCallingIdentity();
13603 try {
13604 mSatelliteController.requestNtnSignalStrength(subId, result);
13605 } finally {
13606 Binder.restoreCallingIdentity(identity);
13607 }
13608 }
13609
13610 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013611 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13612 * is not successful, a {@link ServiceSpecificException} that contains
13613 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013614 *
13615 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013616 * @param callback The callback to handle the NTN signal strength changed event. If the
13617 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13618 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13619 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13620 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013621 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013622 * @throws SecurityException If the caller doesn't have the required permission.
13623 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013624 */
13625 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013626 public void registerForNtnSignalStrengthChanged(int subId,
13627 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013628 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13629 final long identity = Binder.clearCallingIdentity();
13630 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013631 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013632 } finally {
13633 Binder.restoreCallingIdentity(identity);
13634 }
13635 }
13636
13637 /**
13638 * Unregisters for NTN signal strength changed from satellite modem.
13639 * If callback was not registered before, the request will be ignored.
13640 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013641 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13642 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013643 * @param callback The callback that was passed to
13644 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13645 *
13646 * @throws SecurityException if the caller doesn't have the required permission.
13647 */
13648 @Override
13649 public void unregisterForNtnSignalStrengthChanged(
13650 int subId, @NonNull INtnSignalStrengthCallback callback) {
13651 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13652 final long identity = Binder.clearCallingIdentity();
13653 try {
13654 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13655 } finally {
13656 Binder.restoreCallingIdentity(identity);
13657 }
13658 }
13659
13660 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013661 * Registers for satellite capabilities change event from the satellite service.
13662 *
13663 * @param subId The subId of the subscription to request for.
13664 * @param callback The callback to handle the satellite capabilities changed event.
13665 *
13666 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13667 *
13668 * @throws SecurityException if the caller doesn't have required permission.
13669 */
13670 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013671 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013672 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013673 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013674 final long identity = Binder.clearCallingIdentity();
13675 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013676 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013677 } finally {
13678 Binder.restoreCallingIdentity(identity);
13679 }
13680 }
13681
13682 /**
13683 * Unregisters for satellite capabilities change event from the satellite service.
13684 * If callback was not registered before, the request will be ignored.
13685 *
13686 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13687 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013688 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013689 *
13690 * @throws SecurityException if the caller doesn't have required permission.
13691 */
13692 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013693 public void unregisterForCapabilitiesChanged(int subId,
13694 @NonNull ISatelliteCapabilitiesCallback callback) {
13695 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013696 final long identity = Binder.clearCallingIdentity();
13697 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013698 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013699 } finally {
13700 Binder.restoreCallingIdentity(identity);
13701 }
13702 }
13703
13704 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013705 * Registers for the satellite supported state changed.
13706 *
13707 * @param subId The subId of the subscription to register for supported state changed.
13708 * @param callback The callback to handle the satellite supported state changed event.
13709 *
13710 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13711 *
13712 * @throws SecurityException if the caller doesn't have the required permission.
13713 */
13714 @Override
13715 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13716 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13717 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13718 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13719 }
13720
13721 /**
13722 * Unregisters for the satellite supported state changed.
13723 * If callback was not registered before, the request will be ignored.
13724 *
13725 * @param subId The subId of the subscription to unregister for supported state changed.
13726 * @param callback The callback that was passed to
13727 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13728 *
13729 * @throws SecurityException if the caller doesn't have the required permission.
13730 */
13731 @Override
13732 public void unregisterForSatelliteSupportedStateChanged(
13733 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13734 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13735 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13736 }
13737
13738 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013739 * This API can be used by only CTS to update satellite vendor service package name.
13740 *
13741 * @param servicePackageName The package name of the satellite vendor service.
13742 * @return {@code true} if the satellite vendor service is set successfully,
13743 * {@code false} otherwise.
13744 */
13745 public boolean setSatelliteServicePackageName(String servicePackageName) {
13746 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13747 TelephonyPermissions.enforceShellOnly(
13748 Binder.getCallingUid(), "setSatelliteServicePackageName");
13749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13750 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13751 "setSatelliteServicePackageName");
13752 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13753 }
13754
13755 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013756 * This API can be used by only CTS to update satellite gateway service package name.
13757 *
13758 * @param servicePackageName The package name of the satellite gateway service.
13759 * @return {@code true} if the satellite gateway service is set successfully,
13760 * {@code false} otherwise.
13761 */
13762 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13763 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13764 TelephonyPermissions.enforceShellOnly(
13765 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13767 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13768 "setSatelliteGatewayServicePackageName");
13769 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13770 }
13771
13772 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013773 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13774 *
13775 * @param packageName The package name of the satellite pointing UI app.
13776 * @param className The class name of the satellite pointing UI app.
13777 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13778 * {@code false} otherwise.
13779 */
13780 public boolean setSatellitePointingUiClassName(
13781 @Nullable String packageName, @Nullable String className) {
13782 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13783 + ", className=" + className);
13784 TelephonyPermissions.enforceShellOnly(
13785 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13787 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13788 "setSatelliteGatewayServicePackageName");
13789 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13790 }
13791
13792 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013793 * This API can be used by only CTS to update the timeout duration in milliseconds that
13794 * satellite should stay at listening mode to wait for the next incoming page before disabling
13795 * listening mode.
13796 *
13797 * @param timeoutMillis The timeout duration in millisecond.
13798 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13799 */
13800 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13801 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13802 TelephonyPermissions.enforceShellOnly(
13803 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13805 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13806 "setSatelliteListeningTimeoutDuration");
13807 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13808 }
13809
13810 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013811 * This API can be used by only CTS to override the timeout durations used by the
13812 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013813 *
13814 * @param timeoutMillis The timeout duration in millisecond.
13815 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13816 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013817 public boolean setDatagramControllerTimeoutDuration(
13818 boolean reset, int timeoutType, long timeoutMillis) {
13819 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13820 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013821 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013822 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13824 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013825 "setDatagramControllerTimeoutDuration");
13826 return mSatelliteController.setDatagramControllerTimeoutDuration(
13827 reset, timeoutType, timeoutMillis);
13828 }
13829
13830 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013831 * This API can be used by only CTS to override the boolean configs used by the
13832 * DatagramController module.
13833 *
13834 * @param enable Whether to enable or disable boolean config.
13835 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13836 */
13837 public boolean setDatagramControllerBooleanConfig(
13838 boolean reset, int booleanType, boolean enable) {
13839 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13840 + ", reset=" + reset + ", enable=" + enable);
13841 TelephonyPermissions.enforceShellOnly(
13842 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13844 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13845 "ssetDatagramControllerBooleanConfig");
13846 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13847 }
13848
13849
13850 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013851 * This API can be used by only CTS to override the timeout durations used by the
13852 * SatelliteController module.
13853 *
13854 * @param timeoutMillis The timeout duration in millisecond.
13855 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13856 */
13857 public boolean setSatelliteControllerTimeoutDuration(
13858 boolean reset, int timeoutType, long timeoutMillis) {
13859 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13860 + reset + ", timeoutMillis=" + timeoutMillis);
13861 TelephonyPermissions.enforceShellOnly(
13862 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13864 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13865 "setSatelliteControllerTimeoutDuration");
13866 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13867 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013868 }
13869
13870 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013871 * This API can be used in only testing to override connectivity status in monitoring emergency
13872 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13873 *
13874 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13875 * of the following values to enable the override:
13876 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13877 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13878 * To disable the override, use -1 for handoverType.
13879 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13880 * delaySeconds after the emergency call starts.
13881 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13882 */
13883 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13884 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13885 TelephonyPermissions.enforceShellOnly(
13886 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13888 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13889 "setEmergencyCallToSatelliteHandoverType");
13890 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13891 handoverType, delaySeconds);
13892 }
13893
13894 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013895 * This API can be used in only testing to override oem-enabled satellite provision status.
13896 *
13897 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13898 * otherwise.
13899 * @param isProvisioned The overriding provision status.
13900 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13901 */
13902 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13903 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13904 + ", isProvisioned=" + isProvisioned);
13905 TelephonyPermissions.enforceShellOnly(
13906 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13908 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13909 "setOemEnabledSatelliteProvisionStatus");
13910 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13911 }
13912
13913 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013914 * This API should be used by only CTS tests to forcefully set telephony country codes.
13915 *
13916 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13917 */
13918 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13919 Map cachedNetworkCountryCodes, String locationCountryCode,
13920 long locationCountryCodeTimestampNanos) {
13921 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13922 + String.join(", ", currentNetworkCountryCodes)
13923 + ", locationCountryCode=" + locationCountryCode
13924 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13925 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13926 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13927 TelephonyPermissions.enforceShellOnly(
13928 Binder.getCallingUid(), "setCachedLocationCountryCode");
13929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13930 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13931 "setCachedLocationCountryCode");
13932 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13933 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13934 locationCountryCodeTimestampNanos);
13935 }
13936
13937 /**
13938 * This API should be used by only CTS tests to override the overlay configs of satellite
13939 * access controller.
13940 *
13941 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13942 * otherwise.
13943 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13944 */
13945 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13946 String s2CellFile, long locationFreshDurationNanos,
13947 List<String> satelliteCountryCodes) {
13948 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13949 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13950 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13951 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13952 ? String.join(", ", satelliteCountryCodes) : null));
13953 TelephonyPermissions.enforceShellOnly(
13954 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13956 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13957 "setSatelliteAccessControlOverlayConfigs");
13958 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13959 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13960 }
13961
13962 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013963 * This API can be used by only CTS to override the cached value for the device overlay config
13964 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13965 * outgoing satellite datagrams should be sent to modem in demo mode.
13966 *
13967 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13968 * satellite modem or not.
13969 *
13970 * @return {@code true} if the operation is successful, {@code false} otherwise.
13971 */
13972 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13973 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13974 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13975 + "disabled");
13976 return false;
13977 }
13978 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13979 TelephonyPermissions.enforceShellOnly(
13980 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13982 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13983 "setShouldSendDatagramToModemInDemoMode");
13984 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13985 shouldSendToModemInDemoMode);
13986 }
13987
13988 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000013989 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
13990 *
13991 * @param state a state indicates whether satellite access allowed state should be cached and
13992 * the allowed state.
13993 * @return {@code true} if the setting is successful, {@code false} otherwise.
13994 */
13995 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
13996 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13997 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13998 + "oemEnabledSatelliteFlag is disabled");
13999 return false;
14000 }
14001
14002 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
14003 + "state=" + state);
14004 TelephonyPermissions.enforceShellOnly(
14005 Binder.getCallingUid(),
14006 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14008 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
14009 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
14010 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
14011 state);
14012 }
14013
14014 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014015 * Sets the service defined in ComponentName to be bound.
14016 *
14017 * This should only be used for testing.
14018 * @return {@code true} if the DomainSelectionService to bind to was set,
14019 * {@code false} otherwise.
14020 */
14021 @Override
14022 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14023 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14024
14025 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14026 "setDomainSelectionServiceOverride");
14027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14028 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14029
14030 final long identity = Binder.clearCallingIdentity();
14031 try {
14032 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14033 return DomainSelectionResolver.getInstance()
14034 .setDomainSelectionServiceOverride(componentName);
14035 }
14036 } finally {
14037 Binder.restoreCallingIdentity(identity);
14038 }
14039 return false;
14040 }
14041
14042 /**
14043 * Clears the DomainSelectionService override.
14044 *
14045 * This should only be used for testing.
14046 * @return {@code true} if the DomainSelectionService override was cleared,
14047 * {@code false} otherwise.
14048 */
14049 @Override
14050 public boolean clearDomainSelectionServiceOverride() {
14051 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14052
14053 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14054 "clearDomainSelectionServiceOverride");
14055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14056 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14057
14058 final long identity = Binder.clearCallingIdentity();
14059 try {
14060 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14061 return DomainSelectionResolver.getInstance()
14062 .clearDomainSelectionServiceOverride();
14063 }
14064 } finally {
14065 Binder.restoreCallingIdentity(identity);
14066 }
14067 return false;
14068 }
14069
14070 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014071 * Enable or disable notifications sent for cellular identifier disclosure events.
14072 *
14073 * Disclosure events are defined as instances where a device has sent a cellular identifier
14074 * on the Non-access stratum (NAS) before a security context is established. As a result the
14075 * identifier is sent in the clear, which has privacy implications for the user.
14076 *
14077 * @param enable if notifications about disclosure events should be enabled
14078 * @throws SecurityException if the caller does not have the required privileges
14079 * @throws UnsupportedOperationException if the modem does not support this feature.
14080 */
14081 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014082 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014083 enforceModifyPermission();
14084 checkForIdentifierDisclosureNotificationSupport();
14085
14086 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14087 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14088 editor.apply();
14089
14090 // Each phone instance is responsible for updating its respective modem immediately
14091 // after we've made a preference change.
14092 for (Phone phone : PhoneFactory.getPhones()) {
14093 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14094 }
14095 }
14096
14097 /**
14098 * Get whether or not cellular identifier disclosure notifications are enabled.
14099 *
14100 * @throws SecurityException if the caller does not have the required privileges
14101 * @throws UnsupportedOperationException if the modem does not support this feature.
14102 */
14103 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014104 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014105 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14106 checkForIdentifierDisclosureNotificationSupport();
14107 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14108 }
14109
14110 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014111 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14112 * are in use by the cellular modem.
14113 *
14114 * @throws IllegalStateException if the Telephony process is not currently available
14115 * @throws SecurityException if the caller does not have the required privileges
14116 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14117 * and integrity algorithms in use
14118 * @hide
14119 */
14120 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014121 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014122 enforceModifyPermission();
14123 checkForNullCipherNotificationSupport();
14124
14125 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14126 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14127 editor.apply();
14128
14129 // Each phone instance is responsible for updating its respective modem immediately
14130 // after a preference change.
14131 for (Phone phone : PhoneFactory.getPhones()) {
14132 phone.handleNullCipherNotificationPreferenceChanged();
14133 }
14134 }
14135
14136 /**
14137 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14138 * cellular modem.
14139 *
14140 * @throws IllegalStateException if the Telephony process is not currently available
14141 * @throws SecurityException if the caller does not have the required privileges
14142 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14143 * and integrity algorithms in use
14144 * @hide
14145 */
14146 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14147 public boolean isNullCipherNotificationsEnabled() {
14148 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14149 checkForNullCipherNotificationSupport();
14150 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14151 }
14152
14153 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014154 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14155 *
14156 * <p>This method behaves in one of the following ways:
14157 * <ul>
14158 * <li>return true : if the calling package has the appop permission {@link
14159 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14160 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14161 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14162 * Owner device identifier access check, or the calling package has carrier privileges</>
14163 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14164 * </ul>
14165 */
14166 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14167 String callingPackage, @Nullable String callingFeatureId, String message) {
14168 for (Phone phone : PhoneFactory.getPhones()) {
14169 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14170 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14171 return true;
14172 }
14173 }
14174 return false;
14175 }
arunvoddud7401012022-12-15 16:08:12 +000014176
14177 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014178 * @return The subscription manager service instance.
14179 */
14180 public SubscriptionManagerService getSubscriptionManagerService() {
14181 return SubscriptionManagerService.getInstance();
14182 }
14183
14184 /**
arunvoddud7401012022-12-15 16:08:12 +000014185 * Class binds the consumer[callback] and carrierId.
14186 */
14187 private static class CallerCallbackInfo {
14188 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014189 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014190
Steve Statia28b7cb32024-03-11 23:58:50 +000014191 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014192 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014193 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014194 }
14195
14196 public Consumer<Integer> getConsumer() {
14197 return mConsumer;
14198 }
14199
Steve Statia28b7cb32024-03-11 23:58:50 +000014200 public Set<Integer> getCarrierIds() {
14201 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014202 }
14203 }
joonhunshin4ac60942023-11-15 15:23:39 +000014204
14205 /*
14206 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14207 * But the context that is passed in is unused if the phone app is already alive.
14208 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14209 */
14210 @VisibleForTesting
14211 public void setPackageManager(PackageManager packageManager) {
14212 mPackageManager = packageManager;
14213 }
14214
14215 /*
Nate Myren453c3472024-03-13 11:28:11 -070014216 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14217 * But the context that is passed in is unused if the phone app is already alive.
14218 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14219 */
14220 @VisibleForTesting
14221 public void setAppOpsManager(AppOpsManager appOps) {
14222 mAppOps = appOps;
14223 }
14224
14225 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014226 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14227 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14228 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14229 */
14230 @VisibleForTesting
14231 public void setFeatureFlags(FeatureFlags featureFlags) {
14232 mFeatureFlags = featureFlags;
14233 }
14234
14235 /**
14236 * Make sure the device has required telephony feature
14237 *
14238 * @throws UnsupportedOperationException if the device does not have required telephony feature
14239 */
14240 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14241 @NonNull String telephonyFeature, @NonNull String methodName) {
14242 if (callingPackage == null || mPackageManager == null) {
14243 return;
14244 }
14245
14246 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14247 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014248 Binder.getCallingUserHandle())
14249 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14250 // Skip to check associated telephony feature,
14251 // if compatibility change is not enabled for the current process or
14252 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014253 return;
14254 }
14255
14256 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14257 throw new UnsupportedOperationException(
14258 methodName + " is unsupported without " + telephonyFeature);
14259 }
14260 }
youngtaecha5d483d52024-04-29 17:05:45 +000014261
14262 /**
14263 * Registers for the satellite communication allowed state changed.
14264 *
14265 * @param subId The subId of the subscription to register for the satellite communication
14266 * allowed state changed.
14267 * @param callback The callback to handle the satellite communication allowed
14268 * state changed event.
14269 *
14270 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14271 *
14272 * @throws SecurityException if the caller doesn't have the required permission.
14273 */
14274 @Override
14275 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14276 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14277 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14278 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14279 subId, callback);
14280 }
14281
14282 /**
14283 * Unregisters for the satellite communication allowed state changed.
14284 * If callback was not registered before, the request will be ignored.
14285 *
14286 * @param subId The subId of the subscription to unregister for the satellite communication
14287 * allowed state changed.
14288 * @param callback The callback that was passed to
14289 * {@link #registerForCommunicationAllowedStateChanged(int,
14290 * ISatelliteCommunicationAllowedStateCallback)}. *
14291 * @throws SecurityException if the caller doesn't have the required permission.
14292 */
14293 @Override
14294 public void unregisterForCommunicationAllowedStateChanged(
14295 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14296 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14297 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14298 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014299
14300 /**
14301 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14302 *
14303 * @param subId The subId of the subscription to the satellite session stats for.
14304 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14305 * if the request is successful or an error code if the request failed.
14306 *
14307 * @throws SecurityException if the caller doesn't have required permission.
14308 */
14309 @Override
14310 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14311 enforceModifyPermission();
14312 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
14313 mSatelliteController.requestSatelliteSessionStats(subId, result);
14314 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014315
14316 /**
14317 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14318 *
14319 * @param result The result receiver, which returns the list of prioritized satellite tokens
14320 * to be used for provision if the request is successful or an error code if the request failed.
14321 *
14322 * @throws SecurityException if the caller doesn't have the required permission.
14323 */
14324 @Override
14325 public void requestProvisionSubscriberIds(@NonNull ResultReceiver result) {
14326 enforceSatelliteCommunicationPermission("requestProvisionSubscriberIds");
14327 mSatelliteController.requestProvisionSubscriberIds(result);
14328 }
14329
14330 /**
14331 * Request to get provisioned status for given a satellite subscriber id.
14332 *
14333 * @param satelliteSubscriberId Satellite subscriber id requiring provisioned status check.
14334 * @param result The result receiver, which returns the provisioned status of the token if the
14335 * request is successful or an error code if the request failed.
14336 *
14337 * @throws SecurityException if the caller doesn't have the required permission.
14338 */
14339 @Override
14340 public void requestIsProvisioned(String satelliteSubscriberId, @NonNull ResultReceiver result) {
14341 enforceSatelliteCommunicationPermission("requestIsProvisioned");
14342 mSatelliteController.requestIsProvisioned(satelliteSubscriberId, result);
14343 }
14344
14345 /**
14346 * Deliver the list of provisioned satellite subscriber ids.
14347 *
14348 * @param list List of provisioned satellite subscriber ids.
14349 * @param result The result receiver that returns whether deliver success or fail.
14350 *
14351 * @throws SecurityException if the caller doesn't have the required permission.
14352 */
14353 @Override
14354 public void provisionSatellite(List<ProvisionSubscriberId> list,
14355 @NonNull ResultReceiver result) {
14356 enforceSatelliteCommunicationPermission("provisionSatellite");
14357 mSatelliteController.provisionSatellite(list, result);
14358 }
Jack Yufa8ed012023-02-11 15:42:28 -080014359}