blob: af8caa458a9819a2a85e2f97cafa2bcfc7bccb99 [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;
Sarah Chin503828c2023-02-01 23:54:20 -0800168import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000169import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800170import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800171import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800172import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700175import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800177import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800178
Andrew Lee312e8172014-10-23 17:01:36 -0700179import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800180import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800181import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800182import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800183import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700185import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700186import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800187import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800188import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700189import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700190import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800191import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700192import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800193import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800194import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000197import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700198import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800199import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800201import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800202import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800203import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700204import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700205import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700206import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700208import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800209import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700210import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700211import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700212import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700213import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800214import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800215import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700216import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000217import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700218import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700219import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800220import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800221import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800222import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700223import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000224import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800225import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700226import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700227import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800228import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700229import com.android.internal.telephony.imsphone.ImsPhone;
230import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000231import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800232import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000233import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800234import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
235import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700236import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700237import com.android.internal.telephony.uicc.IccIoResult;
238import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700240import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800241import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000243import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800244import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000245import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800246import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000247import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700248import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700249import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800250import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800251import com.android.phone.callcomposer.CallComposerPictureManager;
252import com.android.phone.callcomposer.CallComposerPictureTransfer;
253import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800254import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000255import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700256import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700257import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000258import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700259import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800260import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700261import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700262import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800263import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800264import com.android.services.telephony.TelecomAccountRegistry;
265import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000266import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800267import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800268
Hall Liu82694d52020-12-11 18:22:04 -0800269import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700270import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800271import java.io.IOException;
272import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700273import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800275import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000276import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800277import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800278import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800279import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800280import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100281import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800282import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700283import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800284import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800285import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700286import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800287import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800288import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800289import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
291/**
292 * Implementation of the ITelephony interface.
293 */
Santos Cordon117fee72014-05-16 17:56:12 -0700294public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 private static final String LOG_TAG = "PhoneInterfaceManager";
296 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
297 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800298 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299
300 // Message codes used with mMainThreadHandler
301 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700302 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
303 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700304 private static final int CMD_OPEN_CHANNEL = 9;
305 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
306 private static final int CMD_CLOSE_CHANNEL = 11;
307 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800308 private static final int CMD_NV_READ_ITEM = 13;
309 private static final int EVENT_NV_READ_ITEM_DONE = 14;
310 private static final int CMD_NV_WRITE_ITEM = 15;
311 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
312 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
313 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700314 private static final int CMD_RESET_MODEM_CONFIG = 19;
315 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800316 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
317 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800318 private static final int CMD_SEND_ENVELOPE = 25;
319 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700320 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
321 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
322 private static final int CMD_EXCHANGE_SIM_IO = 31;
323 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800324 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
325 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700326 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
327 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700328 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
329 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700330 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
331 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
332 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
333 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700334 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
335 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
336 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
337 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700338 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800339 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
340 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000341 private static final int CMD_SWITCH_SLOTS = 50;
342 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700343 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
344 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
345 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
346 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
347 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
348 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
349 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
350 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700351 private static final int CMD_GET_ALL_CELL_INFO = 60;
352 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
353 private static final int CMD_GET_CELL_LOCATION = 62;
354 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700355 private static final int CMD_MODEM_REBOOT = 64;
356 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700357 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
358 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800359 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
360 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700361 private static final int CMD_GET_MODEM_STATUS = 70;
362 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700363 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
364 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700365 private static final int CMD_ERASE_MODEM_CONFIG = 74;
366 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800367 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
368 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
369 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
370 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800371 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
372 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800374 private static final int CMD_GET_CALL_FORWARDING = 83;
375 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
376 private static final int CMD_SET_CALL_FORWARDING = 85;
377 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
378 private static final int CMD_GET_CALL_WAITING = 87;
379 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
380 private static final int CMD_SET_CALL_WAITING = 89;
381 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700382 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
383 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
384 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
385 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700386 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
387 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800388 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
389 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800390 private static final int CMD_SET_DATA_THROTTLING = 99;
391 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800392 private static final int CMD_SET_SIM_POWER = 101;
393 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800394 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
395 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
396 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
397 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800398 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
399 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000400 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800401 private static final int CMD_GET_SLICING_CONFIG = 110;
402 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800403 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700404 private static final int CMD_ENABLE_VONR = 113;
405 private static final int EVENT_ENABLE_VONR_DONE = 114;
406 private static final int CMD_IS_VONR_ENABLED = 115;
407 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700408 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
409 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000410
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800411 // Parameters of select command.
412 private static final int SELECT_COMMAND = 0xA4;
413 private static final int SELECT_P1 = 0x04;
414 private static final int SELECT_P2 = 0;
415 private static final int SELECT_P3 = 0x10;
416
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000417 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
418 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000419 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
420 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600421 // Null cipher notification support was added in IRadioNetwork 2.2
422 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 /** The singleton instance. */
425 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800426 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427
Sarah Chin4beb2b72023-02-14 14:47:54 -0800428 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000429 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800430 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800431 private final CallManager mCM;
432 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000433
434 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800435 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800436 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800437 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final SharedPreferences mTelephonySharedPreferences;
439 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800440 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700441 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000442 private PackageManager mPackageManager;
joonhunshinf624b2a2024-04-18 04:42:12 +0000443 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Peter Wangdafb9ac2020-01-15 14:13:38 -0800445 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800446 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800447 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800448 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800449
Derek Tan97ebb422014-09-05 16:55:38 -0700450 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
451 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800452 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800453 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700454
Michelecea4cf22018-12-21 15:00:11 -0800455 // String to store multi SIM allowed
456 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
457
Derek Tan740e1672017-06-27 14:56:27 -0700458 // The AID of ISD-R.
459 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
460
yinxub1bed742017-04-17 11:45:04 -0700461 private NetworkScanRequestTracker mNetworkScanRequestTracker;
462
David Kelly5e06a7f2018-03-12 14:10:59 +0000463 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
464 private static final int MANUFACTURER_CODE_LENGTH = 8;
465
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800466 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800467 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800468
Sarah Chin2ec39f62022-08-31 17:03:26 -0700469 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
470 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
471
Derek Tan89e89d42014-07-08 17:00:10 -0700472 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700473 * Experiment flag to enable erase modem config on reset network, default value is false
474 */
475 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
476 "reset_network_erase_modem_config_enabled";
477
Rambo Wang0f050d82021-02-12 11:43:36 -0800478 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800479
Gary Jian76280a42022-12-07 16:18:33 +0800480 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
481
sandeepjsb6c87872021-09-27 15:34:44 +0000482 /**
483 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
484 * one ICCID active at the same time.
485 * Apps should use below API signatures if targeting SDK is T and beyond.
486 *
487 * @hide
488 */
489 @ChangeId
490 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
491 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800492
Naina Nallurid63128d2019-09-17 14:10:30 -0700493 /**
Chen Xu540470b2021-12-14 17:15:47 -0800494 * Apps targeting on Android T and beyond will get exception whenever icc close channel
495 * operation fails.
496 */
497 @ChangeId
498 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
499 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
500
501 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700502 * A request object to use for transmitting data to an ICC.
503 */
504 private static final class IccAPDUArgument {
505 public int channel, cla, command, p1, p2, p3;
506 public String data;
507
508 public IccAPDUArgument(int channel, int cla, int command,
509 int p1, int p2, int p3, String data) {
510 this.channel = channel;
511 this.cla = cla;
512 this.command = command;
513 this.p1 = p1;
514 this.p2 = p2;
515 this.p3 = p3;
516 this.data = data;
517 }
518 }
519
520 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700521 * A request object to use for transmitting data to an ICC.
522 */
523 private static final class ManualNetworkSelectionArgument {
524 public OperatorInfo operatorInfo;
525 public boolean persistSelection;
526
527 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
528 this.operatorInfo = operatorInfo;
529 this.persistSelection = persistSelection;
530 }
531 }
532
Sarah Chin71b3a852022-09-28 15:54:19 -0700533 private static final class PurchasePremiumCapabilityArgument {
534 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700535 public @NonNull IIntegerConsumer callback;
536
537 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800538 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700539 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700540 this.callback = callback;
541 }
542 }
543
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700544 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
546 * request after sending. The main thread will notify the request when it is complete.
547 */
548 private static final class MainThreadRequest {
549 /** The argument to use for the request */
550 public Object argument;
551 /** The result of the request that is run on the main thread */
552 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800553 // The subscriber id that this request applies to. Defaults to
554 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
555 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556
Nathan Harold92bed182018-10-12 18:16:49 -0700557 // In cases where subId is unavailable, the caller needs to specify the phone.
558 public Phone phone;
559
vagdeviaf9a5b92018-08-15 16:01:53 -0700560 public WorkSource workSource;
561
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700562 public MainThreadRequest(Object argument) {
563 this.argument = argument;
564 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800565
Nathan Harold92bed182018-10-12 18:16:49 -0700566 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
567 this.argument = argument;
568 if (phone != null) {
569 this.phone = phone;
570 }
571 this.workSource = workSource;
572 }
573
vagdeviaf9a5b92018-08-15 16:01:53 -0700574 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800575 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800576 if (subId != null) {
577 this.subId = subId;
578 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700579 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 }
582
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800583 private static final class IncomingThirdPartyCallArgs {
584 public final ComponentName component;
585 public final String callId;
586 public final String callerDisplayName;
587
588 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
589 String callerDisplayName) {
590 this.component = component;
591 this.callId = callId;
592 this.callerDisplayName = callerDisplayName;
593 }
594 }
595
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700596 /**
597 * A handler that processes messages on the main thread in the phone process. Since many
598 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
599 * inbound binder threads to the main thread in the phone process. The Binder thread
600 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
601 * on, which will be notified when the operation completes and will contain the result of the
602 * request.
603 *
604 * <p>If a MainThreadRequest object is provided in the msg.obj field,
605 * note that request.result must be set to something non-null for the calling thread to
606 * unblock.
607 */
608 private final class MainThreadHandler extends Handler {
609 @Override
610 public void handleMessage(Message msg) {
611 MainThreadRequest request;
612 Message onCompleted;
613 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000614 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800616 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617
618 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 case CMD_HANDLE_USSD_REQUEST: {
620 request = (MainThreadRequest) msg.obj;
621 final Phone phone = getPhoneFromRequest(request);
622 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800623 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700625
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 if (!isUssdApiAllowed(request.subId)) {
627 // Carrier does not support use of this API, return failure.
628 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
629 UssdResponse response = new UssdResponse(ussdRequest, null);
630 Bundle returnData = new Bundle();
631 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
632 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700633
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 request.result = true;
635 notifyRequester(request);
636 return;
637 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700638
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 try {
640 request.result = phone != null
641 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
642 } catch (CallStateException cse) {
643 request.result = false;
644 }
645 // Wake up the requesting thread
646 notifyRequester(request);
647 break;
pkanwar32d516d2016-10-14 19:37:38 -0700648 }
649
Yorke Lee716f67e2015-06-17 15:39:16 -0700650 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700651 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700652 final Phone phone = getPhoneFromRequest(request);
653 request.result = phone != null ?
654 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
655 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700656 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700658 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700660
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000664 uiccPort = getUiccPortFromRequest(request);
665 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700669 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800671 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000672 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800673 iccArgument.channel, iccArgument.cla, iccArgument.command,
674 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
675 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
682 if (ar.exception == null && ar.result != null) {
683 request.result = ar.result;
684 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800685 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 if (ar.result == null) {
687 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800688 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800690 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 } else {
692 loge("iccTransmitApduLogicalChannel: Unknown exception");
693 }
694 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 break;
697
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
699 request = (MainThreadRequest) msg.obj;
700 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000701 uiccPort = getUiccPortFromRequest(request);
702 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800704 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 } else {
707 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800708 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000709 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800710 iccArgument.cla, iccArgument.command, iccArgument.p1,
711 iccArgument.p2,
712 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700713 }
714 break;
715
716 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
717 ar = (AsyncResult) msg.obj;
718 request = (MainThreadRequest) ar.userObj;
719 if (ar.exception == null && ar.result != null) {
720 request.result = ar.result;
721 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800722 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 if (ar.result == null) {
724 loge("iccTransmitApduBasicChannel: Empty response");
725 } else if (ar.exception instanceof CommandException) {
726 loge("iccTransmitApduBasicChannel: CommandException: " +
727 ar.exception);
728 } else {
729 loge("iccTransmitApduBasicChannel: Unknown exception");
730 }
731 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 break;
734
735 case CMD_EXCHANGE_SIM_IO:
736 request = (MainThreadRequest) msg.obj;
737 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000738 uiccPort = getUiccPortFromRequest(request);
739 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800741 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 } else {
744 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
745 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000746 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700747 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
748 iccArgument.data, onCompleted);
749 }
750 break;
751
752 case EVENT_EXCHANGE_SIM_IO_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 if (ar.exception == null && ar.result != null) {
756 request.result = ar.result;
757 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800758 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700759 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700761 break;
762
Derek Tan4d5e5c12014-02-04 11:54:58 -0800763 case CMD_SEND_ENVELOPE:
764 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000765 uiccPort = getUiccPortFromRequest(request);
766 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700767 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800768 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700770 } else {
771 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800772 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700773 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800774 break;
775
776 case EVENT_SEND_ENVELOPE_DONE:
777 ar = (AsyncResult) msg.obj;
778 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700779 if (ar.exception == null && ar.result != null) {
780 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800781 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800782 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700783 if (ar.result == null) {
784 loge("sendEnvelopeWithStatus: Empty response");
785 } else if (ar.exception instanceof CommandException) {
786 loge("sendEnvelopeWithStatus: CommandException: " +
787 ar.exception);
788 } else {
789 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
790 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800791 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700792 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800793 break;
794
Shishir Agrawal566b7612013-10-28 14:41:00 -0700795 case CMD_OPEN_CHANNEL:
796 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000797 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800798 IccLogicalChannelRequest openChannelRequest =
799 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000800 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700801 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800802 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800803 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700804 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700805 } else {
806 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800807 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
808 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700809 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700810 break;
811
812 case EVENT_OPEN_CHANNEL_DONE:
813 ar = (AsyncResult) msg.obj;
814 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700815 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700816 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700817 int[] result = (int[]) ar.result;
818 int channelId = result[0];
819 byte[] selectResponse = null;
820 if (result.length > 1) {
821 selectResponse = new byte[result.length - 1];
822 for (int i = 1; i < result.length; ++i) {
823 selectResponse[i - 1] = (byte) result[i];
824 }
825 }
826 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800827 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800828
829 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700830 if (uiccPort == null) {
831 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
832 } else {
833 IccLogicalChannelRequest channelRequest =
834 (IccLogicalChannelRequest) request.argument;
835 channelRequest.channel = channelId;
836 uiccPort.onLogicalChannelOpened(channelRequest);
837 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700838 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 if (ar.result == null) {
840 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700842 if (ar.exception != null) {
843 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
844 }
845
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700846 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700847 if (ar.exception instanceof CommandException) {
848 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800849 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700850 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700851 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700852 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700853 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700854 }
855 }
856 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800857 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700858 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700859 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700860 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700861 break;
862
863 case CMD_CLOSE_CHANNEL:
864 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000865 uiccPort = getUiccPortFromRequest(request);
866 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700867 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800868 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800869 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800870 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700871 } else {
872 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000873 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700874 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700875 break;
876
877 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null) {
881 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800882 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700883 if (uiccPort == null) {
884 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
885 } else {
886 final int channelId = (Integer) request.argument;
887 uiccPort.onLogicalChannelClosed(channelId);
888 }
Chen Xu540470b2021-12-14 17:15:47 -0800889 } else {
890 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800891 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800892 if (ar.exception instanceof CommandException) {
893 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
894 CommandException.Error error =
895 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800896 if (error == CommandException.Error.INVALID_ARGUMENTS) {
897 // should only throw exceptions from the binder threads.
898 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800899 "iccCloseLogicalChannel: invalid argument ");
900 }
901 } else {
902 loge("iccCloseLogicalChannel: Unknown exception");
903 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800904 request.result = (exception != null) ? exception :
905 new IllegalStateException(
906 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800907 }
908 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800909 break;
910
911 case CMD_NV_READ_ITEM:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800914 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
915 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800916 break;
917
918 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800921 if (ar.exception == null && ar.result != null) {
922 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700923 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800924 request.result = "";
925 if (ar.result == null) {
926 loge("nvReadItem: Empty response");
927 } else if (ar.exception instanceof CommandException) {
928 loge("nvReadItem: CommandException: " +
929 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700930 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800931 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700932 }
933 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700934 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700935 break;
936
Jake Hambye994d462014-02-03 13:10:13 -0800937 case CMD_NV_WRITE_ITEM:
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
940 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800941 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700942 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800943 break;
944
945 case EVENT_NV_WRITE_ITEM_DONE:
946 handleNullReturnEvent(msg, "nvWriteItem");
947 break;
948
949 case CMD_NV_WRITE_CDMA_PRL:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800952 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800953 break;
954
955 case EVENT_NV_WRITE_CDMA_PRL_DONE:
956 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
957 break;
958
chen xu6dac5ab2018-10-26 17:39:23 -0700959 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800960 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700961 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800962 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800963 break;
964
chen xu6dac5ab2018-10-26 17:39:23 -0700965 case EVENT_RESET_MODEM_CONFIG_DONE:
966 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800967 break;
968
Sooraj Sasindran37444802020-08-11 10:40:43 -0700969 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
972 request);
973 Phone phone = getPhoneFromRequest(request);
974 if (phone != null) {
975 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
976 } else {
977 loge("isNRDualConnectivityEnabled: No phone object");
978 request.result = false;
979 notifyRequester(request);
980 }
981 break;
982 }
983
984 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception == null && ar.result != null) {
988 request.result = ar.result;
989 } else {
990 // request.result must be set to something non-null
991 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700992 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700993 request.result = ar.result;
994 } else {
995 request.result = false;
996 }
997 if (ar.result == null) {
998 loge("isNRDualConnectivityEnabled: Empty response");
999 } else if (ar.exception instanceof CommandException) {
1000 loge("isNRDualConnectivityEnabled: CommandException: "
1001 + ar.exception);
1002 } else {
1003 loge("isNRDualConnectivityEnabled: Unknown exception");
1004 }
1005 }
1006 notifyRequester(request);
1007 break;
1008
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001009 case CMD_IS_VONR_ENABLED: {
1010 request = (MainThreadRequest) msg.obj;
1011 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1012 request);
1013 Phone phone = getPhoneFromRequest(request);
1014 if (phone != null) {
1015 phone.isVoNrEnabled(onCompleted, request.workSource);
1016 } else {
1017 loge("isVoNrEnabled: No phone object");
1018 request.result = false;
1019 notifyRequester(request);
1020 }
1021 break;
1022 }
1023
1024 case EVENT_IS_VONR_ENABLED_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception == null && ar.result != null) {
1028 request.result = ar.result;
1029 } else {
1030 // request.result must be set to something non-null
1031 // for the calling thread to unblock
1032 if (ar.result != null) {
1033 request.result = ar.result;
1034 } else {
1035 request.result = false;
1036 }
1037 if (ar.result == null) {
1038 loge("isVoNrEnabled: Empty response");
1039 } else if (ar.exception instanceof CommandException) {
1040 loge("isVoNrEnabled: CommandException: "
1041 + ar.exception);
1042 } else {
1043 loge("isVoNrEnabled: Unknown exception");
1044 }
1045 }
1046 notifyRequester(request);
1047 break;
1048
Sooraj Sasindran37444802020-08-11 10:40:43 -07001049 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1052 Phone phone = getPhoneFromRequest(request);
1053 if (phone != null) {
1054 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1055 request.workSource);
1056 } else {
1057 loge("enableNrDualConnectivity: No phone object");
1058 request.result =
1059 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1060 notifyRequester(request);
1061 }
1062 break;
1063 }
1064
1065 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 if (ar.exception == null) {
1069 request.result =
1070 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1071 } else {
1072 request.result =
1073 TelephonyManager
1074 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1075 if (ar.exception instanceof CommandException) {
1076 CommandException.Error error =
1077 ((CommandException) (ar.exception)).getCommandError();
1078 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1079 request.result =
1080 TelephonyManager
1081 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001082 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1083 request.result =
1084 TelephonyManager
1085 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001086 }
1087 loge("enableNrDualConnectivity" + ": CommandException: "
1088 + ar.exception);
1089 } else {
1090 loge("enableNrDualConnectivity" + ": Unknown exception");
1091 }
1092 }
1093 notifyRequester(request);
1094 break;
1095 }
1096
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001097 case CMD_ENABLE_VONR: {
1098 request = (MainThreadRequest) msg.obj;
1099 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1100 Phone phone = getPhoneFromRequest(request);
1101 if (phone != null) {
1102 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1103 request.workSource);
1104 } else {
1105 loge("setVoNrEnabled: No phone object");
1106 request.result =
1107 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1108 notifyRequester(request);
1109 }
1110 break;
1111 }
1112
1113 case EVENT_ENABLE_VONR_DONE: {
1114 ar = (AsyncResult) msg.obj;
1115 request = (MainThreadRequest) ar.userObj;
1116 if (ar.exception == null) {
1117 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1118 } else {
1119 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1120 if (ar.exception instanceof CommandException) {
1121 CommandException.Error error =
1122 ((CommandException) (ar.exception)).getCommandError();
1123 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1124 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1125 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1126 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1127 } else {
1128 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1129 }
1130 loge("setVoNrEnabled" + ": CommandException: "
1131 + ar.exception);
1132 } else {
1133 loge("setVoNrEnabled" + ": Unknown exception");
1134 }
1135 }
1136 notifyRequester(request);
1137 break;
1138 }
1139
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1143 request);
1144 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001145 break;
1146
SongFerngWang3ef3e072020-12-21 16:41:52 +08001147 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001148 ar = (AsyncResult) msg.obj;
1149 request = (MainThreadRequest) ar.userObj;
1150 if (ar.exception == null && ar.result != null) {
1151 request.result = ar.result; // Integer
1152 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301153 // request.result must be set to something non-null
1154 // for the calling thread to unblock
1155 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001157 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001159 loge("getAllowedNetworkTypesBitmask: CommandException: "
1160 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001162 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001163 }
1164 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001165 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001166 break;
1167
SongFerngWang3ef3e072020-12-21 16:41:52 +08001168 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001169 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001170 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1171 request);
1172 Pair<Integer, Long> reasonWithNetworkTypes =
1173 (Pair<Integer, Long>) request.argument;
1174 getPhoneFromRequest(request).setAllowedNetworkTypes(
1175 reasonWithNetworkTypes.first,
1176 reasonWithNetworkTypes.second,
1177 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001178 break;
1179
SongFerngWang3ef3e072020-12-21 16:41:52 +08001180 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1181 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001182 break;
1183
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001184 case CMD_SET_VOICEMAIL_NUMBER:
1185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1187 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001188 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1189 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001190 break;
1191
1192 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1193 handleNullReturnEvent(msg, "setVoicemailNumber");
1194 break;
1195
Stuart Scott54788802015-03-30 13:18:01 -07001196 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1197 request = (MainThreadRequest) msg.obj;
1198 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1199 request);
1200 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1201 break;
1202
1203 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1204 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1205 break;
1206
Shishir Agrawal302c8692015-06-19 13:49:39 -07001207 case CMD_PERFORM_NETWORK_SCAN:
1208 request = (MainThreadRequest) msg.obj;
1209 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1210 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1211 break;
1212
Hall Liu27d24262020-09-18 19:04:59 -07001213 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001214 request = (MainThreadRequest) msg.obj;
1215 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001216 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1217 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1218 request.argument;
1219 int callForwardingReason = args.first;
1220 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001221 break;
Hall Liu27d24262020-09-18 19:04:59 -07001222 }
1223 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001224 ar = (AsyncResult) msg.obj;
1225 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001226 TelephonyManager.CallForwardingInfoCallback callback =
1227 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1228 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001229 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001230 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001231 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1232 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1233 // Service Class is a bit mask per 3gpp 27.007. Search for
1234 // any service for voice call.
1235 if ((callForwardInfo.serviceClass
1236 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001237 callForwardingInfo = new CallForwardingInfo(
1238 callForwardInfo.status
1239 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001240 callForwardInfo.reason,
1241 callForwardInfo.number,
1242 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001243 break;
1244 }
1245 }
1246 // Didn't find a call forward info for voice call.
1247 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001248 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1249 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001250 }
Hall Liu27d24262020-09-18 19:04:59 -07001251 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001252 } else {
1253 if (ar.result == null) {
1254 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1255 }
1256 if (ar.exception != null) {
1257 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1258 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001259 int errorCode = TelephonyManager
1260 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001261 if (ar.exception instanceof CommandException) {
1262 CommandException.Error error =
1263 ((CommandException) (ar.exception)).getCommandError();
1264 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001265 errorCode = TelephonyManager
1266 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001267 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001268 errorCode = TelephonyManager
1269 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001270 }
1271 }
Hall Liu27d24262020-09-18 19:04:59 -07001272 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001273 }
Shuo Qian4a594052020-01-23 11:59:30 -08001274 break;
Hall Liu27d24262020-09-18 19:04:59 -07001275 }
Shuo Qian4a594052020-01-23 11:59:30 -08001276
Hall Liu27d24262020-09-18 19:04:59 -07001277 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001278 request = (MainThreadRequest) msg.obj;
1279 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001280 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001281 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001282 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1283 request.argument).first;
1284 request.phone.setCallForwardingOption(
1285 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001286 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001287 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001288 callForwardingInfoToSet.getReason(),
1289 callForwardingInfoToSet.getNumber(),
1290 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1291 break;
Hall Liu27d24262020-09-18 19:04:59 -07001292 }
Shuo Qian4a594052020-01-23 11:59:30 -08001293
Hall Liu27d24262020-09-18 19:04:59 -07001294 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001295 ar = (AsyncResult) msg.obj;
1296 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001297 Consumer<Integer> callback =
1298 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1299 request.argument).second;
1300 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001301 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001302 int errorCode = TelephonyManager.CallForwardingInfoCallback
1303 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001304 if (ar.exception instanceof CommandException) {
1305 CommandException.Error error =
1306 ((CommandException) (ar.exception)).getCommandError();
1307 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001308 errorCode = TelephonyManager.CallForwardingInfoCallback
1309 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001310 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001311 errorCode = TelephonyManager.CallForwardingInfoCallback
1312 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001313 }
1314 }
1315 callback.accept(errorCode);
1316 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001317 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001318 }
Shuo Qian4a594052020-01-23 11:59:30 -08001319 break;
Hall Liu27d24262020-09-18 19:04:59 -07001320 }
Shuo Qian4a594052020-01-23 11:59:30 -08001321
Hall Liu27d24262020-09-18 19:04:59 -07001322 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001323 request = (MainThreadRequest) msg.obj;
1324 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1325 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1326 break;
Hall Liu27d24262020-09-18 19:04:59 -07001327 }
Shuo Qian4a594052020-01-23 11:59:30 -08001328
Hall Liu27d24262020-09-18 19:04:59 -07001329 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001332 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001334 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001335 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001336 // Service Class is a bit mask per 3gpp 27.007.
1337 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001338 if (callForwardResults.length > 1
1339 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001340 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001341 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001342 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1343 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001344 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001345 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001346 }
1347 } else {
1348 if (ar.result == null) {
1349 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1350 }
1351 if (ar.exception != null) {
1352 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1353 }
1354 if (ar.exception instanceof CommandException) {
1355 CommandException.Error error =
1356 ((CommandException) (ar.exception)).getCommandError();
1357 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001358 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001359 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001360 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1361 callWaitingStatus =
1362 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001363 }
1364 }
1365 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001366 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001367 break;
Hall Liu27d24262020-09-18 19:04:59 -07001368 }
Shuo Qian4a594052020-01-23 11:59:30 -08001369
Hall Liu27d24262020-09-18 19:04:59 -07001370 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001371 request = (MainThreadRequest) msg.obj;
1372 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001373 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1374 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001375 break;
Hall Liu27d24262020-09-18 19:04:59 -07001376 }
Shuo Qian4a594052020-01-23 11:59:30 -08001377
Hall Liu27d24262020-09-18 19:04:59 -07001378 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001379 ar = (AsyncResult) msg.obj;
1380 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001381 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1382 Consumer<Integer> callback =
1383 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1384 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001385 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001386 if (ar.exception instanceof CommandException) {
1387 CommandException.Error error =
1388 ((CommandException) (ar.exception)).getCommandError();
1389 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1390 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001391 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1392 callback.accept(
1393 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001394 } else {
1395 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1396 }
1397 } else {
1398 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1399 }
1400 } else {
1401 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1402 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001403 }
Shuo Qian4a594052020-01-23 11:59:30 -08001404 break;
Hall Liu27d24262020-09-18 19:04:59 -07001405 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001406 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
1409 CellNetworkScanResult cellScanResult;
1410 if (ar.exception == null && ar.result != null) {
1411 cellScanResult = new CellNetworkScanResult(
1412 CellNetworkScanResult.STATUS_SUCCESS,
1413 (List<OperatorInfo>) ar.result);
1414 } else {
1415 if (ar.result == null) {
1416 loge("getCellNetworkScanResults: Empty response");
1417 }
1418 if (ar.exception != null) {
1419 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1420 }
1421 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1422 if (ar.exception instanceof CommandException) {
1423 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001424 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001425 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1426 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1427 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1428 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1429 }
1430 }
1431 cellScanResult = new CellNetworkScanResult(errorCode, null);
1432 }
1433 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001434 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001435 break;
1436
1437 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1438 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001439 ManualNetworkSelectionArgument selArg =
1440 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001441 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1442 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001443 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1444 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001445 break;
1446
1447 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null) {
1451 request.result = true;
1452 } else {
1453 request.result = false;
1454 loge("setNetworkSelectionModeManual " + ar.exception);
1455 }
1456 notifyRequester(request);
1457 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001458 break;
1459
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001460 case CMD_GET_MODEM_ACTIVITY_INFO:
1461 request = (MainThreadRequest) msg.obj;
1462 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001463 if (defaultPhone != null) {
1464 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 } else {
1466 ResultReceiver result = (ResultReceiver) request.argument;
1467 Bundle bundle = new Bundle();
1468 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001469 new ModemActivityInfo(0, 0, 0,
1470 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001471 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001472 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001473 break;
1474
Hall Liud0f208c2020-10-14 16:54:44 -07001475 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001476 ar = (AsyncResult) msg.obj;
1477 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001478 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001479 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001480 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001481 if (mLastModemActivityInfo == null) {
1482 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1483 mLastModemActivitySpecificInfo[0] =
1484 new ActivityStatsTechSpecificInfo(
1485 0,
1486 0,
1487 new int[ModemActivityInfo.getNumTxPowerLevels()],
1488 0);
1489 mLastModemActivityInfo =
1490 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1491 }
1492
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001493 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001494 // Update the last modem activity info and the result of the request.
1495 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1496 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001497 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001498 } else {
1499 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001500 }
Kai Shi917fdc62022-11-28 14:01:02 -08001501 // This is needed to decouple ret from mLastModemActivityInfo
1502 // We don't want to return mLastModemActivityInfo which is updated
1503 // inside mergeModemActivityInfo()
1504 ret = new ModemActivityInfo(
1505 mLastModemActivityInfo.getTimestampMillis(),
1506 mLastModemActivityInfo.getSleepTimeMillis(),
1507 mLastModemActivityInfo.getIdleTimeMillis(),
1508 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001509
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 } else {
1511 if (ar.result == null) {
1512 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001513 error = TelephonyManager.ModemActivityInfoException
1514 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001515 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001516 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001517 error = TelephonyManager.ModemActivityInfoException
1518 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001519 } else {
1520 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001521 error = TelephonyManager.ModemActivityInfoException
1522 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001523 }
1524 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001525 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001526 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001527 bundle.putParcelable(
1528 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001529 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001530 } else {
1531 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1532 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001533 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001534 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001535 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001536 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001537
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001538 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001539 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001540 CarrierRestrictionRules argument =
1541 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001542 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001543 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001545 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001546
1547 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 if (ar.exception == null && ar.result != null) {
1551 request.result = ar.result;
1552 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001553 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1554 if (ar.exception instanceof CommandException) {
1555 loge("setAllowedCarriers: CommandException: " + ar.exception);
1556 CommandException.Error error =
1557 ((CommandException) (ar.exception)).getCommandError();
1558 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1559 request.result =
1560 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1561 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001562 } else {
1563 loge("setAllowedCarriers: Unknown exception");
1564 }
1565 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001566 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001567 break;
1568
1569 case CMD_GET_ALLOWED_CARRIERS:
1570 request = (MainThreadRequest) msg.obj;
1571 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001572 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001573 break;
1574
1575 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1576 ar = (AsyncResult) msg.obj;
1577 request = (MainThreadRequest) ar.userObj;
1578 if (ar.exception == null && ar.result != null) {
1579 request.result = ar.result;
1580 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001581 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001582 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001583 if (ar.result == null) {
1584 loge("getAllowedCarriers: Empty response");
1585 } else if (ar.exception instanceof CommandException) {
1586 loge("getAllowedCarriers: CommandException: " +
1587 ar.exception);
1588 } else {
1589 loge("getAllowedCarriers: Unknown exception");
1590 }
1591 }
arunvoddud7401012022-12-15 16:08:12 +00001592 if (request.argument != null) {
1593 // This is for the implementation of carrierRestrictionStatus.
1594 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1595 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001596 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001597 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1598 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1599 CarrierRestrictionRules carrierRestrictionRules =
1600 (CarrierRestrictionRules) ar.result;
1601 int carrierId = -1;
1602 try {
1603 CarrierIdentifier carrierIdentifier =
1604 carrierRestrictionRules.getAllowedCarriers().get(0);
1605 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1606 carrierIdentifier);
1607 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1608 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1609 }
1610 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001611 int restrictedStatus =
1612 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1613 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1614 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001615 lockStatus = TelephonyManager
1616 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001617 }
1618 } else {
1619 Rlog.e(LOG_TAG,
1620 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1621 }
1622 callback.accept(lockStatus);
1623 } else {
1624 // This is for the implementation of getAllowedCarriers.
1625 notifyRequester(request);
1626 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001627 break;
1628
Nathan Haroldb3014052017-01-25 15:57:32 -08001629 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1630 ar = (AsyncResult) msg.obj;
1631 request = (MainThreadRequest) ar.userObj;
1632 if (ar.exception == null && ar.result != null) {
1633 request.result = ar.result;
1634 } else {
1635 request.result = new IllegalArgumentException(
1636 "Failed to retrieve Forbidden Plmns");
1637 if (ar.result == null) {
1638 loge("getForbiddenPlmns: Empty response");
1639 } else {
1640 loge("getForbiddenPlmns: Unknown exception");
1641 }
1642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001643 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001644 break;
1645
1646 case CMD_GET_FORBIDDEN_PLMNS:
1647 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001648 uiccPort = getUiccPortFromRequest(request);
1649 if (uiccPort == null) {
1650 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001651 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001652 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001653 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001654 break;
1655 }
1656 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001657 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001658 if (uiccApp == null) {
1659 loge("getForbiddenPlmns() no app with specified type -- "
1660 + appType);
1661 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001662 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001663 break;
1664 } else {
1665 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1666 + " specified type -- " + appType);
1667 }
1668 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1669 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001670 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001671 break;
1672
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001673 case CMD_SWITCH_SLOTS:
1674 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001675 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001676 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001677 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001678 break;
1679
1680 case EVENT_SWITCH_SLOTS_DONE:
1681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001684 notifyRequester(request);
1685 break;
1686 case CMD_GET_NETWORK_SELECTION_MODE:
1687 request = (MainThreadRequest) msg.obj;
1688 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1689 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1690 break;
1691
1692 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1693 ar = (AsyncResult) msg.obj;
1694 request = (MainThreadRequest) ar.userObj;
1695 if (ar.exception != null) {
1696 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1697 } else {
1698 int mode = ((int[]) ar.result)[0];
1699 if (mode == 0) {
1700 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1701 } else {
1702 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1703 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001705 notifyRequester(request);
1706 break;
1707 case CMD_GET_CDMA_ROAMING_MODE:
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1710 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1711 break;
1712 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 if (ar.exception != null) {
1716 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1717 } else {
1718 request.result = ((int[]) ar.result)[0];
1719 }
1720 notifyRequester(request);
1721 break;
1722 case CMD_SET_CDMA_ROAMING_MODE:
1723 request = (MainThreadRequest) msg.obj;
1724 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1725 int mode = (int) request.argument;
1726 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1727 break;
1728 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731 request.result = ar.exception == null;
1732 notifyRequester(request);
1733 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001734 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1735 request = (MainThreadRequest) msg.obj;
1736 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1737 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1738 break;
1739 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1740 ar = (AsyncResult) msg.obj;
1741 request = (MainThreadRequest) ar.userObj;
1742 if (ar.exception != null) {
1743 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1744 } else {
1745 request.result = ((int[]) ar.result)[0];
1746 }
1747 notifyRequester(request);
1748 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001749 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1750 request = (MainThreadRequest) msg.obj;
1751 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1752 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001753 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1754 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001755 break;
1756 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
1759 request.result = ar.exception == null;
1760 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001761 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001762 case CMD_GET_ALL_CELL_INFO:
1763 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001764 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001765 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001766 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001767 case EVENT_GET_ALL_CELL_INFO_DONE:
1768 ar = (AsyncResult) msg.obj;
1769 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001770 // If a timeout occurs, the response will be null
1771 request.result = (ar.exception == null && ar.result != null)
1772 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001773 synchronized (request) {
1774 request.notifyAll();
1775 }
1776 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001777 case CMD_REQUEST_CELL_INFO_UPDATE:
1778 request = (MainThreadRequest) msg.obj;
1779 request.phone.requestCellInfoUpdate(request.workSource,
1780 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1781 break;
1782 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1783 ar = (AsyncResult) msg.obj;
1784 request = (MainThreadRequest) ar.userObj;
1785 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1786 try {
1787 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001788 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001789 cb.onError(
1790 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1791 ar.exception.getClass().getName(),
1792 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001793 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001794 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001795 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001796 } else {
1797 // use the result as returned
1798 cb.onCellInfo((List<CellInfo>) ar.result);
1799 }
1800 } catch (RemoteException re) {
1801 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1802 }
1803 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001804 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 request = (MainThreadRequest) msg.obj;
1806 WorkSource ws = (WorkSource) request.argument;
1807 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001808 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001809 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001810 }
1811 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001812 ar = (AsyncResult) msg.obj;
1813 request = (MainThreadRequest) ar.userObj;
1814 if (ar.exception == null) {
1815 request.result = ar.result;
1816 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001817 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001818 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001819 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001820 }
1821
1822 synchronized (request) {
1823 request.notifyAll();
1824 }
1825 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001826 }
chen xu6dac5ab2018-10-26 17:39:23 -07001827 case CMD_MODEM_REBOOT:
1828 request = (MainThreadRequest) msg.obj;
1829 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001830 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001831 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001832 case EVENT_CMD_MODEM_REBOOT_DONE:
1833 handleNullReturnEvent(msg, "rebootModem");
1834 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001835 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001836 request = (MainThreadRequest) msg.obj;
1837 boolean enable = (boolean) request.argument;
1838 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001839 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001840 PhoneConfigurationManager.getInstance()
1841 .enablePhone(request.phone, enable, onCompleted);
1842 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001843 }
Michele Berionne5e411512020-11-13 02:36:59 +00001844 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001845 ar = (AsyncResult) msg.obj;
1846 request = (MainThreadRequest) ar.userObj;
1847 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001848 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001849 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001850 if ((boolean) request.result) {
1851 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1852 updateModemStateMetrics();
1853 } else {
1854 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1855 + ar.exception);
1856 }
1857 notifyRequester(request);
1858 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001859 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001860 case CMD_GET_MODEM_STATUS:
1861 request = (MainThreadRequest) msg.obj;
1862 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1863 PhoneConfigurationManager.getInstance()
1864 .getPhoneStatusFromModem(request.phone, onCompleted);
1865 break;
1866 case EVENT_GET_MODEM_STATUS_DONE:
1867 ar = (AsyncResult) msg.obj;
1868 request = (MainThreadRequest) ar.userObj;
1869 int id = request.phone.getPhoneId();
1870 if (ar.exception == null && ar.result != null) {
1871 request.result = ar.result;
1872 //update the cache as modem status has changed
1873 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1874 (boolean) request.result);
1875 } else {
1876 // Return true if modem status cannot be retrieved. For most cases,
1877 // modem status is on. And for older version modems, GET_MODEM_STATUS
1878 // and disable modem are not supported. Modem is always on.
1879 // TODO: this should be fixed in R to support a third
1880 // status UNKNOWN b/131631629
1881 request.result = true;
1882 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1883 + ar.exception);
1884 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001885 notifyRequester(request);
1886 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001887 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1888 request = (MainThreadRequest) msg.obj;
1889 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1890 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1891 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1892 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1893 break;
1894 }
1895 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1896 ar = (AsyncResult) msg.obj;
1897 request = (MainThreadRequest) ar.userObj;
1898 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1899 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1900 args.second.accept(ar.exception == null);
1901 notifyRequester(request);
1902 break;
1903 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001904 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1905 request = (MainThreadRequest) msg.obj;
1906 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1907 Phone phone = getPhoneFromRequest(request);
1908 if (phone != null) {
1909 phone.getSystemSelectionChannels(onCompleted);
1910 } else {
1911 loge("getSystemSelectionChannels: No phone object");
1912 request.result = new ArrayList<RadioAccessSpecifier>();
1913 notifyRequester(request);
1914 }
1915 break;
1916 }
1917 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1918 ar = (AsyncResult) msg.obj;
1919 request = (MainThreadRequest) ar.userObj;
1920 if (ar.exception == null && ar.result != null) {
1921 request.result = ar.result;
1922 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001923 request.result = new IllegalStateException(
1924 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001925 if (ar.result == null) {
1926 loge("getSystemSelectionChannels: Empty response");
1927 } else {
1928 loge("getSystemSelectionChannels: Unknown exception");
1929 }
1930 }
1931 notifyRequester(request);
1932 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001933 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1934 ar = (AsyncResult) msg.obj;
1935 request = (MainThreadRequest) ar.userObj;
1936 if (ar.exception == null && ar.result != null) {
1937 request.result = ar.result;
1938 } else {
1939 request.result = -1;
1940 loge("Failed to set Forbidden Plmns");
1941 if (ar.result == null) {
1942 loge("setForbidenPlmns: Empty response");
1943 } else if (ar.exception != null) {
1944 loge("setForbiddenPlmns: Exception: " + ar.exception);
1945 request.result = -1;
1946 } else {
1947 loge("setForbiddenPlmns: Unknown exception");
1948 }
1949 }
1950 notifyRequester(request);
1951 break;
1952 case CMD_SET_FORBIDDEN_PLMNS:
1953 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001954 uiccPort = getUiccPortFromRequest(request);
1955 if (uiccPort == null) {
1956 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001957 request.result = -1;
1958 notifyRequester(request);
1959 break;
1960 }
1961 Pair<Integer, List<String>> setFplmnsArgs =
1962 (Pair<Integer, List<String>>) request.argument;
1963 appType = setFplmnsArgs.first;
1964 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001965 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001966 if (uiccApp == null) {
1967 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1968 request.result = -1;
1969 loge("Failed to get UICC App");
1970 notifyRequester(request);
1971 } else {
1972 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1973 ((SIMRecords) uiccApp.getIccRecords())
1974 .setForbiddenPlmns(onCompleted, fplmns);
1975 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001976 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001977 case CMD_ERASE_MODEM_CONFIG:
1978 request = (MainThreadRequest) msg.obj;
1979 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1980 defaultPhone.eraseModemConfig(onCompleted);
1981 break;
1982 case EVENT_ERASE_MODEM_CONFIG_DONE:
1983 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001984 break;
zoey chene02881a2019-12-30 16:11:23 +08001985
Kai Shif70f46f2021-03-03 13:59:46 -08001986 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1987 request = (MainThreadRequest) msg.obj;
1988 request.result = defaultPhone.eraseDataInSharedPreferences();
1989 notifyRequester(request);
1990 break;
1991
zoey chene02881a2019-12-30 16:11:23 +08001992 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1993 request = (MainThreadRequest) msg.obj;
1994 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1995 Pair<String, String> changed = (Pair<String, String>) request.argument;
1996 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1997 changed.first, changed.second, onCompleted);
1998 break;
1999 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2000 ar = (AsyncResult) msg.obj;
2001 request = (MainThreadRequest) ar.userObj;
2002 if (ar.exception == null) {
2003 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002004 // If the operation is successful, update the PIN storage
2005 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2006 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002007 UiccController.getInstance().getPinStorage()
2008 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002009 } else {
2010 request.result = msg.arg1;
2011 }
2012 notifyRequester(request);
2013 break;
2014
Michele Berionne5e411512020-11-13 02:36:59 +00002015 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002016 request = (MainThreadRequest) msg.obj;
2017 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2018 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2019 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2020 enabled.first, enabled.second, onCompleted);
2021 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002022 }
zoey chene02881a2019-12-30 16:11:23 +08002023 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2024 ar = (AsyncResult) msg.obj;
2025 request = (MainThreadRequest) ar.userObj;
2026 if (ar.exception == null) {
2027 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002028 // If the operation is successful, update the PIN storage
2029 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2030 int phoneId = getPhoneFromRequest(request).getPhoneId();
2031 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002032 UiccController.getInstance().getPinStorage()
2033 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002034 } else {
2035 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2036 }
zoey chene02881a2019-12-30 16:11:23 +08002037 } else {
2038 request.result = msg.arg1;
2039 }
Michele Berionne5e411512020-11-13 02:36:59 +00002040
2041
zoey chene02881a2019-12-30 16:11:23 +08002042 notifyRequester(request);
2043 break;
2044
Peter Wangdafb9ac2020-01-15 14:13:38 -08002045 case MSG_NOTIFY_USER_ACTIVITY:
2046 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002047 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002048 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2049 getDefaultPhone().getContext().sendBroadcastAsUser(
2050 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2051 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002052
2053 case CMD_SET_DATA_THROTTLING: {
2054 request = (MainThreadRequest) msg.obj;
2055 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2056 DataThrottlingRequest dataThrottlingRequest =
2057 (DataThrottlingRequest) request.argument;
2058 Phone phone = getPhoneFromRequest(request);
2059 if (phone != null) {
2060 phone.setDataThrottling(onCompleted,
2061 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2062 dataThrottlingRequest.getCompletionDurationMillis());
2063 } else {
2064 loge("setDataThrottling: No phone object");
2065 request.result =
2066 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2067 notifyRequester(request);
2068 }
2069
2070 break;
2071 }
2072 case EVENT_SET_DATA_THROTTLING_DONE:
2073 ar = (AsyncResult) msg.obj;
2074 request = (MainThreadRequest) ar.userObj;
2075
2076 if (ar.exception == null) {
2077 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2078 } else if (ar.exception instanceof CommandException) {
2079 loge("setDataThrottling: CommandException: " + ar.exception);
2080 CommandException.Error error =
2081 ((CommandException) (ar.exception)).getCommandError();
2082
2083 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2084 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002085 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002086 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2087 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002088 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2089 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002090 } else {
2091 request.result =
2092 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2093 }
2094 } else {
2095 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2096 }
2097 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2098 notifyRequester(request);
2099 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002100
2101 case CMD_SET_SIM_POWER: {
2102 request = (MainThreadRequest) msg.obj;
2103 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2104 request = (MainThreadRequest) msg.obj;
2105 int stateToSet =
2106 ((Pair<Integer, IIntegerConsumer>)
2107 request.argument).first;
2108 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2109 break;
2110 }
2111 case EVENT_SET_SIM_POWER_DONE: {
2112 ar = (AsyncResult) msg.obj;
2113 request = (MainThreadRequest) ar.userObj;
2114 IIntegerConsumer callback =
2115 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2116 if (ar.exception != null) {
2117 loge("setSimPower exception: " + ar.exception);
2118 int errorCode = TelephonyManager.CallForwardingInfoCallback
2119 .RESULT_ERROR_UNKNOWN;
2120 if (ar.exception instanceof CommandException) {
2121 CommandException.Error error =
2122 ((CommandException) (ar.exception)).getCommandError();
2123 if (error == CommandException.Error.SIM_ERR) {
2124 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2125 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2126 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2127 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2128 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2129 } else {
2130 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2131 }
2132 }
2133 try {
2134 callback.accept(errorCode);
2135 } catch (RemoteException e) {
2136 // Ignore if the remote process is no longer available to call back.
2137 Log.w(LOG_TAG, "setSimPower: callback not available.");
2138 }
2139 } else {
2140 try {
2141 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2142 } catch (RemoteException e) {
2143 // Ignore if the remote process is no longer available to call back.
2144 Log.w(LOG_TAG, "setSimPower: callback not available.");
2145 }
2146 }
2147 break;
2148 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002149 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2150 request = (MainThreadRequest) msg.obj;
2151
2152 final Phone phone = getPhoneFromRequest(request);
2153 if (phone == null || phone.getServiceStateTracker() == null) {
2154 request.result = new IllegalStateException("Phone or SST is null");
2155 notifyRequester(request);
2156 break;
2157 }
2158
2159 Pair<Integer, SignalStrengthUpdateRequest> pair =
2160 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2161 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2162 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002163 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002164 request.subId, pair.first /*callingUid*/,
2165 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002166 break;
2167 }
2168 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2169 ar = (AsyncResult) msg.obj;
2170 request = (MainThreadRequest) ar.userObj;
2171 // request.result will be the exception of ar if present, true otherwise.
2172 // Be cautious not to leave result null which will wait() forever
2173 request.result = ar.exception != null ? ar.exception : true;
2174 notifyRequester(request);
2175 break;
2176 }
2177 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2178 request = (MainThreadRequest) msg.obj;
2179
2180 Phone phone = getPhoneFromRequest(request);
2181 if (phone == null || phone.getServiceStateTracker() == null) {
2182 request.result = new IllegalStateException("Phone or SST is null");
2183 notifyRequester(request);
2184 break;
2185 }
2186
2187 Pair<Integer, SignalStrengthUpdateRequest> pair =
2188 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2189 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2190 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002191 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002192 request.subId, pair.first /*callingUid*/,
2193 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002194 break;
2195 }
2196 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2197 ar = (AsyncResult) msg.obj;
2198 request = (MainThreadRequest) ar.userObj;
2199 request.result = ar.exception != null ? ar.exception : true;
2200 notifyRequester(request);
2201 break;
2202 }
Jordan Liu109698e2020-11-24 14:50:34 -08002203
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002204 case CMD_GET_SLICING_CONFIG: {
2205 request = (MainThreadRequest) msg.obj;
2206 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2207 request.phone.getSlicingConfig(onCompleted);
2208 break;
2209 }
2210 case EVENT_GET_SLICING_CONFIG_DONE: {
2211 ar = (AsyncResult) msg.obj;
2212 request = (MainThreadRequest) ar.userObj;
2213 ResultReceiver result = (ResultReceiver) request.argument;
2214
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002215 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002216 Bundle bundle = new Bundle();
2217 int resultCode = 0;
2218 if (ar.exception != null) {
2219 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2220 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002221 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002222 } else if (ar.result == null) {
2223 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002224 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002225 } else {
2226 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002227 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2228 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002229 }
2230
2231 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002232 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002233 }
2234 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2235 result.send(resultCode, bundle);
2236 notifyRequester(request);
2237 break;
2238 }
2239
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241 request = (MainThreadRequest) msg.obj;
2242 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 PurchasePremiumCapabilityArgument arg =
2244 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002245 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2246 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002247 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002248 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002249
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251 ar = (AsyncResult) msg.obj;
2252 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002253 PurchasePremiumCapabilityArgument arg =
2254 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002255 try {
2256 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002257 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002258 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002259 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002260 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002261 + TelephonyManager.convertPurchaseResultToString(result));
2262 } catch (RemoteException e) {
2263 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002264 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002265 + " failed: " + e;
2266 if (DBG) log(logStr);
2267 AnomalyReporter.reportAnomaly(
2268 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2269 }
2270 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002271 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002272
Michele Berionne5e411512020-11-13 02:36:59 +00002273 case CMD_PREPARE_UNATTENDED_REBOOT:
2274 request = (MainThreadRequest) msg.obj;
2275 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002276 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002277 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002278 notifyRequester(request);
2279 break;
2280
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 default:
2282 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2283 break;
2284 }
2285 }
Jake Hambye994d462014-02-03 13:10:13 -08002286
Pengquan Menga1bb6272018-09-06 09:59:22 -07002287 private void notifyRequester(MainThreadRequest request) {
2288 synchronized (request) {
2289 request.notifyAll();
2290 }
2291 }
2292
Jake Hambye994d462014-02-03 13:10:13 -08002293 private void handleNullReturnEvent(Message msg, String command) {
2294 AsyncResult ar = (AsyncResult) msg.obj;
2295 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2296 if (ar.exception == null) {
2297 request.result = true;
2298 } else {
2299 request.result = false;
2300 if (ar.exception instanceof CommandException) {
2301 loge(command + ": CommandException: " + ar.exception);
2302 } else {
2303 loge(command + ": Unknown exception");
2304 }
2305 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002306 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 }
2309
2310 /**
2311 * Posts the specified command to be executed on the main thread,
2312 * waits for the request to complete, and returns the result.
2313 * @see #sendRequestAsync
2314 */
2315 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002316 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2317 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002318 }
2319
2320 /**
2321 * Posts the specified command to be executed on the main thread,
2322 * waits for the request to complete, and returns the result.
2323 * @see #sendRequestAsync
2324 */
2325 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2326 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002327 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002328 }
2329
2330 /**
2331 * Posts the specified command to be executed on the main thread,
2332 * waits for the request to complete, and returns the result.
2333 * @see #sendRequestAsync
2334 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002335 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002336 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2337 }
2338
2339 /**
2340 * Posts the specified command to be executed on the main thread,
2341 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2342 * if not timeout or null otherwise.
2343 * @see #sendRequestAsync
2344 */
2345 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2346 long timeoutInMs) {
2347 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002348 }
2349
2350 /**
2351 * Posts the specified command to be executed on the main thread,
2352 * waits for the request to complete, and returns the result.
2353 * @see #sendRequestAsync
2354 */
Nathan Harold92bed182018-10-12 18:16:49 -07002355 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002356 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002357 }
2358
2359 /**
2360 * Posts the specified command to be executed on the main thread,
2361 * waits for the request to complete, and returns the result.
2362 * @see #sendRequestAsync
2363 */
2364 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002365 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2366 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002367 }
2368
2369 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002370 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2371 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2372 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002373 * @see #sendRequestAsync
2374 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002375 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2376 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2378 throw new RuntimeException("This method will deadlock if called from the main thread.");
2379 }
2380
Nathan Harold92bed182018-10-12 18:16:49 -07002381 MainThreadRequest request = null;
2382 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2383 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2384 } else if (phone != null) {
2385 request = new MainThreadRequest(argument, phone, workSource);
2386 } else {
2387 request = new MainThreadRequest(argument, subId, workSource);
2388 }
2389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 Message msg = mMainThreadHandler.obtainMessage(command, request);
2391 msg.sendToTarget();
2392
Rambo Wang0f050d82021-02-12 11:43:36 -08002393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002395 if (timeoutInMs >= 0) {
2396 // Wait for at least timeoutInMs before returning null request result
2397 long now = SystemClock.elapsedRealtime();
2398 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002399 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002400 try {
2401 request.wait(deadline - now);
2402 } catch (InterruptedException e) {
2403 // Do nothing, go back and check if request is completed or timeout
2404 } finally {
2405 now = SystemClock.elapsedRealtime();
2406 }
2407 }
2408 } else {
2409 // Wait for the request to complete
2410 while (request.result == null) {
2411 try {
2412 request.wait();
2413 } catch (InterruptedException e) {
2414 // Do nothing, go back and wait until the request is complete
2415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 }
2417 }
2418 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002419 if (request.result == null) {
2420 Log.wtf(LOG_TAG,
2421 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 return request.result;
2424 }
2425
2426 /**
2427 * Asynchronous ("fire and forget") version of sendRequest():
2428 * Posts the specified command to be executed on the main thread, and
2429 * returns immediately.
2430 * @see #sendRequest
2431 */
2432 private void sendRequestAsync(int command) {
2433 mMainThreadHandler.sendEmptyMessage(command);
2434 }
2435
2436 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002437 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002438 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002439 */
2440 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002441 sendRequestAsync(command, argument, null, null);
2442 }
2443
2444 /**
2445 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2446 * @see {@link #sendRequest(int,Object)}
2447 */
2448 private void sendRequestAsync(
2449 int command, Object argument, Phone phone, WorkSource workSource) {
2450 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002451 Message msg = mMainThreadHandler.obtainMessage(command, request);
2452 msg.sendToTarget();
2453 }
2454
2455 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 * Initialize the singleton PhoneInterfaceManager instance.
2457 * This is only done once, at startup, from PhoneApp.onCreate().
2458 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002459 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 synchronized (PhoneInterfaceManager.class) {
2461 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002462 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 } else {
2464 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2465 }
2466 return sInstance;
2467 }
2468 }
2469
2470 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002471 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002473 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002474 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002476 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002477 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002478 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2480 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002481 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002482 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002483 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002484 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002485 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002486 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002487 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2488 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002489 mVendorApiLevel = SystemProperties.getInt(
2490 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2491
Tyler Gunn64144d92022-03-17 14:16:41 -07002492 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 publish();
arunvoddud7401012022-12-15 16:08:12 +00002494 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002495
2496 // Create the SatelliteEntitlementController singleton, for using the get the
2497 // entitlementStatus for satellite service.
2498 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 }
2500
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002501 @VisibleForTesting
2502 public SharedPreferences getSharedPreferences() {
2503 return mTelephonySharedPreferences;
2504 }
2505
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002506 /**
2507 * Get the default phone for this device.
2508 */
2509 @VisibleForTesting
2510 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002511 Phone thePhone = getPhone(getDefaultSubscription());
2512 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2513 }
2514
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 private void publish() {
2516 if (DBG) log("publish: " + this);
2517
Peter Wangc035ce42020-01-08 21:00:22 -08002518 TelephonyFrameworkInitializer
2519 .getTelephonyServiceManager()
2520 .getTelephonyServiceRegisterer()
2521 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 }
2523
Stuart Scott584921c2015-01-15 17:10:34 -08002524 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002525 if (request.phone != null) {
2526 return request.phone;
2527 } else {
2528 return getPhoneFromSubId(request.subId);
2529 }
2530 }
2531
2532 private Phone getPhoneFromSubId(int subId) {
2533 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2534 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002535 }
2536
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002537 /**
2538 * Get phone object associated with a subscription.
2539 * Return default phone if phone object associated with subscription is null
2540 * @param subId - subscriptionId
2541 * @return phone object associated with a subscription or default phone if null.
2542 */
Ling Mac28f0212023-03-24 16:07:15 -07002543 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002544 Phone phone = getPhoneFromSubId(subId);
2545 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002546 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002547 phone = getDefaultPhone();
2548 }
2549 return phone;
2550 }
2551
Rambo Wange53e07d2022-05-10 13:01:13 -07002552 @Nullable
2553 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002554 Phone phone = getPhoneFromRequest(request);
2555 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002556 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002557 }
2558
Ling Mac28f0212023-03-24 16:07:15 -07002559 /**
2560 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2561 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2562 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2563 * @return The Phone associated the sub Id
2564 */
2565 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002566 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568
Kai Shif70f46f2021-03-03 13:59:46 -08002569 private void sendEraseModemConfig(@NonNull Phone phone) {
2570 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2571 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2572 }
2573
2574 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2575 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2576 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002577 }
2578
Peter Wang44b186e2020-01-13 23:33:09 -08002579 private boolean isImsAvailableOnDevice() {
2580 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2581 if (pm == null) {
2582 // For some reason package manger is not available.. This will fail internally anyway,
2583 // so do not throw error and allow.
2584 return true;
2585 }
2586 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2587 }
2588
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002590 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2591 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2592
Wink Savilleadd7cc52014-09-08 14:23:09 -07002593 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002594 }
2595
Wink Savilleb564aae2014-10-23 10:18:09 -07002596 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597 if (DBG) log("dial: " + number);
2598 // No permission check needed here: This is just a wrapper around the
2599 // ACTION_DIAL intent, which is available to any app since it puts up
2600 // the UI before it does anything.
2601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 String url = createTelUrl(number);
2605 if (url == null) {
2606 return;
2607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 // PENDING: should we just silently fail if phone is offhook or ringing?
2610 PhoneConstants.State state = mCM.getState(subId);
2611 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2612 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2613 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2614 mApp.startActivity(intent);
2615 }
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619 }
2620
2621 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002622 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002623 }
2624
Wink Savilleb564aae2014-10-23 10:18:09 -07002625 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 if (DBG) log("call: " + number);
2627
2628 // This is just a wrapper around the ACTION_CALL intent, but we still
2629 // need to do a permission check since we're calling startActivity()
2630 // from the context of the phone app.
2631 enforceCallPermission();
2632
Jordan Liu1617b712019-07-10 15:06:26 -07002633 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 != AppOpsManager.MODE_ALLOWED) {
2635 return;
2636 }
2637
joonhunshin4ac60942023-11-15 15:23:39 +00002638 enforceTelephonyFeatureWithException(callingPackage,
2639 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 String url = createTelUrl(number);
2644 if (url == null) {
2645 return;
2646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 boolean isValid = false;
2649 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2650 if (slist != null) {
2651 for (SubscriptionInfo subInfoRecord : slist) {
2652 if (subInfoRecord.getSubscriptionId() == subId) {
2653 isValid = true;
2654 break;
2655 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002656 }
Wink Saville08874612014-08-31 19:19:58 -07002657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 if (!isValid) {
2659 return;
2660 }
Wink Saville08874612014-08-31 19:19:58 -07002661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2663 intent.putExtra(SUBSCRIPTION_KEY, subId);
2664 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2665 mApp.startActivity(intent);
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002669 }
2670
Wink Savilleb564aae2014-10-23 10:18:09 -07002671 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002672 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002673 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2674 }
2675
Wink Savilleb564aae2014-10-23 10:18:09 -07002676 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002678 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2679 }
2680
Wink Savilleb564aae2014-10-23 10:18:09 -07002681 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
joonhunshin4ac60942023-11-15 15:23:39 +00002684 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2685 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2686 "supplyPinReportResultForSubscriber");
2687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 final long identity = Binder.clearCallingIdentity();
2689 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002690 Phone phone = getPhone(subId);
2691 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 checkSimPin.start();
2693 return checkSimPin.unlockSim(null, pin);
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
2696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 }
2698
Wink Savilleb564aae2014-10-23 10:18:09 -07002699 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701
joonhunshin4ac60942023-11-15 15:23:39 +00002702 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2703 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002707 Phone phone = getPhone(subId);
2708 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709 checkSimPuk.start();
2710 return checkSimPuk.unlockSim(puk, pin);
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
2713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
2716 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002717 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 * a synchronous one.
2719 */
2720 private static class UnlockSim extends Thread {
2721
2722 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002723 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724
2725 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002726 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2727 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728
2729 // For replies from SimCard interface
2730 private Handler mHandler;
2731
2732 // For async handler to identify request type
2733 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002734 private static final int SUPPLY_PIN_DELAYED = 101;
2735 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2736 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2737 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738
Michele Berionne5e411512020-11-13 02:36:59 +00002739 UnlockSim(int phoneId, IccCard simCard) {
2740 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 mSimCard = simCard;
2742 }
2743
2744 @Override
2745 public void run() {
2746 Looper.prepare();
2747 synchronized (UnlockSim.this) {
2748 mHandler = new Handler() {
2749 @Override
2750 public void handleMessage(Message msg) {
2751 AsyncResult ar = (AsyncResult) msg.obj;
2752 switch (msg.what) {
2753 case SUPPLY_PIN_COMPLETE:
2754 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2755 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002756 mRetryCount = msg.arg1;
2757 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002758 CommandException.Error error = null;
2759 if (ar.exception instanceof CommandException) {
2760 error = ((CommandException) (ar.exception))
2761 .getCommandError();
2762 }
2763 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002764 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002765 } else if (error == CommandException.Error.ABORTED) {
2766 /* When UiccCardApp dispose, handle message and return
2767 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002768 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002769 } else {
2770 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2771 }
2772 } else {
2773 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002776 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 UnlockSim.this.notifyAll();
2778 }
2779 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002780 case SUPPLY_PIN_DELAYED:
2781 if(!mDone) {
2782 String logStr = "Delay in receiving SIM PIN response ";
2783 if (DBG) log(logStr);
2784 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2785 }
2786 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 }
2788 }
2789 };
2790 UnlockSim.this.notifyAll();
2791 }
2792 Looper.loop();
2793 }
2794
2795 /*
2796 * Use PIN or PUK to unlock SIM card
2797 *
2798 * If PUK is null, unlock SIM card with PIN
2799 *
2800 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302801 *
2802 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2803 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002804 */
Wink Saville9de0f752013-10-22 19:04:03 -07002805 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002806
2807 while (mHandler == null) {
2808 try {
2809 wait();
2810 } catch (InterruptedException e) {
2811 Thread.currentThread().interrupt();
2812 }
2813 }
2814 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2815
2816 if (puk == null) {
2817 mSimCard.supplyPin(pin, callback);
2818 } else {
2819 mSimCard.supplyPuk(puk, pin, callback);
2820 }
2821
2822 while (!mDone) {
2823 try {
2824 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002825 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2826 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 wait();
2828 } catch (InterruptedException e) {
2829 // Restore the interrupted status
2830 Thread.currentThread().interrupt();
2831 }
2832 }
2833 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002834 int[] resultArray = new int[2];
2835 resultArray[0] = mResult;
2836 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002837
2838 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002839 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002840 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302841 // This instance is no longer reused, so quit its thread's looper.
2842 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002843
Wink Saville9de0f752013-10-22 19:04:03 -07002844 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 }
2846 }
2847
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002848 /**
2849 * This method has been removed due to privacy and stability concerns.
2850 */
2851 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002853 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2854 return;
Wink Saville36469e72014-06-11 15:17:00 -07002855 }
2856
Nathan Harold1f889d82020-06-04 17:05:26 -07002857 @Override
2858 public void updateServiceLocationWithPackageName(String callingPackage) {
2859 mApp.getSystemService(AppOpsManager.class)
2860 .checkPackage(Binder.getCallingUid(), callingPackage);
2861
Nathan Haroldf096d982020-11-18 17:18:06 -08002862 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002863 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2864 // Callers targeting S have no business invoking this method.
2865 return;
2866 }
2867
2868 LocationAccessPolicy.LocationPermissionResult locationResult =
2869 LocationAccessPolicy.checkLocationPermission(mApp,
2870 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2871 .setCallingPackage(callingPackage)
2872 .setCallingFeatureId(null)
2873 .setCallingPid(Binder.getCallingPid())
2874 .setCallingUid(Binder.getCallingUid())
2875 .setMethod("updateServiceLocation")
2876 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2877 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2878 .build());
2879 // Apps that lack location permission have no business calling this method;
2880 // however, because no permission was declared in the public API, denials must
2881 // all be "soft".
2882 switch (locationResult) {
2883 case DENIED_HARD: /* fall through */
2884 case DENIED_SOFT:
2885 return;
2886 }
2887
2888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 final long identity = Binder.clearCallingIdentity();
2890 try {
Ling Mac28f0212023-03-24 16:07:15 -07002891 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 } finally {
2893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 }
2896
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002897 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002898 @Override
2899 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002900 return isRadioOnWithFeature(callingPackage, null);
2901 }
2902
2903
2904 @Override
2905 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2906 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2907 callingFeatureId);
2908 }
2909
2910 @Deprecated
2911 @Override
2912 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2913 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002914 }
2915
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002916 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002917 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2918 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002919 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002920 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002921 return false;
2922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923
joonhunshin4ac60942023-11-15 15:23:39 +00002924 enforceTelephonyFeatureWithException(callingPackage,
2925 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 return isRadioOnForSubscriber(subId);
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002933 }
2934
2935 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 final Phone phone = getPhone(subId);
2939 if (phone != null) {
2940 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2941 } else {
2942 return false;
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 }
2948
2949 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002950 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002951 }
Wink Saville36469e72014-06-11 15:17:00 -07002952
Wink Savilleb564aae2014-10-23 10:18:09 -07002953 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955
joonhunshin4ac60942023-11-15 15:23:39 +00002956 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2957 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 final Phone phone = getPhone(subId);
2962 if (phone != null) {
2963 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2964 }
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002967 }
Wink Saville36469e72014-06-11 15:17:00 -07002968 }
2969
2970 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002971 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002972 }
2973
Wink Savilleb564aae2014-10-23 10:18:09 -07002974 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002975 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976
2977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 final Phone phone = getPhone(subId);
2980 if (phone == null) {
2981 return false;
2982 }
2983 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2984 toggleRadioOnOffForSubscriber(subId);
2985 }
2986 return true;
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 }
Wink Saville36469e72014-06-11 15:17:00 -07002991
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002992 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002993 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002994
2995 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2996 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2997
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002998 /*
2999 * If any of the Radios are available, it will need to be
3000 * shutdown. So return true if any Radio is available.
3001 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3005 Phone phone = PhoneFactory.getPhone(i);
3006 if (phone != null && phone.isRadioAvailable()) return true;
3007 }
3008 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3009 return false;
3010 } finally {
3011 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003012 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003013 }
3014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003016 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017 enforceModifyPermission();
3018
joonhunshin4ac60942023-11-15 15:23:39 +00003019 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3020 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3025 logv("Shutting down Phone " + i);
3026 shutdownRadioUsingPhoneId(i);
3027 }
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003030 }
3031 }
3032
3033 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003034 Phone phone = PhoneFactory.getPhone(phoneId);
3035 if (phone != null && phone.isRadioAvailable()) {
3036 phone.shutdownRadio();
3037 }
3038 }
3039
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003040 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042
Ling Ma83dc5ea2023-01-12 15:06:04 -08003043 if (!turnOn) {
3044 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3045 }
3046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3050 if (defaultPhone != null) {
3051 defaultPhone.setRadioPower(turnOn);
3052 return true;
3053 } else {
3054 loge("There's no default phone.");
3055 return false;
3056 }
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003059 }
Wink Saville36469e72014-06-11 15:17:00 -07003060 }
3061
Wink Savilleb564aae2014-10-23 10:18:09 -07003062 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064
Ling Ma83dc5ea2023-01-12 15:06:04 -08003065 if (!turnOn) {
3066 log("setRadioPowerForSubscriber off: subId=" + subId
3067 + ",callingPackage=" + getCurrentPackageName());
3068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 final Phone phone = getPhone(subId);
3072 if (phone != null) {
3073 phone.setRadioPower(turnOn);
3074 return true;
3075 } else {
3076 return false;
3077 }
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081 }
3082
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003083 /**
3084 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3085 * no reason to power it off. When any of the voters want to power it off, it will be turned
3086 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3087 * powering it off, and these radio off votes will be cleared.
3088 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3089 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3090 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3091 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3092 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3093 * check its vote.
3094 *
3095 * @param subId The subscription ID.
3096 * @param reason The reason for powering off radio.
3097 * @return true on success and false on failure.
3098 */
3099 public boolean requestRadioPowerOffForReason(int subId,
3100 @TelephonyManager.RadioPowerReason int reason) {
3101 enforceModifyPermission();
3102
joonhunshin4ac60942023-11-15 15:23:39 +00003103 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3104 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3105
Ling Ma83dc5ea2023-01-12 15:06:04 -08003106 log("requestRadioPowerOffForReason: subId=" + subId
3107 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003108 final long identity = Binder.clearCallingIdentity();
3109 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003110 boolean result = false;
3111 for (Phone phone : PhoneFactory.getPhones()) {
3112 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003113 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003114 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003115 if (!result) {
3116 loge("requestRadioPowerOffForReason: no phone exists");
3117 }
3118 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
3124 /**
3125 * Remove the vote on powering off the radio for a reason, as requested by
3126 * {@link requestRadioPowerOffForReason}.
3127 *
3128 * @param subId The subscription ID.
3129 * @param reason The reason for powering off radio.
3130 * @return true on success and false on failure.
3131 */
3132 public boolean clearRadioPowerOffForReason(int subId,
3133 @TelephonyManager.RadioPowerReason int reason) {
3134 enforceModifyPermission();
3135
joonhunshin4ac60942023-11-15 15:23:39 +00003136 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3137 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3138
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003139 final long identity = Binder.clearCallingIdentity();
3140 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003141 boolean result = false;
3142 for (Phone phone : PhoneFactory.getPhones()) {
3143 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003144 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003145 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003146 if (!result) {
3147 loge("clearRadioPowerOffForReason: no phone exists");
3148 }
3149 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003150 } finally {
3151 Binder.restoreCallingIdentity(identity);
3152 }
3153 }
3154
3155 /**
3156 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3157 *
3158 * @param subId The subscription ID.
3159 * @param callingPackage The package making the call.
3160 * @param callingFeatureId The feature in the package.
3161 * @return List of reasons for powering off radio.
3162 */
3163 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3164 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3165
joonhunshin4ac60942023-11-15 15:23:39 +00003166 enforceTelephonyFeatureWithException(callingPackage,
3167 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3168
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003169 final long identity = Binder.clearCallingIdentity();
3170 List result = new ArrayList();
3171 try {
3172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3173 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3174 return result;
3175 }
3176
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003177 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003178 if (phone != null) {
3179 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003180 } else {
3181 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003182 }
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
3185 }
3186 return result;
3187 }
3188
Wink Saville36469e72014-06-11 15:17:00 -07003189 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003190 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003191 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193
joonhunshin4ac60942023-11-15 15:23:39 +00003194 enforceTelephonyFeatureWithException(callingPackage,
3195 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 final long identity = Binder.clearCallingIdentity();
3198 try {
Jack Yu285100e2022-12-02 22:48:35 -08003199 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final Phone phone = getPhone(subId);
3201 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003202 phone.getDataSettingsManager().setDataEnabled(
3203 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 return true;
3205 } else {
3206 return false;
3207 }
3208 } finally {
3209 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 }
3212
Wink Saville36469e72014-06-11 15:17:00 -07003213 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003214 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003215 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217
joonhunshin4ac60942023-11-15 15:23:39 +00003218 enforceTelephonyFeatureWithException(callingPackage,
3219 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 final long identity = Binder.clearCallingIdentity();
3222 try {
Jack Yu285100e2022-12-02 22:48:35 -08003223 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 final Phone phone = getPhone(subId);
3225 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003226 phone.getDataSettingsManager().setDataEnabled(
3227 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228 return true;
3229 } else {
3230 return false;
3231 }
3232 } finally {
3233 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003235 }
3236
Sanket Padawe356d7632015-06-22 14:03:32 -07003237 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003238 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003239 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3240 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 final Phone phone = getPhone(subId);
3245 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003246 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247 } else {
3248 return false;
3249 }
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 }
3254
3255 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003256 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003257 }
3258
pkanwarae03a6b2016-11-06 20:37:09 -08003259 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003260 enforceCallPermission();
3261
joonhunshin4ac60942023-11-15 15:23:39 +00003262 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3263 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265 final long identity = Binder.clearCallingIdentity();
3266 try {
3267 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3268 return;
3269 }
3270 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3271 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3272 } finally {
3273 Binder.restoreCallingIdentity(identity);
3274 }
pkanwar32d516d2016-10-14 19:37:38 -07003275 };
3276
Wink Savilleb564aae2014-10-23 10:18:09 -07003277 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279
joonhunshin4ac60942023-11-15 15:23:39 +00003280 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3281 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3286 return false;
3287 }
3288 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3289 } finally {
3290 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003292 }
3293
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003294 /**
3295 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3296 * tag on getCallState Binder call.
3297 */
3298 @Deprecated
3299 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003301 if (CompatChanges.isChangeEnabled(
3302 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3303 Binder.getCallingUid())) {
3304 // Do not allow this API to be called on API version 31+, it should only be
3305 // called on old apps using this Binder call directly.
3306 throw new SecurityException("This method can only be used for applications "
3307 + "targeting API version 30 or less.");
3308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309 final long identity = Binder.clearCallingIdentity();
3310 try {
Ling Mac28f0212023-03-24 16:07:15 -07003311 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3312 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
3316 }
3317
3318 @Override
3319 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3320 if (CompatChanges.isChangeEnabled(
3321 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3322 Binder.getCallingUid())) {
3323 // Check READ_PHONE_STATE for API version 31+
3324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3325 featureId, "getCallStateForSubscription")) {
3326 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3327 + "targeting API level 31+.");
3328 }
3329 }
joonhunshin4ac60942023-11-15 15:23:39 +00003330
3331 enforceTelephonyFeatureWithException(callingPackage,
3332 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3333
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3338 PhoneConstantConversions.convertCallState(phone.getState());
3339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003342 }
3343
Sanket Padawe356d7632015-06-22 14:03:32 -07003344 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003345 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003346 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003347 }
3348
3349 @Override
3350 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003351 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3352 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354 final long identity = Binder.clearCallingIdentity();
3355 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003356 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003358 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359 } else {
3360 return PhoneConstantConversions.convertDataState(
3361 PhoneConstants.DataState.DISCONNECTED);
3362 }
3363 } finally {
3364 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003366 }
3367
Sanket Padawe356d7632015-06-22 14:03:32 -07003368 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003369 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003370 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003371 }
3372
3373 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003374 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003375 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3376 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 final long identity = Binder.clearCallingIdentity();
3379 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003380 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003382 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003383 } else {
3384 return TelephonyManager.DATA_ACTIVITY_NONE;
3385 }
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 }
3390
3391 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003392 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003393 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003394 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003395
3396 LocationAccessPolicy.LocationPermissionResult locationResult =
3397 LocationAccessPolicy.checkLocationPermission(mApp,
3398 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3399 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003400 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003401 .setCallingPid(Binder.getCallingPid())
3402 .setCallingUid(Binder.getCallingUid())
3403 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003404 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003405 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3406 .build());
3407 switch (locationResult) {
3408 case DENIED_HARD:
3409 throw new SecurityException("Not allowed to access cell location");
3410 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003411 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3412 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 }
3414
joonhunshin4ac60942023-11-15 15:23:39 +00003415 enforceTelephonyFeatureWithException(callingPackage,
3416 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3417
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003418 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003422 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003423 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
Svetoslav64fad262015-04-14 14:35:21 -07003427 }
3428
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003429 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003430 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003431 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3432 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3433
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003434 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3435 // registered cell info, so return a NULL country instead.
3436 final long identity = Binder.clearCallingIdentity();
3437 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003438 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3439 // Get default phone in this case.
3440 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3441 }
Jack Yu285100e2022-12-02 22:48:35 -08003442 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003444 if (phone == null) return "";
3445 ServiceStateTracker sst = phone.getServiceStateTracker();
3446 if (sst == null) return "";
3447 LocaleTracker lt = sst.getLocaleTracker();
3448 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003449 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003450 } finally {
3451 Binder.restoreCallingIdentity(identity);
3452 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003453 }
3454
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003455 /**
3456 * This method was removed due to potential issues caused by performing partial
3457 * updates of service state, and lack of a credible use case.
3458 *
3459 * This has the ability to break the telephony implementation by disabling notification of
3460 * changes in device connectivity. DO NOT USE THIS!
3461 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003462 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 public void enableLocationUpdates() {
3464 mApp.enforceCallingOrSelfPermission(
3465 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003466 }
3467
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003468 /**
3469 * This method was removed due to potential issues caused by performing partial
3470 * updates of service state, and lack of a credible use case.
3471 *
3472 * This has the ability to break the telephony implementation by disabling notification of
3473 * changes in device connectivity. DO NOT USE THIS!
3474 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003475 @Override
3476 public void disableLocationUpdates() {
3477 mApp.enforceCallingOrSelfPermission(
3478 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003479 }
3480
3481 @Override
3482 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003483 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3484 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003485 try {
3486 mApp.getSystemService(AppOpsManager.class)
3487 .checkPackage(Binder.getCallingUid(), callingPackage);
3488 } catch (SecurityException e) {
3489 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3490 throw e;
3491 }
3492
Nathan Haroldf096d982020-11-18 17:18:06 -08003493 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003494 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3495 throw new SecurityException(
3496 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3497 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003498
Jordan Liu1617b712019-07-10 15:06:26 -07003499 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003500 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3501 return null;
3502 }
Svetoslav64fad262015-04-14 14:35:21 -07003503
joonhunshin4ac60942023-11-15 15:23:39 +00003504 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3505 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3506
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003507 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003509 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003510 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511
Nathan Haroldf180aac2018-06-01 18:43:55 -07003512 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3513 for (CellInfo ci : info) {
3514 if (ci instanceof CellInfoGsm) {
3515 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3516 } else if (ci instanceof CellInfoWcdma) {
3517 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003519 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003520 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 }
3522
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003523 private List<CellInfo> getCachedCellInfo() {
3524 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3525 for (Phone phone : PhoneFactory.getPhones()) {
3526 List<CellInfo> info = phone.getAllCellInfo();
3527 if (info != null) cellInfos.addAll(info);
3528 }
3529 return cellInfos;
3530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003531
3532 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003533 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003534 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003535 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003536
3537 LocationAccessPolicy.LocationPermissionResult locationResult =
3538 LocationAccessPolicy.checkLocationPermission(mApp,
3539 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3540 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003541 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003542 .setCallingPid(Binder.getCallingPid())
3543 .setCallingUid(Binder.getCallingUid())
3544 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003545 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003546 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3547 .build());
3548 switch (locationResult) {
3549 case DENIED_HARD:
3550 throw new SecurityException("Not allowed to access cell info");
3551 case DENIED_SOFT:
3552 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003553 }
3554
Nathan Haroldf096d982020-11-18 17:18:06 -08003555 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003556 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3557 return getCachedCellInfo();
3558 }
3559
joonhunshin4ac60942023-11-15 15:23:39 +00003560 enforceTelephonyFeatureWithException(callingPackage,
3561 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3562
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003563 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003564 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3568 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003569 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003570 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571 if (info != null) cellInfos.addAll(info);
3572 }
3573 return cellInfos;
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003576 }
3577 }
3578
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003579 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003580 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3581 String callingFeatureId) {
3582 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3583 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003584 }
3585
3586 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003587 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3588 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003589 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003590 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003591 }
3592
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003593 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3594 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003596 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003597
3598 LocationAccessPolicy.LocationPermissionResult locationResult =
3599 LocationAccessPolicy.checkLocationPermission(mApp,
3600 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3601 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003602 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003603 .setCallingPid(Binder.getCallingPid())
3604 .setCallingUid(Binder.getCallingUid())
3605 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003606 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3607 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003608 .build());
3609 switch (locationResult) {
3610 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003611 if (TelephonyPermissions
3612 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003613 // Safetynet logging for b/154934934
3614 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3615 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003616 throw new SecurityException("Not allowed to access cell info");
3617 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003618 if (TelephonyPermissions
3619 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003620 // Safetynet logging for b/154934934
3621 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3622 }
Nathan Harold5320c422019-05-09 10:26:08 -07003623 try {
3624 cb.onCellInfo(new ArrayList<CellInfo>());
3625 } catch (RemoteException re) {
3626 // Drop without consequences
3627 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003628 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003629 }
3630
joonhunshin4ac60942023-11-15 15:23:39 +00003631 enforceTelephonyFeatureWithException(callingPackage,
3632 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003633
3634 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003635 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3636
3637 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3638 }
3639
3640 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003641 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003642 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003643 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644
3645 final long identity = Binder.clearCallingIdentity();
3646 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003647 Phone phone = getPhone(subId);
3648 if (phone == null) {
3649 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3650 } else {
3651 phone.setCellInfoListRate(rateInMillis, workSource);
3652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003656 }
3657
Shishir Agrawala9f32182016-04-12 12:00:16 -07003658 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003659 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003660 Phone phone = PhoneFactory.getPhone(slotIndex);
3661 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 return null;
3663 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003664 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003665 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003666 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003667 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003668 return null;
3669 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003670
joonhunshin4ac60942023-11-15 15:23:39 +00003671 enforceTelephonyFeatureWithException(callingPackage,
3672 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 return phone.getImei();
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003680 }
3681
3682 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003683 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3684 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3685 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3686 callingFeatureId, "getPrimaryImei")) {
3687 throw new SecurityException("Caller does not have permission");
3688 }
joonhunshin4ac60942023-11-15 15:23:39 +00003689
3690 enforceTelephonyFeatureWithException(callingPackage,
3691 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3692
arunvoddud5c6ce02022-12-11 06:03:12 +00003693 final long identity = Binder.clearCallingIdentity();
3694 try {
3695 for (Phone phone : PhoneFactory.getPhones()) {
3696 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3697 return phone.getImei();
3698 }
3699 }
3700 throw new UnsupportedOperationException("Operation not supported");
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
3704 }
3705
3706 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003707 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003708 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3709 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3710
David Kelly5e06a7f2018-03-12 14:10:59 +00003711 Phone phone = PhoneFactory.getPhone(slotIndex);
3712 String tac = null;
3713 if (phone != null) {
3714 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003715 try {
3716 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3717 } catch (IndexOutOfBoundsException e) {
3718 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3719 return null;
3720 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003721 }
3722 return tac;
3723 }
3724
3725 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003726 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003727 try {
3728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3729 } catch (SecurityException se) {
3730 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3731 throw new SecurityException("Package " + callingPackage + " does not belong to "
3732 + Binder.getCallingUid());
3733 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003734 Phone phone = PhoneFactory.getPhone(slotIndex);
3735 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003736 return null;
3737 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003738
Jeff Davidson913390f2018-02-23 17:11:49 -08003739 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003740 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003741 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003742 return null;
3743 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744
joonhunshin4ac60942023-11-15 15:23:39 +00003745 enforceTelephonyFeatureWithException(callingPackage,
3746 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 return phone.getMeid();
3751 } finally {
3752 Binder.restoreCallingIdentity(identity);
3753 }
Jack Yu2af8d712017-03-15 17:14:14 -07003754 }
3755
3756 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003757 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003758 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3759 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3760
David Kelly5e06a7f2018-03-12 14:10:59 +00003761 Phone phone = PhoneFactory.getPhone(slotIndex);
3762 String manufacturerCode = null;
3763 if (phone != null) {
3764 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003765 try {
3766 manufacturerCode =
3767 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3768 } catch (IndexOutOfBoundsException e) {
3769 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3770 return null;
3771 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003772 }
3773 return manufacturerCode;
3774 }
3775
3776 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003777 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3778 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003779 Phone phone = PhoneFactory.getPhone(slotIndex);
3780 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003781 return null;
3782 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003783 int subId = phone.getSubId();
3784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003785 mApp, subId, callingPackage, callingFeatureId,
3786 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003787 return null;
3788 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003789
joonhunshin4ac60942023-11-15 15:23:39 +00003790 enforceTelephonyFeatureWithException(callingPackage,
3791 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 return phone.getDeviceSvn();
3796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003799 }
3800
fionaxu43304da2017-11-27 22:51:16 -08003801 @Override
3802 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003803 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3804 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 final Phone phone = getPhone(subId);
3809 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
3812 }
fionaxu43304da2017-11-27 22:51:16 -08003813 }
3814
3815 @Override
3816 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003817 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3818 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 final Phone phone = getPhone(subId);
3823 return phone == null ? null : phone.getCarrierName();
3824 } finally {
3825 Binder.restoreCallingIdentity(identity);
3826 }
fionaxu43304da2017-11-27 22:51:16 -08003827 }
3828
calvinpanffe225e2018-11-01 19:43:06 +08003829 @Override
chen xu0026ca62019-03-06 15:28:50 -08003830 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003831 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3832 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3833
chen xu25637222018-11-04 17:17:00 -08003834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 final Phone phone = getPhone(subId);
3837 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003838 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003839 } finally {
3840 Binder.restoreCallingIdentity(identity);
3841 }
3842 }
3843
3844 @Override
chen xu0026ca62019-03-06 15:28:50 -08003845 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003846 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3847 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3848 "getSubscriptionSpecificCarrierName");
3849
chen xu25637222018-11-04 17:17:00 -08003850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003853 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003854 } finally {
3855 Binder.restoreCallingIdentity(identity);
3856 }
3857 }
3858
chen xu651eec72018-11-11 19:03:44 -08003859 @Override
chen xu864e11c2018-12-06 22:10:03 -08003860 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3861 if (!isSubscriptionMccMnc) {
3862 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3863 }
chen xu651eec72018-11-11 19:03:44 -08003864 final Phone phone = PhoneFactory.getPhone(slotIndex);
3865 if (phone == null) {
3866 return TelephonyManager.UNKNOWN_CARRIER_ID;
3867 }
joonhunshin4ac60942023-11-15 15:23:39 +00003868
3869 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3870 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3871
chen xu651eec72018-11-11 19:03:44 -08003872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
3877 }
3878 }
3879
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003880 //
3881 // Internal helper methods.
3882 //
3883
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003884 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003885 * Make sure the caller is the calling package itself
3886 *
3887 * @throws SecurityException if the caller is not the calling package
3888 */
3889 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3890 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003891 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3892 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003893 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003894 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003895 } catch (PackageManager.NameNotFoundException e) {
3896 // packageUid is -1
3897 }
3898 if (packageUid != callingUid) {
3899 throw new SecurityException(message + ": Package " + callingPackage
3900 + " does not belong to " + callingUid);
3901 }
3902 }
3903
3904 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003905 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3906 *
3907 * @throws SecurityException if the caller does not have the required permission
3908 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003909 @VisibleForTesting
3910 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003911 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3912 }
3913
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003914 /**
arunvoddud7401012022-12-15 16:08:12 +00003915 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003916 *
3917 * @throws SecurityException if the caller does not have the required permission
3918 */
3919 @VisibleForTesting
3920 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003921 enforceReadPermission(null);
3922 }
3923
3924 /**
3925 * Make sure the caller has the READ_PHONE_STATE permissions.
3926 *
3927 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3928 */
3929 @VisibleForTesting
3930 public void enforceReadPermission(String msg) {
3931 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003932 }
3933
Shuo Qian3b6ee772019-11-13 17:43:31 -08003934 private void enforceActiveEmergencySessionPermission() {
3935 mApp.enforceCallingOrSelfPermission(
3936 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3937 }
3938
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003939 /**
3940 * Make sure the caller has the CALL_PHONE permission.
3941 *
3942 * @throws SecurityException if the caller does not have the required permission
3943 */
3944 private void enforceCallPermission() {
3945 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3946 }
3947
paulhu5a773602019-08-23 19:17:33 +08003948 private void enforceSettingsPermission() {
3949 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003950 }
3951
Michele Berionne5e411512020-11-13 02:36:59 +00003952 private void enforceRebootPermission() {
3953 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3954 }
3955
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003956 /**
3957 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3958 * @param message - log message to print.
3959 * @throws SecurityException if the caller does not have the required permission
3960 */
3961 private void enforceSatelliteCommunicationPermission(String message) {
3962 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3963 }
3964
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003965 private String createTelUrl(String number) {
3966 if (TextUtils.isEmpty(number)) {
3967 return null;
3968 }
3969
Jake Hambye994d462014-02-03 13:10:13 -08003970 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003971 }
3972
Ihab Awadf9e92732013-12-05 18:02:52 -08003973 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003974 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003975 }
3976
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003977 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003978 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003979 }
3980
Ihab Awadf9e92732013-12-05 18:02:52 -08003981 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003982 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003983 }
3984
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003985 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003986 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003987 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003988 }
3989
Sanket Padawe356d7632015-06-22 14:03:32 -07003990 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003991 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003992 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3993 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 final Phone phone = PhoneFactory.getPhone(slotIndex);
3998 if (phone == null) {
3999 return PhoneConstants.PHONE_TYPE_NONE;
4000 } else {
4001 return phone.getPhoneType();
4002 }
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004006 }
4007
4008 /**
4009 * Returns the CDMA ERI icon index to display
4010 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004011 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004012 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4013 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4014 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004015 }
4016
Sanket Padawe356d7632015-06-22 14:03:32 -07004017 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004018 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4019 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004021 mApp, subId, callingPackage, callingFeatureId,
4022 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004023 return -1;
4024 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004025
joonhunshin4ac60942023-11-15 15:23:39 +00004026 enforceTelephonyFeatureWithException(callingPackage,
4027 PackageManager.FEATURE_TELEPHONY_CDMA,
4028 "getCdmaEriIconIndexForSubscriber");
4029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004030 final long identity = Binder.clearCallingIdentity();
4031 try {
4032 final Phone phone = getPhone(subId);
4033 if (phone != null) {
4034 return phone.getCdmaEriIconIndex();
4035 } else {
4036 return -1;
4037 }
4038 } finally {
4039 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004041 }
4042
4043 /**
4044 * Returns the CDMA ERI icon mode,
4045 * 0 - ON
4046 * 1 - FLASHING
4047 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004048 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004049 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4050 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4051 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004052 }
4053
Sanket Padawe356d7632015-06-22 14:03:32 -07004054 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004055 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4056 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004058 mApp, subId, callingPackage, callingFeatureId,
4059 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004060 return -1;
4061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004062
4063 final long identity = Binder.clearCallingIdentity();
4064 try {
4065 final Phone phone = getPhone(subId);
4066 if (phone != null) {
4067 return phone.getCdmaEriIconMode();
4068 } else {
4069 return -1;
4070 }
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004073 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004074 }
4075
4076 /**
4077 * Returns the CDMA ERI text,
4078 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004079 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004080 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4081 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4082 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004083 }
4084
Sanket Padawe356d7632015-06-22 14:03:32 -07004085 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004086 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4087 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004089 mApp, subId, callingPackage, callingFeatureId,
4090 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004091 return null;
4092 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093
4094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 final Phone phone = getPhone(subId);
4097 if (phone != null) {
4098 return phone.getCdmaEriText();
4099 } else {
4100 return null;
4101 }
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004105 }
4106
4107 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004108 * Returns the CDMA MDN.
4109 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004110 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004111 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4113 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004114
joonhunshin4ac60942023-11-15 15:23:39 +00004115 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4116 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004121 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004122 return phone.getLine1Number();
4123 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004124 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125 return null;
4126 }
4127 } finally {
4128 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004129 }
4130 }
4131
4132 /**
4133 * Returns the CDMA MIN.
4134 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004135 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004136 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4138 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004139
joonhunshin4ac60942023-11-15 15:23:39 +00004140 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4141 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 final Phone phone = getPhone(subId);
4146 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4147 return phone.getCdmaMin();
4148 } else {
4149 return null;
4150 }
4151 } finally {
4152 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004153 }
4154 }
4155
Hall Liud892bec2018-11-30 14:51:45 -08004156 @Override
4157 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4158 INumberVerificationCallback callback, String callingPackage) {
4159 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4160 != PERMISSION_GRANTED) {
4161 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4162 }
4163 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4164
4165 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4166 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004167 throw new SecurityException("Calling package must be configured in the device config: "
4168 + "calling package: " + callingPackage
4169 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004170 }
4171
joonhunshin4ac60942023-11-15 15:23:39 +00004172 enforceTelephonyFeatureWithException(callingPackage,
4173 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4174
Hall Liud892bec2018-11-30 14:51:45 -08004175 if (range == null) {
4176 throw new NullPointerException("Range must be non-null");
4177 }
4178
4179 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004180 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004181
4182 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4183 }
4184
Junda Liuca05d5d2014-08-14 22:36:34 -07004185 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004186 * Returns true if CDMA provisioning needs to run.
4187 */
4188 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004189 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4190 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192 final long identity = Binder.clearCallingIdentity();
4193 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004194 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 } finally {
4196 Binder.restoreCallingIdentity(identity);
4197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004198 }
4199
4200 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004201 * Sets the voice mail number of a given subId.
4202 */
4203 @Override
4204 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004205 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4206 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004207
joonhunshin4ac60942023-11-15 15:23:39 +00004208 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4209 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 final long identity = Binder.clearCallingIdentity();
4212 try {
4213 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4214 new Pair<String, String>(alphaTag, number), new Integer(subId));
4215 return success;
4216 } finally {
4217 Binder.restoreCallingIdentity(identity);
4218 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004219 }
4220
Ta-wei Yen87c49842016-05-13 21:19:52 -07004221 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004222 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4223 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004224 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4225 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004226 if (!TextUtils.equals(callingPackage, systemDialer)) {
4227 throw new SecurityException("caller must be system dialer");
4228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229
joonhunshin4ac60942023-11-15 15:23:39 +00004230 enforceTelephonyFeatureWithException(callingPackage,
4231 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004233 final long identity = Binder.clearCallingIdentity();
4234 try {
4235 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4236 if (phoneAccountHandle == null) {
4237 return null;
4238 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004239 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240 } finally {
4241 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004242 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004243 }
4244
4245 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004246 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4247 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004248 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004250 mApp, subId, callingPackage, callingFeatureId,
4251 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004252 return null;
4253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254
joonhunshin4ac60942023-11-15 15:23:39 +00004255 enforceTelephonyFeatureWithException(callingPackage,
4256 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4257
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004258 final long identity = Binder.clearCallingIdentity();
4259 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004260 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004261 } finally {
4262 Binder.restoreCallingIdentity(identity);
4263 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004264 }
4265
4266 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004267 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4268 VisualVoicemailSmsFilterSettings settings) {
4269 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004270 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004271 enforceTelephonyFeatureWithException(callingPackage,
4272 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 final long identity = Binder.clearCallingIdentity();
4274 try {
4275 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004276 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277 } finally {
4278 Binder.restoreCallingIdentity(identity);
4279 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004280 }
4281
4282 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004283 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4284 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285
joonhunshin4ac60942023-11-15 15:23:39 +00004286 enforceTelephonyFeatureWithException(callingPackage,
4287 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 final long identity = Binder.clearCallingIdentity();
4290 try {
4291 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004292 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 } finally {
4294 Binder.restoreCallingIdentity(identity);
4295 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004296 }
4297
4298 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004299 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4300 String callingPackage, int subId) {
4301 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004302
4303 final long identity = Binder.clearCallingIdentity();
4304 try {
4305 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004306 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004310 }
4311
4312 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004313 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004314 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315
4316 final long identity = Binder.clearCallingIdentity();
4317 try {
4318 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004319 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004323 }
4324
4325 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004326 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4327 String callingAttributionTag, int subId, String number, int port, String text,
4328 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004329 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004330 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004331 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004332
4333 enforceTelephonyFeatureWithException(callingPackage,
4334 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4335
Amit Mahajandccb3f12019-05-13 13:48:32 -07004336 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004337 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4338 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004339 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004340
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004341 /**
fionaxu0152e512016-11-14 13:36:14 -08004342 * Sets the voice activation state of a given subId.
4343 */
4344 @Override
4345 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4347 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004348
joonhunshin4ac60942023-11-15 15:23:39 +00004349 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4350 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004352 final long identity = Binder.clearCallingIdentity();
4353 try {
4354 final Phone phone = getPhone(subId);
4355 if (phone != null) {
4356 phone.setVoiceActivationState(activationState);
4357 } else {
4358 loge("setVoiceActivationState fails with invalid subId: " + subId);
4359 }
4360 } finally {
4361 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004362 }
4363 }
4364
4365 /**
4366 * Sets the data activation state of a given subId.
4367 */
4368 @Override
4369 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4371 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372
joonhunshin4ac60942023-11-15 15:23:39 +00004373 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4374 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 final Phone phone = getPhone(subId);
4379 if (phone != null) {
4380 phone.setDataActivationState(activationState);
4381 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004382 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004383 }
4384 } finally {
4385 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004386 }
4387 }
4388
4389 /**
4390 * Returns the voice activation state of a given subId.
4391 */
4392 @Override
4393 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004394 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395
joonhunshin4ac60942023-11-15 15:23:39 +00004396 enforceTelephonyFeatureWithException(callingPackage,
4397 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4398
fionaxu0152e512016-11-14 13:36:14 -08004399 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400 final long identity = Binder.clearCallingIdentity();
4401 try {
4402 if (phone != null) {
4403 return phone.getVoiceActivationState();
4404 } else {
4405 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4406 }
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004409 }
4410 }
4411
4412 /**
4413 * Returns the data activation state of a given subId.
4414 */
4415 @Override
4416 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004417 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004418
joonhunshin4ac60942023-11-15 15:23:39 +00004419 enforceTelephonyFeatureWithException(callingPackage,
4420 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4421
fionaxu0152e512016-11-14 13:36:14 -08004422 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004423 final long identity = Binder.clearCallingIdentity();
4424 try {
4425 if (phone != null) {
4426 return phone.getDataActivationState();
4427 } else {
4428 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4429 }
4430 } finally {
4431 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004432 }
4433 }
4434
4435 /**
Wink Saville36469e72014-06-11 15:17:00 -07004436 * Returns the unread count of voicemails for a subId
4437 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004438 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004439 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4440 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004442 mApp, subId, callingPackage, callingFeatureId,
4443 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004444 return 0;
4445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 final long identity = Binder.clearCallingIdentity();
4447 try {
4448 final Phone phone = getPhone(subId);
4449 if (phone != null) {
4450 return phone.getVoiceMessageCount();
4451 } else {
4452 return 0;
4453 }
4454 } finally {
4455 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004457 }
4458
4459 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004460 * returns true, if the device is in a state where both voice and data
4461 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004462 */
4463 @Override
4464 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004465 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4466 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468 final long identity = Binder.clearCallingIdentity();
4469 try {
Ling Mac28f0212023-03-24 16:07:15 -07004470 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004474 }
4475
4476 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004477 * Send the dialer code if called from the current default dialer or the caller has
4478 * carrier privilege.
4479 * @param inputCode The dialer code to send
4480 */
4481 @Override
4482 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004483 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004484 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004485 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4486 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004487 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004488 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004489 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491
joonhunshin4ac60942023-11-15 15:23:39 +00004492 enforceTelephonyFeatureWithException(callingPackage,
4493 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004497 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
fionaxu235cc5e2017-03-06 22:25:57 -08004501 }
4502
Pengquan Menga1bb6272018-09-06 09:59:22 -07004503 @Override
4504 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004505 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004506 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4507 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004508
4509 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4510 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4511
shilufc958392020-01-20 11:36:01 -08004512 final long identity = Binder.clearCallingIdentity();
4513 try {
4514 if (!isActiveSubscription(subId)) {
4515 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4516 }
4517 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4518 } finally {
4519 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004521 }
4522
Brad Ebinger35c841c2018-10-01 10:40:55 -07004523 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004524 public boolean isInEmergencySmsMode() {
4525 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004526
4527 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4528 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4529
Brad Ebingerb2b65522019-03-15 13:48:47 -07004530 final long identity = Binder.clearCallingIdentity();
4531 try {
4532 for (Phone phone : PhoneFactory.getPhones()) {
4533 if (phone.isInEmergencySmsMode()) {
4534 return true;
4535 }
4536 }
4537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
4540 return false;
4541 }
4542
shilu366312e2019-12-17 09:28:10 -08004543 /**
4544 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4545 * @param subId The subscription to use to check the configuration.
4546 * @param c The callback that will be used to send the result.
4547 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004548 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004549 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4550 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004551 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004552 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004553
4554 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4555 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4556 "IMS not available on device.");
4557 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004558 final long token = Binder.clearCallingIdentity();
4559 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004560 int slotId = getSlotIndexOrException(subId);
4561 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004562
4563 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4564 if (controller != null) {
4565 ImsManager imsManager = controller.getImsManager(subId);
4566 if (imsManager != null) {
4567 imsManager.addRegistrationCallbackForSubscription(c, subId);
4568 } else {
4569 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4570 }
4571 } else {
4572 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4573 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004574 } catch (ImsException e) {
4575 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004576 } finally {
4577 Binder.restoreCallingIdentity(token);
4578 }
4579 }
4580
shilu366312e2019-12-17 09:28:10 -08004581 /**
4582 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4583 * @param subId The subscription to use to check the configuration.
4584 * @param c The callback that will be used to send the result.
4585 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004586 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004587 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004588 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004589 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4591 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4592 }
Meng Wangafbc5852019-09-19 17:37:13 -07004593 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004594
Meng Wangafbc5852019-09-19 17:37:13 -07004595 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004596 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4597 if (controller != null) {
4598 ImsManager imsManager = controller.getImsManager(subId);
4599 if (imsManager != null) {
4600 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4601 } else {
4602 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4603 + "is inactive, ignoring unregister.");
4604 // If the ImsManager is not valid, just return, since the callback
4605 // will already have been removed internally.
4606 }
4607 }
Meng Wangafbc5852019-09-19 17:37:13 -07004608 } finally {
4609 Binder.restoreCallingIdentity(token);
4610 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004611 }
4612
Brad Ebingera34a6c22019-10-22 17:36:18 -07004613 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004614 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4615 * @param subId The subscription to use to check the configuration.
4616 * @param c The callback that will be used to send the result.
4617 */
4618 @Override
4619 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4620 throws RemoteException {
4621 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4622 mApp, subId, "registerImsEmergencyRegistrationCallback");
4623
4624 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4625 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4626 "IMS not available on device.");
4627 }
4628 final long token = Binder.clearCallingIdentity();
4629 try {
4630 int slotId = getSlotIndexOrException(subId);
4631 verifyImsMmTelConfiguredOrThrow(slotId);
4632
4633 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4634 if (controller != null) {
4635 ImsManager imsManager = controller.getImsManager(subId);
4636 if (imsManager != null) {
4637 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4638 } else {
4639 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4640 }
4641 } else {
4642 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4643 }
4644 } catch (ImsException e) {
4645 throw new ServiceSpecificException(e.getCode());
4646 } finally {
4647 Binder.restoreCallingIdentity(token);
4648 }
4649 }
4650
4651 /**
4652 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4653 * @param subId The subscription to use to check the configuration.
4654 * @param c The callback that will be used to send the result.
4655 */
4656 @Override
4657 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4658 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4659 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4660 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4661 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4662 }
4663 final long token = Binder.clearCallingIdentity();
4664
4665 try {
4666 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4667 if (controller != null) {
4668 ImsManager imsManager = controller.getImsManager(subId);
4669 if (imsManager != null) {
4670 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4671 } else {
4672 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4673 + "is inactive, ignoring unregister.");
4674 // If the ImsManager is not valid, just return, since the callback
4675 // will already have been removed internally.
4676 }
4677 }
4678 } finally {
4679 Binder.restoreCallingIdentity(token);
4680 }
4681 }
4682
4683 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004684 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4685 */
4686 @Override
4687 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4688 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4689 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4690 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4691 "IMS not available on device.");
4692 }
4693 final long token = Binder.clearCallingIdentity();
4694 try {
4695 Phone phone = getPhone(subId);
4696 if (phone == null) {
4697 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4698 + subId + "'");
4699 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4700 }
4701 phone.getImsRegistrationState(regState -> {
4702 try {
4703 consumer.accept((regState == null)
4704 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4705 } catch (RemoteException e) {
4706 // Ignore if the remote process is no longer available to call back.
4707 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4708 }
4709 });
4710 } finally {
4711 Binder.restoreCallingIdentity(token);
4712 }
4713 }
4714
4715 /**
4716 * Get the transport type for the IMS service registration state.
4717 */
4718 @Override
4719 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004720 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004721 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004722 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4723 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4724 "IMS not available on device.");
4725 }
4726 final long token = Binder.clearCallingIdentity();
4727 try {
4728 Phone phone = getPhone(subId);
4729 if (phone == null) {
4730 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4731 + subId + "'");
4732 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4733 }
4734 phone.getImsRegistrationTech(regTech -> {
4735 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4736 int regTechConverted = (regTech == null)
4737 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4738 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4739 regTechConverted);
4740 try {
4741 consumer.accept(regTechConverted);
4742 } catch (RemoteException e) {
4743 // Ignore if the remote process is no longer available to call back.
4744 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4745 }
4746 });
4747 } finally {
4748 Binder.restoreCallingIdentity(token);
4749 }
4750 }
4751
shilu366312e2019-12-17 09:28:10 -08004752 /**
4753 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4754 * @param subId The subscription to use to check the configuration.
4755 * @param c The callback that will be used to send the result.
4756 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004757 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004758 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4759 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004760 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004761 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004762 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4763 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4764 "IMS not available on device.");
4765 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004766 final long token = Binder.clearCallingIdentity();
4767 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004768 int slotId = getSlotIndexOrException(subId);
4769 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004770
4771 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4772 if (controller != null) {
4773 ImsManager imsManager = controller.getImsManager(subId);
4774 if (imsManager != null) {
4775 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4776 } else {
4777 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4778 }
4779 } else {
4780 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4781 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004782 } catch (ImsException e) {
4783 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004784 } finally {
4785 Binder.restoreCallingIdentity(token);
4786 }
4787 }
4788
shilu366312e2019-12-17 09:28:10 -08004789 /**
4790 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4791 * @param subId The subscription to use to check the configuration.
4792 * @param c The callback that will be used to send the result.
4793 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004794 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004795 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004796 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004797 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004798 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4799 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4800 }
Meng Wangafbc5852019-09-19 17:37:13 -07004801
4802 final long token = Binder.clearCallingIdentity();
4803 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004804 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4805 if (controller != null) {
4806 ImsManager imsManager = controller.getImsManager(subId);
4807 if (imsManager != null) {
4808 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4809 } else {
4810 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4811 + " is inactive, ignoring unregister.");
4812 // If the ImsManager is not valid, just return, since the callback
4813 // will already have been removed internally.
4814 }
4815 }
Meng Wangafbc5852019-09-19 17:37:13 -07004816 } finally {
4817 Binder.restoreCallingIdentity(token);
4818 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004819 }
4820
4821 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004822 public boolean isCapable(int subId, int capability, int regTech) {
4823 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004824
4825 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4826 FEATURE_TELEPHONY_IMS, "isCapable");
4827
Brad Ebinger35c841c2018-10-01 10:40:55 -07004828 final long token = Binder.clearCallingIdentity();
4829 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004830 int slotId = getSlotIndexOrException(subId);
4831 verifyImsMmTelConfiguredOrThrow(slotId);
4832 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4833 } catch (com.android.ims.ImsException e) {
4834 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4835 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004836 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004837 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4838 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004839 } finally {
4840 Binder.restoreCallingIdentity(token);
4841 }
4842 }
4843
4844 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004845 public boolean isAvailable(int subId, int capability, int regTech) {
4846 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004847
4848 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4849 FEATURE_TELEPHONY_IMS, "isAvailable");
4850
Brad Ebinger35c841c2018-10-01 10:40:55 -07004851 final long token = Binder.clearCallingIdentity();
4852 try {
4853 Phone phone = getPhone(subId);
4854 if (phone == null) return false;
4855 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004856 } catch (com.android.ims.ImsException e) {
4857 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4858 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004859 } finally {
4860 Binder.restoreCallingIdentity(token);
4861 }
4862 }
4863
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004864 /**
4865 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4866 * subscription.
4867 * @param subId The subscription to use to check the configuration.
4868 * @param callback The callback that will be used to send the result.
4869 * @param capability The MmTelFeature capability that will be used to send the result.
4870 * @param transportType The transport type of the MmTelFeature capability.
4871 */
4872 @Override
4873 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4874 int transportType) {
4875 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004876 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4877 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4878 "IMS not available on device.");
4879 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004880 final long token = Binder.clearCallingIdentity();
4881 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004882 int slotId = getSlotIndex(subId);
4883 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4884 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4885 + subId + "'");
4886 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4887 }
4888 verifyImsMmTelConfiguredOrThrow(slotId);
4889 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4890 transportType, aBoolean -> {
4891 try {
4892 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4893 } catch (RemoteException e) {
4894 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4895 + "running. Ignore");
4896 }
4897 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004898 } catch (ImsException e) {
4899 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004900 } finally {
4901 Binder.restoreCallingIdentity(token);
4902 }
4903 }
4904
shilu366312e2019-12-17 09:28:10 -08004905 /**
4906 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4907 * @param subId The subscription to use to check the configuration.
4908 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004909 @Override
4910 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004911 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004912 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004913
joonhunshin4ac60942023-11-15 15:23:39 +00004914 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4915 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4916
Brad Ebinger35c841c2018-10-01 10:40:55 -07004917 final long token = Binder.clearCallingIdentity();
4918 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004919 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004920 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004921 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004922 } catch (ImsException e) {
4923 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004924 } finally {
4925 Binder.restoreCallingIdentity(token);
4926 }
4927 }
4928
4929 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004930 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004932 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004933
4934 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4935 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4936
Brad Ebinger35c841c2018-10-01 10:40:55 -07004937 final long identity = Binder.clearCallingIdentity();
4938 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004939 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004940 // This setting doesn't require an active ImsService connection, so do not verify. The
4941 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004942 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004943 } catch (ImsException e) {
4944 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
4948 }
4949
shilu366312e2019-12-17 09:28:10 -08004950 /**
4951 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4952 * @param subId The subscription to use to check the configuration.
4953 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004954 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004955 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004956 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004957 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004958
4959 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4960 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4961
Brad Ebinger35c841c2018-10-01 10:40:55 -07004962 final long identity = Binder.clearCallingIdentity();
4963 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004964 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004965 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004966 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004967 } catch (ImsException e) {
4968 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
4972 }
4973
4974 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004975 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004977 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004978
4979 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4980 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4981
Brad Ebinger35c841c2018-10-01 10:40:55 -07004982 final long identity = Binder.clearCallingIdentity();
4983 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004984 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004985 // This setting doesn't require an active ImsService connection, so do not verify. The
4986 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004987 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004988 } catch (ImsException e) {
4989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
4993 }
4994
shilu366312e2019-12-17 09:28:10 -08004995 /**
4996 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4997 * @param subId The subscription to use to check the configuration.
4998 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004999 @Override
5000 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005001 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005002 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005003
5004 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5005 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5006
Brad Ebinger35c841c2018-10-01 10:40:55 -07005007 final long identity = Binder.clearCallingIdentity();
5008 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005009 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005010 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005011 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005012 } catch (ImsException e) {
5013 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005014 } finally {
5015 Binder.restoreCallingIdentity(identity);
5016 }
5017 }
5018
5019 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005020 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005022 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005023
5024 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5025 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5026
Brad Ebinger35c841c2018-10-01 10:40:55 -07005027 final long identity = Binder.clearCallingIdentity();
5028 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005029 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005030 // This setting doesn't require an active ImsService connection, so do not verify. The
5031 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005032 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005033 } catch (ImsException e) {
5034 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005035 } finally {
5036 Binder.restoreCallingIdentity(identity);
5037 }
5038 }
5039
shilu366312e2019-12-17 09:28:10 -08005040 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005041 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5042 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5043 * @param subId The subscription to use to check the configuration.
5044 */
5045 @Override
5046 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005047 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005048 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005049
5050 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5051 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5052
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005053 final long identity = Binder.clearCallingIdentity();
5054 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005055 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005056 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005057 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005058 } catch (ImsException e) {
5059 throw new ServiceSpecificException(e.getCode());
5060 } finally {
5061 Binder.restoreCallingIdentity(identity);
5062 }
5063 }
5064
5065 /**
5066 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5067 * Requires MODIFY_PHONE_STATE permission.
5068 * @param subId The subscription to use to check the configuration.
5069 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5070 * false otherwise
5071 */
5072 @Override
5073 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5075 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005076
5077 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5078 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5079
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005080 final long identity = Binder.clearCallingIdentity();
5081 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005082 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005083 // This setting doesn't require an active ImsService connection, so do not verify. The
5084 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005085 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005086 } catch (ImsException e) {
5087 throw new ServiceSpecificException(e.getCode());
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
5090 }
5091 }
5092
5093 /**
shilu366312e2019-12-17 09:28:10 -08005094 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5095 * @param subId The subscription to use to check the configuration.
5096 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005097 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005098
Brad Ebinger35c841c2018-10-01 10:40:55 -07005099 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005100 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005101 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005102
5103 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5104 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5105
Brad Ebinger35c841c2018-10-01 10:40:55 -07005106 final long identity = Binder.clearCallingIdentity();
5107 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005108 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005109 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005110 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005111 } catch (ImsException e) {
5112 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005113 } finally {
5114 Binder.restoreCallingIdentity(identity);
5115 }
5116 }
5117
5118 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005119 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005121 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005122
5123 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5124 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5125
Brad Ebinger35c841c2018-10-01 10:40:55 -07005126 final long identity = Binder.clearCallingIdentity();
5127 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005128 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005129 // This setting doesn't require an active ImsService connection, so do not verify. The
5130 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005131 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005132 } catch (ImsException e) {
5133 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
5137 }
5138
5139 @Override
5140 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5142 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005143
5144 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5145 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5146
Brad Ebinger35c841c2018-10-01 10:40:55 -07005147 final long identity = Binder.clearCallingIdentity();
5148 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005149 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005150 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005151 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005152 } catch (ImsException e) {
5153 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
5157 }
5158
shilu366312e2019-12-17 09:28:10 -08005159 /**
5160 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5161 * @param subId The subscription to use to check the configuration.
5162 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005163 @Override
5164 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005165 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005166 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005167
5168 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5169 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5170
Brad Ebinger35c841c2018-10-01 10:40:55 -07005171 final long identity = Binder.clearCallingIdentity();
5172 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005173 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005174 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005175 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005176 } catch (ImsException e) {
5177 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005178 } finally {
5179 Binder.restoreCallingIdentity(identity);
5180 }
5181 }
5182
5183 @Override
5184 public void setVoWiFiModeSetting(int subId, int mode) {
5185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5186 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005187
5188 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5189 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5190
Brad Ebinger35c841c2018-10-01 10:40:55 -07005191 final long identity = Binder.clearCallingIdentity();
5192 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005193 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005194 // This setting doesn't require an active ImsService connection, so do not verify. The
5195 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005196 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005197 } catch (ImsException e) {
5198 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
5202 }
5203
5204 @Override
5205 public int getVoWiFiRoamingModeSetting(int subId) {
5206 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005207
5208 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5209 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5210
Brad Ebinger35c841c2018-10-01 10:40:55 -07005211 final long identity = Binder.clearCallingIdentity();
5212 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005213 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005214 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005215 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*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 void setVoWiFiRoamingModeSetting(int subId, int mode) {
5225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5226 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005227
5228 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5229 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5230
Brad Ebinger35c841c2018-10-01 10:40:55 -07005231 final long identity = Binder.clearCallingIdentity();
5232 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005233 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005234 // This setting doesn't require an active ImsService connection, so do not verify. The
5235 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005236 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005237 } catch (ImsException e) {
5238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005239 } finally {
5240 Binder.restoreCallingIdentity(identity);
5241 }
5242 }
5243
5244 @Override
5245 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5247 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005248
5249 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5250 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5251
Brad Ebinger35c841c2018-10-01 10:40:55 -07005252 final long identity = Binder.clearCallingIdentity();
5253 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005254 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005255 // This setting doesn't require an active ImsService connection, so do not verify. The
5256 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005257 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005258 } catch (ImsException e) {
5259 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
5263 }
5264
shilu366312e2019-12-17 09:28:10 -08005265 /**
5266 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5267 * @param subId The subscription to use to check the configuration.
5268 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005269 @Override
5270 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005271 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005272 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005273
5274 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5275 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5276
Brad Ebinger35c841c2018-10-01 10:40:55 -07005277 final long identity = Binder.clearCallingIdentity();
5278 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005279 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005280 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005281 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005282 } catch (ImsException e) {
5283 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
5287 }
5288
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005289 @Override
5290 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5291 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005292
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005293 final long identity = Binder.clearCallingIdentity();
5294 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005295 if (!isImsAvailableOnDevice()) {
5296 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5297 "IMS not available on device.");
5298 }
5299 int slotId = getSlotIndexOrException(subId);
5300 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005301
5302 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5303 if (controller != null) {
5304 ImsManager imsManager = controller.getImsManager(subId);
5305 if (imsManager != null) {
5306 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5307 } else {
5308 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5309 }
5310 } else {
5311 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5312 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005313 } catch (ImsException e) {
5314 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005315 } finally {
5316 Binder.restoreCallingIdentity(identity);
5317 }
5318 }
5319
5320 @Override
5321 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5322 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005323
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005324 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005325 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5326 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5327 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005328 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005329 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5330 if (controller != null) {
5331 ImsManager imsManager = controller.getImsManager(subId);
5332 if (imsManager != null) {
5333 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5334 } else {
5335 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5336 + " is inactive, ignoring unregister.");
5337 // If the ImsManager is not valid, just return, since the callback will already
5338 // have been removed internally.
5339 }
5340 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005341 } finally {
5342 Binder.restoreCallingIdentity(identity);
5343 }
5344 }
5345
joonhunshincffb7fc2021-11-28 07:32:01 +00005346 @Override
5347 public void registerFeatureProvisioningChangedCallback(int subId,
5348 IFeatureProvisioningCallback callback) {
5349 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5350 mApp, subId, "registerFeatureProvisioningChangedCallback");
5351
5352 final long identity = Binder.clearCallingIdentity();
5353 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5354 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5355 }
5356
joonhunshin91bc1952022-04-29 08:47:15 +00005357 try {
5358 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5359 if (controller == null) {
5360 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5361 "Device does not support IMS");
5362 }
5363 controller.addFeatureProvisioningChangedCallback(subId, callback);
5364 } finally {
5365 Binder.restoreCallingIdentity(identity);
5366 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005367 }
5368
5369 @Override
5370 public void unregisterFeatureProvisioningChangedCallback(int subId,
5371 IFeatureProvisioningCallback callback) {
5372 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5373 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5374
5375 final long identity = Binder.clearCallingIdentity();
5376 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5377 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5378 }
5379
joonhunshin91bc1952022-04-29 08:47:15 +00005380 try {
5381 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5382 if (controller == null) {
5383 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5384 return;
5385 }
5386 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5387 } finally {
5388 Binder.restoreCallingIdentity(identity);
5389 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005390 }
allenwtsu99c623b2020-01-03 18:24:23 +08005391
5392 private void checkModifyPhoneStatePermission(int subId, String message) {
5393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5394 message);
5395 }
5396
allenwtsu99c623b2020-01-03 18:24:23 +08005397 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005398 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005399 boolean isProvisioned) {
5400 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5401
joonhunshin4ac60942023-11-15 15:23:39 +00005402 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5403 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5404
allenwtsu99c623b2020-01-03 18:24:23 +08005405 final long identity = Binder.clearCallingIdentity();
5406 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005407 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5408 if (controller == null) {
5409 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5410 return;
5411 }
5412 controller.setRcsProvisioningStatusForCapability(
5413 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
allenwtsu99c623b2020-01-03 18:24:23 +08005417 }
5418
5419
5420 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005421 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5422 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5423 mApp, subId, "getRcsProvisioningStatusForCapability");
5424
joonhunshin4ac60942023-11-15 15:23:39 +00005425 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5426 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5427
allenwtsu99c623b2020-01-03 18:24:23 +08005428 final long identity = Binder.clearCallingIdentity();
5429 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005430 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5431 if (controller == null) {
5432 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5433
5434 // device does not support IMS, this method will return true always.
5435 return true;
5436 }
5437 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005438 } finally {
5439 Binder.restoreCallingIdentity(identity);
5440 }
5441 }
5442
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005443 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005444 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5445 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005446 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005447
joonhunshin4ac60942023-11-15 15:23:39 +00005448 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5449 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5450
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005451 final long identity = Binder.clearCallingIdentity();
5452 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005453 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5454 if (controller == null) {
5455 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5456 return;
5457 }
5458 controller.setImsProvisioningStatusForCapability(
5459 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
5463 }
5464
5465 @Override
5466 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005467 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5468 mApp, subId, "getProvisioningStatusForCapability");
5469
joonhunshin4ac60942023-11-15 15:23:39 +00005470 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5471 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5472
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005473 final long identity = Binder.clearCallingIdentity();
5474 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005475 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5476 if (controller == null) {
5477 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005478
joonhunshin91bc1952022-04-29 08:47:15 +00005479 // device does not support IMS, this method will return true always.
5480 return true;
5481 }
5482 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
5486 }
5487
5488 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005489 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5490 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5491 mApp, subId, "isProvisioningRequiredForCapability");
5492
joonhunshin4ac60942023-11-15 15:23:39 +00005493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5494 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5495
joonhunshincffb7fc2021-11-28 07:32:01 +00005496 final long identity = Binder.clearCallingIdentity();
5497 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005498 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5499 if (controller == null) {
5500 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5501
5502 // device does not support IMS, this method will return false
5503 return false;
5504 }
5505 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005506 } finally {
5507 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005508 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005509 }
5510
5511 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005512 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5513 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5514 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005515
joonhunshin4ac60942023-11-15 15:23:39 +00005516 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5517 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5518
joonhunshincffb7fc2021-11-28 07:32:01 +00005519 final long identity = Binder.clearCallingIdentity();
5520 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005521 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5522 if (controller == null) {
5523 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5524
5525 // device does not support IMS, this method will return false
5526 return false;
5527 }
5528 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005529 } finally {
5530 Binder.restoreCallingIdentity(identity);
5531 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005532 }
5533
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005534 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005535 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005536 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5537 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5538 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005539 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5540 mApp, subId, "getImsProvisioningInt");
5541
joonhunshin4ac60942023-11-15 15:23:39 +00005542 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5543 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5544
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005545 final long identity = Binder.clearCallingIdentity();
5546 try {
5547 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005548 int slotId = getSlotIndex(subId);
5549 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5550 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5551 + subId + "' for key:" + key);
5552 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5553 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005554
joonhunshin91bc1952022-04-29 08:47:15 +00005555 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5556 if (controller == null) {
5557 loge("getImsProvisioningInt: Device does not support IMS");
5558
5559 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5560 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5561 }
5562 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005563 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5564 return retVal;
5565 }
5566
calvinpanb5a34062021-02-08 19:59:36 +08005567 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005568 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005569 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5570 + subId + "' for key:" + key);
5571 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
5575 }
5576
5577 @Override
5578 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005579 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5580 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5581 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005582 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5583 mApp, subId, "getImsProvisioningString");
5584
joonhunshin4ac60942023-11-15 15:23:39 +00005585 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5586 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5587
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005588 final long identity = Binder.clearCallingIdentity();
5589 try {
5590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005591 int slotId = getSlotIndex(subId);
5592 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5593 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5594 + subId + "' for key:" + key);
5595 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5596 }
calvinpanb5a34062021-02-08 19:59:36 +08005597 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005598 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005599 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5600 + subId + "' for key:" + key);
5601 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005602 } finally {
5603 Binder.restoreCallingIdentity(identity);
5604 }
5605 }
5606
5607 @Override
5608 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005609 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5610 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5611 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5613 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005614
joonhunshin4ac60942023-11-15 15:23:39 +00005615 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5616 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5617
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005618 final long identity = Binder.clearCallingIdentity();
5619 try {
5620 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005621 int slotId = getSlotIndex(subId);
5622 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5623 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5624 + subId + "' for key:" + key);
5625 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5626 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005627
joonhunshin91bc1952022-04-29 08:47:15 +00005628 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5629 if (controller == null) {
5630 loge("setImsProvisioningInt: Device does not support IMS");
5631
5632 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5633 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5634 }
5635 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005636 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5637 return retVal;
5638 }
5639
calvinpanb5a34062021-02-08 19:59:36 +08005640 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5641 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005642 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005643 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005644 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
5648 }
5649
5650 @Override
5651 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005652 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5653 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5654 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5656 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005657
5658 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5659 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5660
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005664 int slotId = getSlotIndex(subId);
5665 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5666 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5667 + subId + "' for key:" + key);
5668 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5669 }
calvinpanb5a34062021-02-08 19:59:36 +08005670 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5671 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005672 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005673 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005674 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
5678 }
5679
Brad Ebinger919631e2021-06-02 17:46:35 -07005680 /**
5681 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5682 * for the given slot ID or no ImsResolver instance has been created.
5683 * @param slotId The slot ID that the IMS service is created for.
5684 * @throws ImsException If there is no ImsService configured for this slot.
5685 */
5686 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5687 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5688 ImsFeature.FEATURE_MMTEL)) {
5689 throw new ImsException("This subscription does not support MMTEL over IMS",
5690 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5691 }
5692 }
5693
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005694 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005695 int slotId = SubscriptionManager.getSlotIndex(subId);
5696 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005697 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5698 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005699 }
5700 return slotId;
5701 }
5702
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005703 private int getSlotIndex(int subId) {
5704 int slotId = SubscriptionManager.getSlotIndex(subId);
5705 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5706 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5707 }
5708 return slotId;
5709 }
5710
Wink Saville36469e72014-06-11 15:17:00 -07005711 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005712 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005713 */
5714 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005715 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5716 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005717 try {
5718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5719 } catch (SecurityException se) {
5720 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5721 throw new SecurityException("Package " + callingPackage + " does not belong to "
5722 + Binder.getCallingUid());
5723 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005724 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005725 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005726 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005727 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005728 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005729 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005730 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005731 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5732 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005733
joonhunshin4ac60942023-11-15 15:23:39 +00005734 enforceTelephonyFeatureWithException(callingPackage,
5735 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737 final long identity = Binder.clearCallingIdentity();
5738 try {
5739 final Phone phone = getPhone(subId);
5740 if (phone != null) {
5741 return phone.getServiceState().getDataNetworkType();
5742 } else {
5743 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5744 }
5745 } finally {
5746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005748 }
5749
5750 /**
5751 * Returns the data network type
5752 */
5753 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005754 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005755 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005756 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005757 }
5758
5759 /**
5760 * Returns the data network type for a subId
5761 */
5762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005763 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5764 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005765 String functionName = "getDataNetworkTypeForSubscriber";
5766 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5767 mApp, functionName)) {
5768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5769 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5770 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5771 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005772 }
5773
joonhunshin4ac60942023-11-15 15:23:39 +00005774 enforceTelephonyFeatureWithException(callingPackage,
5775 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 final long identity = Binder.clearCallingIdentity();
5778 try {
5779 final Phone phone = getPhone(subId);
5780 if (phone != null) {
5781 return phone.getServiceState().getDataNetworkType();
5782 } else {
5783 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5784 }
5785 } finally {
5786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005788 }
5789
5790 /**
Wink Saville36469e72014-06-11 15:17:00 -07005791 * Returns the Voice network type for a subId
5792 */
5793 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005794 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5795 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005796 String functionName = "getVoiceNetworkTypeForSubscriber";
5797 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5798 mApp, functionName)) {
5799 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5800 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5801 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5802 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005803 }
5804
joonhunshin4ac60942023-11-15 15:23:39 +00005805 enforceTelephonyFeatureWithException(callingPackage,
5806 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 final long identity = Binder.clearCallingIdentity();
5809 try {
5810 final Phone phone = getPhone(subId);
5811 if (phone != null) {
5812 return phone.getServiceState().getVoiceNetworkType();
5813 } else {
5814 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5815 }
5816 } finally {
5817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005819 }
5820
5821 /**
5822 * @return true if a ICC card is present
5823 */
5824 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005825 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005826 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005827 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005828 }
5829
5830 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005831 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005832 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005833 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005834 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005835 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5836 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838 final long identity = Binder.clearCallingIdentity();
5839 try {
5840 final Phone phone = PhoneFactory.getPhone(slotIndex);
5841 if (phone != null) {
5842 return phone.getIccCard().hasIccCard();
5843 } else {
5844 return false;
5845 }
5846 } finally {
5847 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005848 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005849 }
5850
5851 /**
5852 * Return if the current radio is LTE on CDMA. This
5853 * is a tri-state return value as for a period of time
5854 * the mode may be unknown.
5855 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005856 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005857 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005858 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005859 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005860 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005861 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5862 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5863 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005864 }
5865
Sanket Padawe356d7632015-06-22 14:03:32 -07005866 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005867 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5868 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005869 try {
5870 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5871 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005872 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5873 }
5874
joonhunshin4ac60942023-11-15 15:23:39 +00005875 enforceTelephonyFeatureWithException(callingPackage,
5876 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5877
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005878 final long identity = Binder.clearCallingIdentity();
5879 try {
5880 final Phone phone = getPhone(subId);
5881 if (phone == null) {
5882 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5883 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005884 return TelephonyProperties.lte_on_cdma_device()
5885 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886 }
5887 } finally {
5888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005889 }
Wink Saville36469e72014-06-11 15:17:00 -07005890 }
5891
Wink Saville36469e72014-06-11 15:17:00 -07005892 /**
5893 * {@hide}
5894 * Returns Default subId, 0 in the case of single standby.
5895 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005896 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005897 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005898 }
5899
Shishir Agrawala9f32182016-04-12 12:00:16 -07005900 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005901 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005902 }
5903
Wink Savilleb564aae2014-10-23 10:18:09 -07005904 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005905 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005906 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005907
Pengquan Menge92a50d2018-09-21 15:54:48 -07005908 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005909 return getSubscriptionManagerService().isActiveSubId(subId,
5910 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005911 }
5912
Ihab Awadf2177b72013-11-25 13:33:23 -08005913 /**
5914 * @see android.telephony.TelephonyManager.WifiCallingChoices
5915 */
5916 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917 final long identity = Binder.clearCallingIdentity();
5918 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005919 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5921 getWhenToMakeWifiCallsDefaultPreference());
5922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005925 }
5926
5927 /**
5928 * @see android.telephony.TelephonyManager.WifiCallingChoices
5929 */
5930 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931 final long identity = Binder.clearCallingIdentity();
5932 try {
5933 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005934 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5936 } finally {
5937 Binder.restoreCallingIdentity(identity);
5938 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005939 }
5940
Sailesh Nepald1e68152013-12-12 19:08:02 -08005941 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005942 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005943 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005944 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005945
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005946 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5947 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5948 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005949 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005950 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005951 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005952 }
5953 return PhoneFactory.getPhone(phoneId);
5954 }
5955
Shishir Agrawal566b7612013-10-28 14:41:00 -07005956 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005957 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005958 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005959
Rambo Wanga1782702021-11-10 20:15:19 -08005960 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5961 /*message=*/ "iccOpenLogicalChannel");
5962
5963 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5964 // Verify that the callingPackage in the request belongs to the calling UID
5965 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5966
joonhunshin4ac60942023-11-15 15:23:39 +00005967 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5968 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5969
Rambo Wanga1782702021-11-10 20:15:19 -08005970 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005971 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005972
Rambo Wanga1782702021-11-10 20:15:19 -08005973 private Phone getPhoneFromValidIccLogicalChannelRequest(
5974 @NonNull IccLogicalChannelRequest request, String message) {
5975 Phone phone;
5976 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5978 mApp, request.subId, message);
5979 phone = getPhoneFromSubId(request.subId);
5980 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5981 enforceModifyPermission();
5982 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5983 } else {
5984 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005985 }
Rambo Wanga1782702021-11-10 20:15:19 -08005986 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005987 }
5988
5989 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005990 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 final long identity = Binder.clearCallingIdentity();
5992 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005993 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005995 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5996 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005997 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5998 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 loge("The calling package is not allowed to access ISD-R.");
6000 throw new SecurityException(
6001 "The calling package is not allowed to access ISD-R.");
6002 }
Derek Tan740e1672017-06-27 14:56:27 -07006003 }
Derek Tan740e1672017-06-27 14:56:27 -07006004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006006 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6007 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 return response;
6009 } finally {
6010 Binder.restoreCallingIdentity(identity);
6011 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006012 }
6013
6014 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006015 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006016 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6017 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6018
Rambo Wanga1782702021-11-10 20:15:19 -08006019 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6020 /*message=*/"iccCloseLogicalChannel");
6021
6022 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6023
6024 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006025 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006026
Rambo Wanga1782702021-11-10 20:15:19 -08006027 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6028 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006029 // before this feature is enabled, this API should only return false if
6030 // the operation fails instead of throwing runtime exception for
6031 // backward-compatibility.
6032 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6033 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 final long identity = Binder.clearCallingIdentity();
6035 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006036 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006037 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 }
Chen Xue9d737e2022-01-01 23:41:31 -08006039 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006040 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006041 Boolean success = false;
6042 if (result instanceof RuntimeException) {
6043 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006044 if (shouldThrowExceptionOnFailure) {
6045 throw (RuntimeException) result;
6046 } else {
6047 return false;
6048 }
Chen Xue9d737e2022-01-01 23:41:31 -08006049 } else if (result instanceof Boolean) {
6050 success = (Boolean) result;
6051 } else {
6052 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6053 }
Rambo Wanga1782702021-11-10 20:15:19 -08006054 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 return success;
6056 } finally {
6057 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006058 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006059 }
6060
6061 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006062 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006063 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6065 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006066
6067 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6068 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6069
Jordan Liu4c733742019-02-28 12:03:40 -08006070 if (DBG) {
6071 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6072 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6073 + p3 + " data=" + data);
6074 }
6075 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6076 command, p1, p2, p3, data);
6077 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006078
Jordan Liu4c733742019-02-28 12:03:40 -08006079 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006080 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006081 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006082 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006083
6084 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6085 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6086 "iccTransmitApduLogicalChannelBySlot");
6087
Jordan Liu4c733742019-02-28 12:03:40 -08006088 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006089 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006090 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6091 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006092 }
6093 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006094 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6095 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006096 }
6097
6098 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6099 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 final long identity = Binder.clearCallingIdentity();
6101 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006102 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006103 return "";
6104 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006107 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6108 null /* workSource */);
6109 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111 // Append the returned status code to the end of the response payload.
6112 String s = Integer.toHexString(
6113 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6114 if (response.payload != null) {
6115 s = IccUtils.bytesToHexString(response.payload) + s;
6116 }
6117 return s;
6118 } finally {
6119 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006120 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006121 }
Jake Hambye994d462014-02-03 13:10:13 -08006122
Evan Charltonc66da362014-05-16 14:06:40 -07006123 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006124 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6125 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6127 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006129
6130 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6131 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6132
Jordan Liu4c733742019-02-28 12:03:40 -08006133 if (DBG) {
6134 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6135 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6136 }
6137 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6138 cla, command, p1, p2, p3, data);
6139 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006140
Jordan Liu4c733742019-02-28 12:03:40 -08006141 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006142 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006143 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006144 enforceModifyPermission();
6145 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006146
6147 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6148 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6149
Jordan Liu4c733742019-02-28 12:03:40 -08006150 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006151 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006152 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6153 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006154 }
6155
6156 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006157 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6158 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006159 }
6160
6161 // open APDU basic channel assuming the caller has sufficient permissions
6162 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6163 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 final long identity = Binder.clearCallingIdentity();
6165 try {
6166 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6167 && TextUtils.equals(ISDR_AID, data)) {
6168 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006169 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6170 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 if (bestComponent == null
6172 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6173 loge("The calling package is not allowed to select ISD-R.");
6174 throw new SecurityException(
6175 "The calling package is not allowed to select ISD-R.");
6176 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006177 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006179 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006180 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6181 null /* workSource */);
6182 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006184 // Append the returned status code to the end of the response payload.
6185 String s = Integer.toHexString(
6186 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6187 if (response.payload != null) {
6188 s = IccUtils.bytesToHexString(response.payload) + s;
6189 }
6190 return s;
6191 } finally {
6192 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006193 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006194 }
6195
6196 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006197 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006198 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6200 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006201
joonhunshin4ac60942023-11-15 15:23:39 +00006202 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6203 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006205 final long identity = Binder.clearCallingIdentity();
6206 try {
6207 if (DBG) {
6208 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6209 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6210 }
6211
6212 IccIoResult response =
6213 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6214 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6215 subId);
6216
6217 if (DBG) {
6218 log("Exchange SIM_IO [R]" + response);
6219 }
6220
6221 byte[] result = null;
6222 int length = 2;
6223 if (response.payload != null) {
6224 length = 2 + response.payload.length;
6225 result = new byte[length];
6226 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6227 } else {
6228 result = new byte[length];
6229 }
6230
6231 result[length - 1] = (byte) response.sw2;
6232 result[length - 2] = (byte) response.sw1;
6233 return result;
6234 } finally {
6235 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006236 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006237 }
6238
Nathan Haroldb3014052017-01-25 15:57:32 -08006239 /**
6240 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6241 * on a particular subscription
6242 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006243 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6244 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006245 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006246 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006247 return null;
6248 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249
joonhunshin4ac60942023-11-15 15:23:39 +00006250 enforceTelephonyFeatureWithException(callingPackage,
6251 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253 final long identity = Binder.clearCallingIdentity();
6254 try {
6255 if (appType != TelephonyManager.APPTYPE_USIM
6256 && appType != TelephonyManager.APPTYPE_SIM) {
6257 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6258 return null;
6259 }
6260 Object response = sendRequest(
6261 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6262 if (response instanceof String[]) {
6263 return (String[]) response;
6264 }
yincheng zhao2737e882019-09-06 17:06:54 -07006265 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006267 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006268 } finally {
6269 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006270 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006271 }
6272
yincheng zhao2737e882019-09-06 17:06:54 -07006273 /**
6274 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6275 * subscription.
6276 *
6277 * @param subId the id of the subscription.
6278 * @param appType the uicc app type, must be USIM or SIM.
6279 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6280 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006281 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006282 * @return number of fplmns that is successfully written to the SIM.
6283 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006284 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6285 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6287 mApp, subId, "setForbiddenPlmns");
6288
joonhunshin4ac60942023-11-15 15:23:39 +00006289 enforceTelephonyFeatureWithException(callingPackage,
6290 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6291
yincheng zhao2737e882019-09-06 17:06:54 -07006292 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6293 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6294 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6295 }
6296 if (fplmns == null) {
6297 throw new IllegalArgumentException("Fplmn List provided is null");
6298 }
6299 for (String fplmn : fplmns) {
6300 if (!CellIdentity.isValidPlmn(fplmn)) {
6301 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6302 }
6303 }
6304 final long identity = Binder.clearCallingIdentity();
6305 try {
6306 Object response = sendRequest(
6307 CMD_SET_FORBIDDEN_PLMNS,
6308 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6309 subId);
6310 return (int) response;
6311 } finally {
6312 Binder.restoreCallingIdentity(identity);
6313 }
6314 }
6315
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006316 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006317 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6319 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006320
joonhunshin4ac60942023-11-15 15:23:39 +00006321 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6322 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 final long identity = Binder.clearCallingIdentity();
6325 try {
6326 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6327 if (response.payload == null) {
6328 return "";
6329 }
Evan Charltonc66da362014-05-16 14:06:40 -07006330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 // Append the returned status code to the end of the response payload.
6332 String s = Integer.toHexString(
6333 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6334 s = IccUtils.bytesToHexString(response.payload) + s;
6335 return s;
6336 } finally {
6337 Binder.restoreCallingIdentity(identity);
6338 }
Evan Charltonc66da362014-05-16 14:06:40 -07006339 }
6340
Jake Hambye994d462014-02-03 13:10:13 -08006341 /**
6342 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6343 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6344 *
6345 * @param itemID the ID of the item to read
6346 * @return the NV item as a String, or null on error.
6347 */
6348 @Override
6349 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006350 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6352 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353
6354 final long identity = Binder.clearCallingIdentity();
6355 try {
6356 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006357 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6359 return value;
6360 } finally {
6361 Binder.restoreCallingIdentity(identity);
6362 }
Jake Hambye994d462014-02-03 13:10:13 -08006363 }
6364
6365 /**
6366 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6367 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6368 *
6369 * @param itemID the ID of the item to read
6370 * @param itemValue the value to write, as a String
6371 * @return true on success; false on any failure
6372 */
6373 @Override
6374 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006375 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6377 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378
6379 final long identity = Binder.clearCallingIdentity();
6380 try {
6381 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6382 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006383 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6385 return success;
6386 } finally {
6387 Binder.restoreCallingIdentity(identity);
6388 }
Jake Hambye994d462014-02-03 13:10:13 -08006389 }
6390
6391 /**
6392 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6393 * Used for device configuration by some CDMA operators.
6394 *
6395 * @param preferredRoamingList byte array containing the new PRL
6396 * @return true on success; false on any failure
6397 */
6398 @Override
6399 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6401 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402
6403 final long identity = Binder.clearCallingIdentity();
6404 try {
6405 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6406 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6407 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6408 return success;
6409 } finally {
6410 Binder.restoreCallingIdentity(identity);
6411 }
Jake Hambye994d462014-02-03 13:10:13 -08006412 }
6413
6414 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006415 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006416 * Used for device configuration by some CDMA operators.
6417 *
chen xu6dac5ab2018-10-26 17:39:23 -07006418 * @param slotIndex - device slot.
6419 *
Jake Hambye994d462014-02-03 13:10:13 -08006420 * @return true on success; false on any failure
6421 */
6422 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006423 public boolean resetModemConfig(int slotIndex) {
6424 Phone phone = PhoneFactory.getPhone(slotIndex);
6425 if (phone != null) {
6426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6427 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428
joonhunshin4ac60942023-11-15 15:23:39 +00006429 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6430 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6431
chen xu6dac5ab2018-10-26 17:39:23 -07006432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6435 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6436 return success;
6437 } finally {
6438 Binder.restoreCallingIdentity(identity);
6439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 }
chen xu6dac5ab2018-10-26 17:39:23 -07006441 return false;
6442 }
6443
6444 /**
6445 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6446 *
6447 * @param slotIndex - device slot.
6448 *
6449 * @return true on success; false on any failure
6450 */
6451 @Override
6452 public boolean rebootModem(int slotIndex) {
6453 Phone phone = PhoneFactory.getPhone(slotIndex);
6454 if (phone != null) {
6455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6456 mApp, phone.getSubId(), "rebootModem");
6457
joonhunshin4ac60942023-11-15 15:23:39 +00006458 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6459 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6460
chen xu6dac5ab2018-10-26 17:39:23 -07006461 final long identity = Binder.clearCallingIdentity();
6462 try {
6463 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6464 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6465 return success;
6466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
6469 }
6470 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006471 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006472
Brad Ebinger51f743a2017-01-23 13:50:20 -08006473 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006474 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6475 * {@link #disableIms(int)}.
6476 * @param slotIndex device slot.
6477 */
6478 public void resetIms(int slotIndex) {
6479 enforceModifyPermission();
6480
joonhunshin4ac60942023-11-15 15:23:39 +00006481 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6482 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6483
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006484 final long identity = Binder.clearCallingIdentity();
6485 try {
6486 if (mImsResolver == null) {
6487 // may happen if the does not support IMS.
6488 return;
6489 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006490 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006491 } finally {
6492 Binder.restoreCallingIdentity(identity);
6493 }
6494 }
6495
6496 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006497 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6498 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006499 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006500 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006501 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006502
6503 final long identity = Binder.clearCallingIdentity();
6504 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006505 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006506 // may happen if the device does not support IMS.
6507 return;
6508 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006509 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006510 } finally {
6511 Binder.restoreCallingIdentity(identity);
6512 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006513 }
6514
6515 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006516 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6517 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006518 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006519 public void disableIms(int slotId) {
6520 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006521
6522 final long identity = Binder.clearCallingIdentity();
6523 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006524 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006525 // may happen if the device does not support IMS.
6526 return;
6527 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006528 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006532 }
6533
6534 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006535 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6536 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006537 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006538 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006539 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006540 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541
6542 final long identity = Binder.clearCallingIdentity();
6543 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006544 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006545 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6546 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006547 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006548 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 } finally {
6550 Binder.restoreCallingIdentity(identity);
6551 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006552 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006553 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006554 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6555 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006556 @Override
6557 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006558 enforceModifyPermission();
6559
6560 final long identity = Binder.clearCallingIdentity();
6561 try {
6562 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006563 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006564 } finally {
6565 Binder.restoreCallingIdentity(identity);
6566 }
6567 }
6568
6569 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006570 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006571 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006572 */
6573 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006575
6576 final long identity = Binder.clearCallingIdentity();
6577 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006578 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006579 // may happen if the device does not support IMS.
6580 return null;
6581 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006582 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 } finally {
6584 Binder.restoreCallingIdentity(identity);
6585 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006586 }
6587
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006588 /**
6589 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006590 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006591 */
6592 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6593 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594
6595 final long identity = Binder.clearCallingIdentity();
6596 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006597 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006598 // may happen if the device does not support IMS.
6599 return null;
6600 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006601 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 } finally {
6603 Binder.restoreCallingIdentity(identity);
6604 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006605 }
6606
Brad Ebinger884c07b2018-02-15 16:17:40 -08006607 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006608 * Sets the ImsService Package Name that Telephony will bind to.
6609 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006610 * @param slotIndex the slot ID that the ImsService should bind for.
6611 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006612 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006613 * @param featureTypes An integer array of feature types associated with a packageName.
6614 * @param packageName The name of the package that the current configuration will be replaced
6615 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006616 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006617 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006618 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6619 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006620 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006622 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006623
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006624 final long identity = Binder.clearCallingIdentity();
6625 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006626 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006627 // may happen if the device does not support IMS.
6628 return false;
6629 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006630 Map<Integer, String> featureConfig = new HashMap<>();
6631 for (int featureType : featureTypes) {
6632 featureConfig.put(featureType, packageName);
6633 }
6634 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6635 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636 } finally {
6637 Binder.restoreCallingIdentity(identity);
6638 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006639 }
6640
6641 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006642 * Clears any carrier ImsService overrides for the slot index specified that were previously
6643 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6644 *
6645 * This should only be used for testing.
6646 *
6647 * @param slotIndex the slot ID that the ImsService should bind for.
6648 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6649 */
6650 @Override
6651 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6653 "clearCarrierImsServiceOverride");
6654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006655 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006656
6657 final long identity = Binder.clearCallingIdentity();
6658 try {
6659 if (mImsResolver == null) {
6660 // may happen if the device does not support IMS.
6661 return false;
6662 }
6663 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6664 } finally {
6665 Binder.restoreCallingIdentity(identity);
6666 }
6667 }
6668
6669 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006670 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006671 *
6672 * @param slotId The slot that the ImsService is associated with.
6673 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6674 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006675 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006676 * @return the package name of the ImsService configuration.
6677 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006678 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6679 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006680 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006681 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6682 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684 final long identity = Binder.clearCallingIdentity();
6685 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006686 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006687 // may happen if the device does not support IMS.
6688 return "";
6689 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006690 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006691 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6692 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 } finally {
6694 Binder.restoreCallingIdentity(identity);
6695 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006696 }
6697
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006698 /**
6699 * Get the MmTelFeature state associated with the requested subscription id.
6700 * @param subId The subscription that the MmTelFeature is associated with.
6701 * @param callback A callback with an integer containing the
6702 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6703 */
6704 @Override
6705 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6706 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006707 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6708 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6709 "IMS not available on device.");
6710 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006711 final long token = Binder.clearCallingIdentity();
6712 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006713 int slotId = getSlotIndex(subId);
6714 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6715 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6716 + subId + "'");
6717 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6718 }
6719 verifyImsMmTelConfiguredOrThrow(slotId);
6720 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6721 try {
6722 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6723 } catch (RemoteException e) {
6724 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6725 + "Ignore");
6726 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006727 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006728 } catch (ImsException e) {
6729 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006730 } finally {
6731 Binder.restoreCallingIdentity(token);
6732 }
6733 }
6734
Daniel Brightbb5840b2021-01-12 15:48:18 -08006735 /**
6736 * Sets the ims registration state on all valid {@link Phone}s.
6737 */
6738 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740
6741 final long identity = Binder.clearCallingIdentity();
6742 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006743 // NOTE: Before S, this method only set the default phone.
6744 for (final Phone phone : PhoneFactory.getPhones()) {
6745 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6746 phone.setImsRegistrationState(registered);
6747 }
6748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749 } finally {
6750 Binder.restoreCallingIdentity(identity);
6751 }
Wink Saville36469e72014-06-11 15:17:00 -07006752 }
6753
6754 /**
Stuart Scott54788802015-03-30 13:18:01 -07006755 * Set the network selection mode to automatic.
6756 *
6757 */
6758 @Override
6759 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6761 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762
joonhunshin4ac60942023-11-15 15:23:39 +00006763 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6764 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766 final long identity = Binder.clearCallingIdentity();
6767 try {
shilufc958392020-01-20 11:36:01 -08006768 if (!isActiveSubscription(subId)) {
6769 return;
6770 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006772 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6773 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774 } finally {
6775 Binder.restoreCallingIdentity(identity);
6776 }
Stuart Scott54788802015-03-30 13:18:01 -07006777 }
6778
Jack Yud10cdd42020-09-28 20:28:01 -07006779 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006780 * Ask the radio to connect to the input network and change selection mode to manual.
6781 *
6782 * @param subId the id of the subscription.
6783 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6784 * the operator to attach to.
6785 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6786 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6787 * normal network selection next time.
6788 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006789 */
6790 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006791 public boolean setNetworkSelectionModeManual(
6792 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6794 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006795
joonhunshin4ac60942023-11-15 15:23:39 +00006796 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6797 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6798
Jack Yu285100e2022-12-02 22:48:35 -08006799 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006800 if (!isActiveSubscription(subId)) {
6801 return false;
6802 }
6803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006804 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006805 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006807 if (DBG) {
6808 log("setNetworkSelectionModeManual: subId: " + subId
6809 + " operator: " + operatorInfo);
6810 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6812 } finally {
6813 Binder.restoreCallingIdentity(identity);
6814 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006815 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006816 /**
shilu84f6e8b2019-12-19 13:58:01 -08006817 * Get the manual network selection
6818 *
6819 * @param subId the id of the subscription.
6820 *
6821 * @return the previously saved user selected PLMN
6822 */
6823 @Override
6824 public String getManualNetworkSelectionPlmn(int subId) {
6825 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006826 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6827 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006828
joonhunshin4ac60942023-11-15 15:23:39 +00006829 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6830 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6831
shilu84f6e8b2019-12-19 13:58:01 -08006832 final long identity = Binder.clearCallingIdentity();
6833 try {
6834 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006835 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006836 }
6837
6838 final Phone phone = getPhone(subId);
6839 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006840 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006841 }
6842 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6843 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006844 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006845 } finally {
6846 Binder.restoreCallingIdentity(identity);
6847 }
6848 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006849
6850 /**
6851 * Scans for available networks.
6852 */
6853 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006854 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6855 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6857 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006858 LocationAccessPolicy.LocationPermissionResult locationResult =
6859 LocationAccessPolicy.checkLocationPermission(mApp,
6860 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6861 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006862 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006863 .setCallingPid(Binder.getCallingPid())
6864 .setCallingUid(Binder.getCallingUid())
6865 .setMethod("getCellNetworkScanResults")
6866 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006867 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6868 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006869 .build());
6870 switch (locationResult) {
6871 case DENIED_HARD:
6872 throw new SecurityException("Not allowed to access scan results -- location");
6873 case DENIED_SOFT:
6874 return null;
6875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876
Pengquan Menga1bb6272018-09-06 09:59:22 -07006877 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006878 try {
6879 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006880 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882 } finally {
6883 Binder.restoreCallingIdentity(identity);
6884 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006885 }
6886
6887 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006888 * Get the call forwarding info, given the call forwarding reason.
6889 */
6890 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006891 public void getCallForwarding(int subId, int callForwardingReason,
6892 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006893 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006894
6895 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6896 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6897
Shuo Qian4a594052020-01-23 11:59:30 -08006898 long identity = Binder.clearCallingIdentity();
6899 try {
6900 if (DBG) {
6901 log("getCallForwarding: subId " + subId
6902 + " callForwardingReason" + callForwardingReason);
6903 }
Hall Liu27d24262020-09-18 19:04:59 -07006904
6905 Phone phone = getPhone(subId);
6906 if (phone == null) {
6907 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006908 callback.onError(
6909 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006910 } catch (RemoteException e) {
6911 // ignore
6912 }
6913 return;
6914 }
6915
6916 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6917 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6918 @Override
6919 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6920 try {
6921 callback.onCallForwardingInfoAvailable(info);
6922 } catch (RemoteException e) {
6923 // ignore
6924 }
6925 }
6926
6927 @Override
6928 public void onError(int error) {
6929 try {
6930 callback.onError(error);
6931 } catch (RemoteException e) {
6932 // ignore
6933 }
6934 }
6935 });
6936 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006937 } finally {
6938 Binder.restoreCallingIdentity(identity);
6939 }
6940 }
6941
6942 /**
6943 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6944 * reason, the number to forward, and the timeout before the forwarding is attempted.
6945 */
6946 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006947 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6948 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006949 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006950
6951 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6952 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6953
Shuo Qian4a594052020-01-23 11:59:30 -08006954 long identity = Binder.clearCallingIdentity();
6955 try {
6956 if (DBG) {
6957 log("setCallForwarding: subId " + subId
6958 + " callForwardingInfo" + callForwardingInfo);
6959 }
Hall Liu27d24262020-09-18 19:04:59 -07006960
6961 Phone phone = getPhone(subId);
6962 if (phone == null) {
6963 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006964 callback.accept(
6965 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006966 } catch (RemoteException e) {
6967 // ignore
6968 }
6969 return;
6970 }
6971
6972 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6973 FunctionalUtils.ignoreRemoteException(callback::accept));
6974
6975 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006976 } finally {
6977 Binder.restoreCallingIdentity(identity);
6978 }
6979 }
6980
6981 /**
Hall Liu27d24262020-09-18 19:04:59 -07006982 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006983 */
6984 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006985 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006986 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006987
6988 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6989 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6990
Shuo Qian4a594052020-01-23 11:59:30 -08006991 long identity = Binder.clearCallingIdentity();
6992 try {
Hall Liu27d24262020-09-18 19:04:59 -07006993 Phone phone = getPhone(subId);
6994 if (phone == null) {
6995 try {
6996 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6997 } catch (RemoteException e) {
6998 // ignore
6999 }
7000 return;
7001 }
SongFerngWang0e767992021-03-31 22:08:45 +08007002 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7003 PersistableBundle c = configManager.getConfigForSubId(subId);
7004 boolean requireUssd = c.getBoolean(
7005 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007006
Shuo Qian4a594052020-01-23 11:59:30 -08007007 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007008 if (requireUssd) {
7009 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7010 getSubscriptionCarrierId(subId));
7011 String newUssdCommand = "";
7012 try {
7013 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007014 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007015 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7016 } catch (NullPointerException e) {
7017 loge("Failed to generate USSD number" + e);
7018 }
7019 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7020 mMainThreadHandler, callback, carrierXmlParser,
7021 CarrierXmlParser.SsEntry.SSAction.QUERY);
7022 final String ussdCommand = newUssdCommand;
7023 Executors.newSingleThreadExecutor().execute(() -> {
7024 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7025 });
7026 } else {
7027 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7028 callback::accept);
7029 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7030 }
Shuo Qian4a594052020-01-23 11:59:30 -08007031 } finally {
7032 Binder.restoreCallingIdentity(identity);
7033 }
7034 }
7035
7036 /**
Hall Liu27d24262020-09-18 19:04:59 -07007037 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007038 */
7039 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007040 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007041 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007042
7043 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7044 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7045
Shuo Qian4a594052020-01-23 11:59:30 -08007046 long identity = Binder.clearCallingIdentity();
7047 try {
Hall Liu27d24262020-09-18 19:04:59 -07007048 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7049
7050 Phone phone = getPhone(subId);
7051 if (phone == null) {
7052 try {
7053 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7054 } catch (RemoteException e) {
7055 // ignore
7056 }
7057 return;
7058 }
7059
SongFerngWang0e767992021-03-31 22:08:45 +08007060 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7061 PersistableBundle c = configManager.getConfigForSubId(subId);
7062 boolean requireUssd = c.getBoolean(
7063 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007064
SongFerngWang0e767992021-03-31 22:08:45 +08007065 if (DBG) log("getCallWaitingStatus: subId " + subId);
7066 if (requireUssd) {
7067 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7068 getSubscriptionCarrierId(subId));
7069 CarrierXmlParser.SsEntry.SSAction ssAction =
7070 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7071 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7072 String newUssdCommand = "";
7073 try {
7074 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007075 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007076 .makeCommand(ssAction, null);
7077 } catch (NullPointerException e) {
7078 loge("Failed to generate USSD number" + e);
7079 }
7080 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7081 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7082 final String ussdCommand = newUssdCommand;
7083 Executors.newSingleThreadExecutor().execute(() -> {
7084 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7085 });
7086 } else {
7087 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7088 FunctionalUtils.ignoreRemoteException(callback::accept));
7089
7090 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7091 }
Shuo Qian4a594052020-01-23 11:59:30 -08007092 } finally {
7093 Binder.restoreCallingIdentity(identity);
7094 }
7095 }
7096
7097 /**
yinxub1bed742017-04-17 11:45:04 -07007098 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007099 *
yinxub1bed742017-04-17 11:45:04 -07007100 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007101 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7102 * location related information which will be sent if the caller already possess
7103 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007104 * @param request contains the radio access networks with bands/channels to scan
7105 * @param messenger callback messenger for scan results or errors
7106 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007107 * @return the id of the requested scan which can be used to stop the scan.
7108 */
7109 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007110 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7111 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007112 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7114 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007115 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007116 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7117 if (!renounceFineLocationAccess) {
7118 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007119 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7120 .setCallingPackage(callingPackage)
7121 .setCallingFeatureId(callingFeatureId)
7122 .setCallingPid(Binder.getCallingPid())
7123 .setCallingUid(Binder.getCallingUid())
7124 .setMethod("requestNetworkScan")
7125 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7126 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7127 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7128 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007129 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007130 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007131 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7132 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007133 if (e != null) {
7134 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7135 throw e;
7136 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007137 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007138 return TelephonyScanManager.INVALID_SCAN_ID;
7139 }
7140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 }
joonhunshin4ac60942023-11-15 15:23:39 +00007142
7143 enforceTelephonyFeatureWithException(callingPackage,
7144 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7145
Hall Liu912dfd32019-04-25 14:02:26 -07007146 int callingUid = Binder.getCallingUid();
7147 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007148 final long identity = Binder.clearCallingIdentity();
7149 try {
7150 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007151 renounceFineLocationAccess, request, messenger, binder,
7152 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007153 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007154 } finally {
7155 Binder.restoreCallingIdentity(identity);
7156 }
yinxu504e1392017-04-12 16:03:22 -07007157 }
7158
Hall Liub2ac8ef2019-02-28 15:56:23 -08007159 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007160 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007161 boolean hasCarrierPriv;
7162 final long identity = Binder.clearCallingIdentity();
7163 try {
7164 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7165 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7166 } finally {
7167 Binder.restoreCallingIdentity(identity);
7168 }
Hall Liu558027f2019-05-15 19:14:05 -07007169 boolean hasNetworkScanPermission =
7170 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007171 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007172
7173 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7174 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7175 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007176 }
7177
7178 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7179 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007180 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7181 return new SecurityException("Specific channels must not be"
7182 + " scanned without location access.");
7183 }
7184 }
7185 }
7186
Hall Liub2ac8ef2019-02-28 15:56:23 -08007187 return null;
7188 }
7189
yinxu504e1392017-04-12 16:03:22 -07007190 /**
7191 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007192 *
7193 * @param subId id of the subscription
7194 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007195 */
7196 @Override
7197 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7199 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200
Hall Liu912dfd32019-04-25 14:02:26 -07007201 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 final long identity = Binder.clearCallingIdentity();
7203 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007204 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205 } finally {
7206 Binder.restoreCallingIdentity(identity);
7207 }
yinxu504e1392017-04-12 16:03:22 -07007208 }
7209
7210 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007211 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007212 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007213 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007214 */
7215 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007216 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007217 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007218 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007219 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007220
joonhunshin4ac60942023-11-15 15:23:39 +00007221 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7222 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 final long identity = Binder.clearCallingIdentity();
7225 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007226 if (DBG) log("getAllowedNetworkTypesBitmask");
7227 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7228 int networkTypesBitmask = (result != null ? result[0] : -1);
7229 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7230 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231 } finally {
7232 Binder.restoreCallingIdentity(identity);
7233 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007234 }
7235
7236 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007237 * Get the allowed network types for certain reason.
7238 *
7239 * @param subId the id of the subscription.
7240 * @param reason the reason the allowed network type change is taking place
7241 * @return the allowed network types.
7242 */
7243 @Override
7244 public long getAllowedNetworkTypesForReason(int subId,
7245 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007246 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007247 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007248
7249 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7250 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7251
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007252 final long identity = Binder.clearCallingIdentity();
7253 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007254 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007255 } finally {
7256 Binder.restoreCallingIdentity(identity);
7257 }
7258 }
7259
7260 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007261 * Enable/Disable E-UTRA-NR Dual Connectivity
7262 * @param subId subscription id of the sim card
7263 * @param nrDualConnectivityState expected NR dual connectivity state
7264 * This can be passed following states
7265 * <ol>
7266 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7267 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7268 * <li>Disable NR dual connectivity and force secondary cell to be released
7269 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7270 * </ol>
7271 * @return operation result.
7272 */
7273 @Override
7274 public int setNrDualConnectivityState(int subId,
7275 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7277 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007278 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007279 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7280 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7281 }
7282
Sooraj Sasindran37444802020-08-11 10:40:43 -07007283 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7284 final long identity = Binder.clearCallingIdentity();
7285 try {
7286 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7287 nrDualConnectivityState, subId,
7288 workSource);
7289 if (DBG) log("enableNRDualConnectivity result: " + result);
7290 return result;
7291 } finally {
7292 Binder.restoreCallingIdentity(identity);
7293 }
7294 }
7295
7296 /**
7297 * Is E-UTRA-NR Dual Connectivity enabled
7298 * @return true if dual connectivity is enabled else false
7299 */
7300 @Override
7301 public boolean isNrDualConnectivityEnabled(int subId) {
7302 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007303 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007304 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007305 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007306 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7307 return false;
7308 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7310 final long identity = Binder.clearCallingIdentity();
7311 try {
7312 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7313 null, subId, workSource);
7314 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7315 return isEnabled;
7316 } finally {
7317 Binder.restoreCallingIdentity(identity);
7318 }
7319 }
7320
7321 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007322 * Set the allowed network types of the device and
7323 * provide the reason triggering the allowed network change.
7324 *
7325 * @param subId the id of the subscription.
7326 * @param reason the reason the allowed network type change is taking place
7327 * @param allowedNetworkTypes the allowed network types.
7328 * @return true on success; false on any failure.
7329 */
7330 @Override
7331 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007332 @TelephonyManager.AllowedNetworkTypesReason int reason,
7333 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7335 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007336 // If the caller only has carrier privileges, then they should not be able to override
7337 // any network types which were set for security reasons.
7338 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7339 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007340 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007341 throw new SecurityException(
7342 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007343 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007344 }
joonhunshin4ac60942023-11-15 15:23:39 +00007345
7346 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7347 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7348
SongFerngWang3ef3e072020-12-21 16:41:52 +08007349 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007350 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007351 return false;
7352 }
7353 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7354 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007355 return false;
7356 }
7357
Jack Yu5b494332023-01-23 18:18:04 +00007358 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7359 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007360
Jack Yue37dd262022-12-16 11:53:37 -08007361 Phone phone = getPhone(subId);
7362 if (phone == null) {
7363 return false;
7364 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007365
Jack Yue37dd262022-12-16 11:53:37 -08007366 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007367 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007368 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007369 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007370
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007371 final long identity = Binder.clearCallingIdentity();
7372 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007373 Boolean success = (Boolean) sendRequest(
7374 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7375 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7376
7377 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7378 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007379 } finally {
7380 Binder.restoreCallingIdentity(identity);
7381 }
7382 }
7383
7384 /**
Miaoa84611c2019-03-15 09:21:10 +08007385 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007386 *
Miaoa84611c2019-03-15 09:21:10 +08007387 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007388 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007389 * @hide
7390 */
7391 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007392 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007393 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007394
7395 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7396 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007399 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400 try {
Miaoa84611c2019-03-15 09:21:10 +08007401 if (phone != null) {
7402 return phone.hasMatchedTetherApnSetting();
7403 } else {
7404 return false;
7405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 } finally {
7407 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007408 }
Junda Liu475951f2014-11-07 16:45:03 -08007409 }
7410
7411 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007412 * Get the user enabled state of Mobile Data.
7413 *
7414 * TODO: remove and use isUserDataEnabled.
7415 * This can't be removed now because some vendor codes
7416 * calls through ITelephony directly while they should
7417 * use TelephonyManager.
7418 *
7419 * @return true on enabled
7420 */
7421 @Override
7422 public boolean getDataEnabled(int subId) {
7423 return isUserDataEnabled(subId);
7424 }
7425
7426 /**
7427 * Get whether mobile data is enabled per user setting.
7428 *
7429 * There are other factors deciding whether mobile data is actually enabled, but they are
7430 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007431 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007432 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7433 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007434 *
7435 * @return {@code true} if data is enabled else {@code false}
7436 */
7437 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007438 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007439 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007440 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007441 try {
7442 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7443 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007444 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007445 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7446 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007447 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007449 mApp, subId, functionName);
7450
Robert Greenwalt646120a2014-05-23 11:54:03 -07007451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452
7453 final long identity = Binder.clearCallingIdentity();
7454 try {
Jack Yu285100e2022-12-02 22:48:35 -08007455 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7457 Phone phone = PhoneFactory.getPhone(phoneId);
7458 if (phone != null) {
7459 boolean retVal = phone.isUserDataEnabled();
7460 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7461 return retVal;
7462 } else {
7463 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7464 return false;
7465 }
7466 } finally {
7467 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007468 }
7469 }
7470
7471 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007472 * Checks if the device is capable of mobile data by considering whether whether the
7473 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7474 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007475 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007476 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007477 */
7478 @Override
7479 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007480 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007481 try {
7482 try {
7483 mApp.enforceCallingOrSelfPermission(
7484 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007485 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007486 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007487 try {
7488 mApp.enforceCallingOrSelfPermission(
7489 android.Manifest.permission.READ_PHONE_STATE,
7490 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007491 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007492 mApp.enforceCallingOrSelfPermission(
7493 permission.READ_BASIC_PHONE_STATE, functionName);
7494 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007495 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007496 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007497 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499
joonhunshin4ac60942023-11-15 15:23:39 +00007500 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7501 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 final long identity = Binder.clearCallingIdentity();
7504 try {
Jack Yu285100e2022-12-02 22:48:35 -08007505 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007506 Phone phone = PhoneFactory.getPhone(phoneId);
7507 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007508 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007509 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510 return retVal;
7511 } else {
7512 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7513 return false;
7514 }
7515 } finally {
7516 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007517 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007518 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007519
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007520 /**
7521 * Check if data is enabled for a specific reason
7522 * @param subId Subscription index
7523 * @param reason the reason the data enable change is taking place
7524 * @return {@code true} if the overall data is enabled; {@code false} if not.
7525 */
7526 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007527 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007528 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007529 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007530 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007531 try {
7532 mApp.enforceCallingOrSelfPermission(
7533 android.Manifest.permission.ACCESS_NETWORK_STATE,
7534 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007535 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007536 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7537 functionName);
7538 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007539 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007540 try {
7541 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007542 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007543 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007545 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007546 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007547 }
7548
joonhunshin4ac60942023-11-15 15:23:39 +00007549 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7550 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007551
7552 final long identity = Binder.clearCallingIdentity();
7553 try {
Jack Yu285100e2022-12-02 22:48:35 -08007554 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007555 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007556 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007557 + " reason=" + reason);
7558 }
7559 Phone phone = PhoneFactory.getPhone(phoneId);
7560 if (phone != null) {
7561 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007562 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007563 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007564 return retVal;
7565 } else {
7566 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007567 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007568 + subId + " retVal=false");
7569 }
7570 return false;
7571 }
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
7575 }
7576
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007577 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007578 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007579 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7580 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7581
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007582 // No permission needed; this only lets the caller inspect their own status.
7583 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007584 }
Junda Liu29340342014-07-10 15:23:27 -07007585
7586 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007587 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007588 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007589
7590 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7591 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7592
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007593 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7594 }
7595
7596 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7597 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007598 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007599 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007600 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7601 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007602 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7603 if (cpt == null) {
7604 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007605 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7606 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007607 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007608 }
7609
7610 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007611 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007612 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007613
7614 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7615 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7616
chen xuf7e9fe82019-05-09 19:31:02 -07007617 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007618 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007619 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007620 Phone phone = getPhone(subId);
7621 if (phone == null) {
7622 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7623 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7624 }
7625 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7626 if (cpt == null) {
7627 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007628 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7629 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007630 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007631 }
7632
7633 @Override
7634 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007635 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007636
7637 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7638 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7639 "checkCarrierPrivilegesForPackageAnyPhone");
7640
Rambo Wange7209ce2022-02-23 13:41:02 -08007641 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7642 }
7643
7644 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007645 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007646 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007647 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007648 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007649 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7650 Phone phone = PhoneFactory.getPhone(phoneId);
7651 if (phone == null) {
7652 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007653 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007654 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7655 if (cpt == null) {
7656 continue;
7657 }
7658 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007659 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7660 break;
7661 }
7662 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007663 return result;
Junda Liu29340342014-07-10 15:23:27 -07007664 }
Derek Tan89e89d42014-07-08 17:00:10 -07007665
7666 @Override
Junda Liue64de782015-04-16 17:19:16 -07007667 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007668 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007669
7670 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7671 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7672 "getCarrierPackageNamesForIntentAndPhone");
7673
Rambo Wang8a247eb2022-02-08 21:11:18 +00007674 Phone phone = PhoneFactory.getPhone(phoneId);
7675 if (phone == null) {
7676 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007677 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007678 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7679 if (cpt == null) {
7680 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007681 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007682 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007683 }
7684
Amith Yamasani6e118872016-02-19 12:53:51 -08007685 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007686 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007687 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007688 Phone phone = PhoneFactory.getPhone(phoneId);
7689 if (phone == null) {
7690 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007691 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007692 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7693 if (cpt == null) {
7694 return Collections.emptyList();
7695 }
7696 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007697 }
7698
chen xuf7e9fe82019-05-09 19:31:02 -07007699 @Override
7700 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007701 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007702
7703 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7704 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7705 "getPackagesWithCarrierPrivilegesForAllPhones");
7706
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007707 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007708 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007709 try {
7710 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7711 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7712 }
7713 } finally {
7714 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007715 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007716 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007717 }
7718
Rambo Wang6812ffb2022-03-15 16:54:17 -07007719 @Override
7720 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7721 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7722
joonhunshin4ac60942023-11-15 15:23:39 +00007723 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7724 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7725 "getCarrierServicePackageNameForLogicalSlot");
7726
Rambo Wang6812ffb2022-03-15 16:54:17 -07007727 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7728 if (phone == null) {
7729 return null;
7730 }
7731 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7732 if (cpt == null) {
7733 return null;
7734 }
7735 return cpt.getCarrierServicePackageName();
7736 }
7737
Wink Savilleb564aae2014-10-23 10:18:09 -07007738 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007739 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007740 UiccPort port = phone == null ? null : phone.getUiccPort();
7741 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007742 return null;
7743 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007744 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007745 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007746 return null;
7747 }
7748 return iccId;
7749 }
7750
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007751 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007752 public void setCallComposerStatus(int subId, int status) {
7753 enforceModifyPermission();
7754
joonhunshin4ac60942023-11-15 15:23:39 +00007755 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7756 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7757
Shuo Qiane4e11672020-12-15 22:15:33 -08007758 final long identity = Binder.clearCallingIdentity();
7759 try {
7760 Phone phone = getPhone(subId);
7761 if (phone != null) {
7762 Phone defaultPhone = phone.getImsPhone();
7763 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7764 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7765 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007766 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7767 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007768 }
7769 }
Shuo Qian284ae752020-12-22 19:10:14 -08007770 } catch (ImsException e) {
7771 throw new ServiceSpecificException(e.getCode());
7772 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007773 Binder.restoreCallingIdentity(identity);
7774 }
7775 }
7776
7777 @Override
7778 public int getCallComposerStatus(int subId) {
7779 enforceReadPrivilegedPermission("getCallComposerStatus");
7780
joonhunshin4ac60942023-11-15 15:23:39 +00007781 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7782 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7783
Shuo Qiane4e11672020-12-15 22:15:33 -08007784 final long identity = Binder.clearCallingIdentity();
7785 try {
7786 Phone phone = getPhone(subId);
7787 if (phone != null) {
7788 Phone defaultPhone = phone.getImsPhone();
7789 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7790 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7791 return imsPhone.getCallComposerStatus();
7792 }
7793 }
7794 } finally {
7795 Binder.restoreCallingIdentity(identity);
7796 }
7797 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7798 }
7799
7800 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007801 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7802 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007803 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007804 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007805
joonhunshin4ac60942023-11-15 15:23:39 +00007806 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7807 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7808 "setLine1NumberForDisplayForSubscriber");
7809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810 final long identity = Binder.clearCallingIdentity();
7811 try {
7812 final String iccId = getIccId(subId);
7813 final Phone phone = getPhone(subId);
7814 if (phone == null) {
7815 return false;
7816 }
7817 final String subscriberId = phone.getSubscriberId();
7818
7819 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007820 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007821 + subscriberId + " to " + number);
7822 }
7823
7824 if (TextUtils.isEmpty(iccId)) {
7825 return false;
7826 }
7827
7828 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7829
7830 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7831 if (alphaTag == null) {
7832 editor.remove(alphaTagPrefKey);
7833 } else {
7834 editor.putString(alphaTagPrefKey, alphaTag);
7835 }
7836
7837 // Record both the line number and IMSI for this ICCID, since we need to
7838 // track all merged IMSIs based on line number
7839 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7840 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7841 if (number == null) {
7842 editor.remove(numberPrefKey);
7843 editor.remove(subscriberPrefKey);
7844 } else {
7845 editor.putString(numberPrefKey, number);
7846 editor.putString(subscriberPrefKey, subscriberId);
7847 }
7848
7849 editor.commit();
7850 return true;
7851 } finally {
7852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007853 }
Derek Tan7226c842014-07-02 17:42:23 -07007854 }
7855
7856 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007857 public String getLine1NumberForDisplay(int subId, String callingPackage,
7858 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007859 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007860 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007861 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007862 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007863 return null;
7864 }
Derek Tan97ebb422014-09-05 16:55:38 -07007865
joonhunshin4ac60942023-11-15 15:23:39 +00007866 enforceTelephonyFeatureWithException(callingPackage,
7867 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007869 final long identity = Binder.clearCallingIdentity();
7870 try {
7871 String iccId = getIccId(subId);
7872 if (iccId != null) {
7873 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7874 if (DBG_MERGE) {
7875 log("getLine1NumberForDisplay returning "
7876 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7877 }
7878 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007880 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7881 return null;
7882 } finally {
7883 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007884 }
Derek Tan7226c842014-07-02 17:42:23 -07007885 }
7886
7887 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007888 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7889 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007891 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007892 return null;
7893 }
Derek Tan97ebb422014-09-05 16:55:38 -07007894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007895 final long identity = Binder.clearCallingIdentity();
7896 try {
7897 String iccId = getIccId(subId);
7898 if (iccId != null) {
7899 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7900 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7901 }
7902 return null;
7903 } finally {
7904 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007905 }
Derek Tan7226c842014-07-02 17:42:23 -07007906 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007907
7908 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007909 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7910 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007911 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7912 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007913 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007914 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007915 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007916 return null;
7917 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007918
Jordan Liub49b04b2019-05-06 14:45:15 -07007919 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7920 // the process, where TelephonyManager was instantiated.
7921 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007922 final long identity = Binder.clearCallingIdentity();
7923 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007924 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 final TelephonyManager tele = TelephonyManager.from(context);
7926 final SubscriptionManager sub = SubscriptionManager.from(context);
7927
7928 // Figure out what subscribers are currently active
7929 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930
Jordan Liub49b04b2019-05-06 14:45:15 -07007931 // Only consider subs which match the current subId
7932 // This logic can be simplified. See b/131189269 for progress.
7933 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007934 activeSubscriberIds.add(tele.getSubscriberId(subId));
7935 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936
7937 // First pass, find a number override for an active subscriber
7938 String mergeNumber = null;
7939 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7940 for (String key : prefs.keySet()) {
7941 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7942 final String subscriberId = (String) prefs.get(key);
7943 if (activeSubscriberIds.contains(subscriberId)) {
7944 final String iccId = key.substring(
7945 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7946 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7947 mergeNumber = (String) prefs.get(numberKey);
7948 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007949 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007950 + " for active subscriber " + subscriberId);
7951 }
7952 if (!TextUtils.isEmpty(mergeNumber)) {
7953 break;
7954 }
7955 }
7956 }
7957 }
7958
7959 // Shortcut when no active merged subscribers
7960 if (TextUtils.isEmpty(mergeNumber)) {
7961 return null;
7962 }
7963
7964 // Second pass, find all subscribers under that line override
7965 final ArraySet<String> result = new ArraySet<>();
7966 for (String key : prefs.keySet()) {
7967 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7968 final String number = (String) prefs.get(key);
7969 if (mergeNumber.equals(number)) {
7970 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7971 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7972 final String subscriberId = (String) prefs.get(subscriberKey);
7973 if (!TextUtils.isEmpty(subscriberId)) {
7974 result.add(subscriberId);
7975 }
7976 }
7977 }
7978 }
7979
7980 final String[] resultArray = result.toArray(new String[result.size()]);
7981 Arrays.sort(resultArray);
7982 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007983 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007984 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7985 }
7986 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007987 } finally {
7988 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007989 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007990 }
7991
7992 @Override
zoey chen38003472019-12-13 17:16:31 +08007993 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7994 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007995
joonhunshin4ac60942023-11-15 15:23:39 +00007996 enforceTelephonyFeatureWithException(callingPackage,
7997 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7998
Malcolm Chen6ca97372019-07-01 16:28:21 -07007999 final long identity = Binder.clearCallingIdentity();
8000 try {
8001 final TelephonyManager telephonyManager = mApp.getSystemService(
8002 TelephonyManager.class);
8003 String subscriberId = telephonyManager.getSubscriberId(subId);
8004 if (subscriberId == null) {
8005 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008006 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008007 + subId);
8008 }
8009 return null;
8010 }
8011
Jack Yu3beaf9d2023-04-14 09:17:27 -07008012 final SubscriptionInfo info = getSubscriptionManagerService()
8013 .getSubscriptionInfo(subId);
8014 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008015 // If it doesn't belong to any group, return just subscriberId of itself.
8016 if (groupUuid == null) {
8017 return new String[]{subscriberId};
8018 }
8019
8020 // Get all subscriberIds from the group.
8021 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008022 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8023 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8024 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008025 for (SubscriptionInfo subInfo : groupInfos) {
8026 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8027 if (subscriberId != null) {
8028 mergedSubscriberIds.add(subscriberId);
8029 }
8030 }
8031
8032 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8033 } finally {
8034 Binder.restoreCallingIdentity(identity);
8035
8036 }
8037 }
8038
8039 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008040 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008041 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008042 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008043
joonhunshin4ac60942023-11-15 15:23:39 +00008044 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8045 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 final long identity = Binder.clearCallingIdentity();
8048 try {
8049 final Phone phone = getPhone(subId);
8050 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8051 } finally {
8052 Binder.restoreCallingIdentity(identity);
8053 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008054 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008055
8056 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008057 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008058 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8059 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008060 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8061 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008062
8063 final long identity = Binder.clearCallingIdentity();
8064 try {
8065 final Phone phone = getPhone(subId);
8066 if (phone == null) {
8067 return false;
8068 }
8069 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8070 cdmaNonRoamingList);
8071 } finally {
8072 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008073 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008074 }
8075
8076 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008077 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008078 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008079 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008080 if (phone == null) {
8081 return raf;
8082 }
8083
Shuo Qiandee53402020-05-29 14:08:15 -07008084 try {
8085 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008086 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008087 mApp, phone.getSubId(), "getRadioAccessFamily");
8088 } catch (SecurityException e) {
8089 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8090 throw e;
8091 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008092
joonhunshin4ac60942023-11-15 15:23:39 +00008093 enforceTelephonyFeatureWithException(callingPackage,
8094 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008096 final long identity = Binder.clearCallingIdentity();
8097 try {
chen xub97461a2018-10-26 14:17:57 -07008098 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008099 } finally {
8100 Binder.restoreCallingIdentity(identity);
8101 }
chen xub97461a2018-10-26 14:17:57 -07008102 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008103 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008104
8105 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008106 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008107 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008108 try {
8109 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8110 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008111 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008112 }
8113 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008114 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008115 }
joonhunshin4ac60942023-11-15 15:23:39 +00008116
8117 enforceTelephonyFeatureWithException(callingPackage,
8118 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8119
Hall Liu82694d52020-12-11 18:22:04 -08008120 RoleManager rm = mApp.getSystemService(RoleManager.class);
8121 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8122 if (!dialerRoleHolders.contains(callingPackage)) {
8123 throw new SecurityException("App must be the dialer role holder to"
8124 + " upload a call composer pic");
8125 }
8126
8127 Executors.newSingleThreadExecutor().execute(() -> {
8128 ByteArrayOutputStream output = new ByteArrayOutputStream(
8129 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8130 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8131 boolean readUntilEnd = false;
8132 int totalBytesRead = 0;
8133 byte[] buffer = new byte[16 * 1024];
8134 while (true) {
8135 int numRead;
8136 try {
8137 numRead = input.read(buffer);
8138 } catch (IOException e) {
8139 try {
8140 fd.checkError();
8141 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8142 null);
8143 } catch (IOException e1) {
8144 // This means that the other side closed explicitly with an error. If this
8145 // happens, log and ignore.
8146 loge("Remote end of call composer picture pipe closed: " + e1);
8147 }
8148 break;
8149 }
8150 if (numRead == -1) {
8151 readUntilEnd = true;
8152 break;
8153 }
8154 totalBytesRead += numRead;
8155 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8156 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8157 try {
8158 input.close();
8159 } catch (IOException e) {
8160 // ignore
8161 }
8162 break;
8163 }
8164 output.write(buffer, 0, numRead);
8165 }
8166 // Generally, the remote end will close the file descriptors. The only case where we
8167 // close is above, where the picture size is too big.
8168
8169 try {
8170 fd.checkError();
8171 } catch (IOException e) {
8172 loge("Remote end for call composer closed with an error: " + e);
8173 return;
8174 }
8175
Hall Liuaa4211e2021-01-20 15:43:39 -08008176 if (!readUntilEnd) {
8177 loge("Did not finish reading entire image; aborting");
8178 return;
8179 }
Hall Liu82694d52020-12-11 18:22:04 -08008180
Hall Liuaa4211e2021-01-20 15:43:39 -08008181 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8182 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8183 new CallComposerPictureTransfer.Factory() {},
8184 imageData,
8185 (result) -> {
8186 if (result.first != null) {
8187 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8188 Bundle outputResult = new Bundle();
8189 outputResult.putParcelable(
8190 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8191 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8192 outputResult);
8193 } else {
8194 callback.send(result.second, null);
8195 }
8196 }
8197 );
Hall Liu82694d52020-12-11 18:22:04 -08008198 });
8199 }
8200
8201 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008202 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008203 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008204 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008205
joonhunshin4ac60942023-11-15 15:23:39 +00008206 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8207 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209 final long identity = Binder.clearCallingIdentity();
8210 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008211 ImsManager.getInstance(defaultPhone.getContext(),
8212 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008213 } finally {
8214 Binder.restoreCallingIdentity(identity);
8215 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008216 }
8217
8218 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008219 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008220 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8222 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008223 return false;
8224 }
Svet Ganovb320e182015-04-16 12:30:10 -07008225
joonhunshin4ac60942023-11-15 15:23:39 +00008226 enforceTelephonyFeatureWithException(callingPackage,
8227 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008229 final long identity = Binder.clearCallingIdentity();
8230 try {
8231 // Check the user preference and the system-level IMS setting. Even if the user has
8232 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8233 // In the long run, we may instead need to check if there exists a connection service
8234 // which can support video calling.
8235 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008236 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008237 return imsManager.isVtEnabledByPlatform()
8238 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8239 && imsManager.isVtEnabledByUser();
8240 } finally {
8241 Binder.restoreCallingIdentity(identity);
8242 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008243 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008244
Andrew Leea1239f22015-03-02 17:44:07 -08008245 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008246 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8247 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008249 mApp, subId, callingPackage, callingFeatureId,
8250 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251 return false;
8252 }
8253
joonhunshin4ac60942023-11-15 15:23:39 +00008254 enforceTelephonyFeatureWithException(callingPackage,
8255 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 final long identity = Binder.clearCallingIdentity();
8258 try {
8259 CarrierConfigManager configManager =
8260 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008261 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008262 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8263 } finally {
8264 Binder.restoreCallingIdentity(identity);
8265 }
Andrew Leea1239f22015-03-02 17:44:07 -08008266 }
8267
8268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008269 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008271 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008272 return false;
8273 }
8274
joonhunshin4ac60942023-11-15 15:23:39 +00008275 enforceTelephonyFeatureWithException(callingPackage,
8276 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 final long identity = Binder.clearCallingIdentity();
8279 try {
8280 CarrierConfigManager configManager =
8281 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008282 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8284 } finally {
8285 Binder.restoreCallingIdentity(identity);
8286 }
Andrew Leea1239f22015-03-02 17:44:07 -08008287 }
8288
Andrew Lee9431b832015-03-09 18:46:45 -07008289 @Override
8290 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008291 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008292 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008293 }
8294
8295 @Override
8296 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008297 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8298 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 final long identity = Binder.clearCallingIdentity();
8301 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008302 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 } finally {
8304 Binder.restoreCallingIdentity(identity);
8305 }
Andrew Lee9431b832015-03-09 18:46:45 -07008306 }
8307
Hall Liuf6668912018-10-31 17:05:23 -07008308 /**
8309 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8310 * support for the feature and device firmware support.
8311 *
8312 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8313 */
8314 @Override
8315 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008316 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8317 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008319 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008320 final Phone phone = getPhone(subscriptionId);
8321 if (phone == null) {
8322 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8323 return false;
8324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008325 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008326 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008328 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8329 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8330 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331 return isCarrierSupported && isDeviceSupported;
8332 } finally {
8333 Binder.restoreCallingIdentity(identity);
8334 }
Hall Liu98187582018-01-22 19:15:32 -08008335 }
8336
Hall Liuf6668912018-10-31 17:05:23 -07008337 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008338 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8339 * RTT setting, will return true if the device and carrier both support RTT.
8340 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008341 */
8342 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343 final long identity = Binder.clearCallingIdentity();
8344 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008345 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8346 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8347 return false;
8348 }
8349 }
8350
Hall Liu5bab75c2019-12-11 23:58:20 +00008351 boolean isRttSupported = isRttSupported(subscriptionId);
8352 boolean isUserRttSettingOn = Settings.Secure.getInt(
8353 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8354 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8355 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8356 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008357 } finally {
8358 Binder.restoreCallingIdentity(identity);
8359 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008360 }
8361
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008362 @Deprecated
8363 @Override
8364 public String getDeviceId(String callingPackage) {
8365 return getDeviceIdWithFeature(callingPackage, null);
8366 }
8367
Sanket Padawe7310cc72015-01-14 09:53:20 -08008368 /**
8369 * Returns the unique device ID of phone, for example, the IMEI for
8370 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8371 *
8372 * <p>Requires Permission:
8373 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8374 */
8375 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008376 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008377 try {
8378 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8379 } catch (SecurityException se) {
8380 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8381 throw new SecurityException("Package " + callingPackage + " does not belong to "
8382 + Binder.getCallingUid());
8383 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008384 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008385 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008386 return null;
8387 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008388 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008389 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008390 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008391 return null;
8392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393
8394 final long identity = Binder.clearCallingIdentity();
8395 try {
8396 return phone.getDeviceId();
8397 } finally {
8398 Binder.restoreCallingIdentity(identity);
8399 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008400 }
8401
Ping Sunc67b7c22016-03-02 19:16:45 +08008402 /**
8403 * {@hide}
8404 * Returns the IMS Registration Status on a particular subid
8405 *
8406 * @param subId
8407 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008408 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008409 Phone phone = getPhone(subId);
8410 if (phone != null) {
8411 return phone.isImsRegistered();
8412 } else {
8413 return false;
8414 }
8415 }
8416
Santos Cordon7a1885b2015-02-03 11:15:19 -08008417 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008418 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008419 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008421 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008422 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8423 }
8424 final long identity = Binder.clearCallingIdentity();
8425 try {
8426 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8427 } finally {
8428 Binder.restoreCallingIdentity(identity);
8429 }
8430 }
8431
8432 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008433 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008434 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008435 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008436 mApp,
8437 subscriptionId,
8438 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8439 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008440
8441 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8442 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8443
Tyler Gunnf70ed162019-04-03 15:28:53 -07008444 final long identity = Binder.clearCallingIdentity();
8445 try {
8446 Phone phone = getPhone(subscriptionId);
8447 if (phone == null) {
8448 return null;
8449 }
8450 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8451 } finally {
8452 Binder.restoreCallingIdentity(identity);
8453 }
8454 }
8455
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008456 /**
8457 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008458 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008459 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008460 final long identity = Binder.clearCallingIdentity();
8461 try {
8462 Phone phone = getPhone(subId);
8463 if (phone != null) {
8464 return phone.isWifiCallingEnabled();
8465 } else {
8466 return false;
8467 }
8468 } finally {
8469 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008470 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008471 }
8472
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008473 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008474 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008475 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008476 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008477 final long identity = Binder.clearCallingIdentity();
8478 try {
8479 Phone phone = getPhone(subId);
8480 if (phone != null) {
8481 return phone.isVideoEnabled();
8482 } else {
8483 return false;
8484 }
8485 } finally {
8486 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008487 }
8488 }
8489
8490 /**
8491 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8492 * defined in {@link ImsRegistrationImplBase}.
8493 */
8494 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008495 final long identity = Binder.clearCallingIdentity();
8496 try {
8497 Phone phone = getPhone(subId);
8498 if (phone != null) {
8499 return phone.getImsRegistrationTech();
8500 } else {
8501 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8502 }
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008505 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008506 }
8507
Stuart Scott8eef64f2015-04-08 15:13:54 -07008508 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008509 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008510 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008511
8512 enforceTelephonyFeatureWithException(callingPackage,
8513 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8514
Stuart Scott981d8582015-04-21 14:09:50 -07008515 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8516 return;
8517 }
Kai Shif70f46f2021-03-03 13:59:46 -08008518 Phone defaultPhone = getDefaultPhone();
8519 if (defaultPhone != null) {
8520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8521 mApp, getDefaultPhone().getSubId(), "factoryReset");
8522 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008523 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008524
Svet Ganovcc087f82015-05-12 20:35:54 -07008525 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008526 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8527 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008528 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008529 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008530 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008531 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008532 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008533 setDataRoamingEnabled(subId, phone == null ? false
8534 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008535 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008536 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008537 // There has been issues when Sms raw table somehow stores orphan
8538 // fragments. They lead to garbled message when new fragments come
8539 // in and combined with those stale ones. In case this happens again,
8540 // user can reset all network settings which will clean up this table.
8541 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008542 // Clean up IMS settings as well here.
8543 int slotId = getSlotIndex(subId);
8544 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8545 ImsManager.getInstance(mApp, slotId).factoryReset();
8546 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008547
Kai Shif70f46f2021-03-03 13:59:46 -08008548 if (defaultPhone == null) {
8549 return;
8550 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008551 // Erase modem config if erase modem on network setting is enabled.
8552 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8553 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8554 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008555 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008556 }
Kai Shif70f46f2021-03-03 13:59:46 -08008557
8558 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008559 } finally {
8560 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008561 }
8562 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008563
SongFerngWangfd89b102021-05-27 22:44:54 +08008564 @VisibleForTesting
8565 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8566 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8567 return;
8568 }
8569 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8570 RILConstants.PREFERRED_NETWORK_MODE);
8571 SubscriptionManager.setSubscriptionProperty(subId,
8572 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8573 "user=" + defaultNetworkType);
8574 phone.loadAllowedNetworksFromSubscriptionDatabase();
8575 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8576 defaultNetworkType, null);
8577 }
8578
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008579 private void cleanUpSmsRawTable(Context context) {
8580 ContentResolver resolver = context.getContentResolver();
8581 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8582 resolver.delete(uri, null, null);
8583 }
8584
Narayan Kamath1c496c22015-04-16 14:40:19 +01008585 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008586 public String getSimLocaleForSubscriber(int subId) {
8587 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008588
8589 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8590 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8591
chen xu5d3637b2019-01-21 23:31:38 -08008592 final Phone phone = getPhone(subId);
8593 if (phone == null) {
8594 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008595 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008597 final long identity = Binder.clearCallingIdentity();
8598 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008599 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8600 phone.getContext().getOpPackageName(),
8601 phone.getContext().getAttributionTag());
8602 if (info == null) {
8603 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8604 return null;
chen xu6291c472019-02-04 12:55:53 -08008605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008606 // Try and fetch the locale from the carrier properties or from the SIM language
8607 // preferences (EF-PL and EF-LI)...
8608 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008609 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008610 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8611 if (localeFromDefaultSim != null) {
8612 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8613 if (DBG) log("Using locale from subId: " + subId + " locale: "
8614 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008615 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008616 } else {
8617 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008618 }
8619 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008621 // The SIM language preferences only store a language (e.g. fr = French), not an
8622 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8623 // the SIM and carrier preferences does not include a country we add the country
8624 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008625 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008626 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008627 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008628 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008629 }
8630
8631 if (DBG) log("No locale found - returning null");
8632 return null;
8633 } finally {
8634 Binder.restoreCallingIdentity(identity);
8635 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008636 }
8637
tom hsu0b59d292022-09-29 23:49:21 +08008638 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008639 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008640 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008641 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008642 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008643 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8644 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008645 Locale.forLanguageTag(localeTag).getCountry())) {
8646 return localeTag;
8647 }
8648 }
8649 return inputLocale.toLanguageTag();
8650 }
8651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008652 /**
8653 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8654 */
8655 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008656 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008657 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008658 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008659
Gary Jian3aa9a762022-01-24 16:41:19 +08008660 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8661 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008662
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008663 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008664 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8665 * representing the state of the modem.
8666 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008667 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8668 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008669 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008670 */
8671 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008672 public void requestModemActivityInfo(ResultReceiver result) {
8673 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008674
8675 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8676 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8677
vagdeviaf9a5b92018-08-15 16:01:53 -07008678 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008679
8680 final long identity = Binder.clearCallingIdentity();
8681 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008682 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008683 } finally {
8684 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008685 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008686 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008687
Gary Jian76280a42022-12-07 16:18:33 +08008688 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008689 // less than total activity duration.
8690 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8691 if (info == null) {
8692 return false;
8693 }
8694 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008695 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008696 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8697
Hall Liu49656c02020-10-09 19:00:11 -07008698 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8699
Siddharth Rayb8114062018-06-17 15:02:38 -07008700 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008701 && (info.getSleepTimeMillis() <= activityDurationMs)
8702 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008703 }
8704
Gary Jian3aa9a762022-01-24 16:41:19 +08008705 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8706 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8707 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8708 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8709
8710 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8711 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8712 }
8713
8714 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8715 mLastModemActivityInfo.setReceiveTimeMillis(
8716 rat,
8717 freq,
8718 info.getReceiveTimeMillis(rat, freq)
8719 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8720 }
8721
8722 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8723 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8724 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8725 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8726
8727 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8728 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8729 }
8730 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8731 mLastModemActivityInfo.setReceiveTimeMillis(
8732 rat,
8733 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8734 }
8735
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008736 /**
8737 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8738 * @param info recent ModemActivityInfo
8739 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008740 private void mergeModemActivityInfo(ModemActivityInfo info) {
8741 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008742 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008743 boolean matched;
8744 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8745 matched = false;
8746 int rat = info.getSpecificInfoRat(i);
8747 int freq = info.getSpecificInfoFrequencyRange(i);
8748 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8749 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8750 //if it already exists
8751 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8752 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8753 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8754 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8755 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8756 updateLastModemActivityInfo(info, rat, freq);
8757 matched = true;
8758 }
8759 } else {
8760 updateLastModemActivityInfo(info, rat);
8761 matched = true;
8762 }
8763 }
8764 }
8765
8766 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008767 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008768 new ActivityStatsTechSpecificInfo(
8769 rat,
8770 freq,
8771 info.getTransmitTimeMillis(rat, freq),
8772 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008773 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008774 }
8775 }
8776 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8777 mLastModemActivitySpecificInfo =
8778 new ActivityStatsTechSpecificInfo[merged.size()];
8779 merged.toArray(mLastModemActivitySpecificInfo);
8780
8781 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8782 mLastModemActivityInfo.setSleepTimeMillis(
8783 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008784 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008785 mLastModemActivityInfo.setIdleTimeMillis(
8786 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008787 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008788
8789 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008790 new ModemActivityInfo(
8791 mLastModemActivityInfo.getTimestampMillis(),
8792 mLastModemActivityInfo.getSleepTimeMillis(),
8793 mLastModemActivityInfo.getIdleTimeMillis(),
8794 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008795 }
8796
8797 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8798 ActivityStatsTechSpecificInfo[] info) {
8799 int infoSize = info.length;
8800 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8801 for (int i = 0; i < infoSize; i++) {
8802 ret[i] = new ActivityStatsTechSpecificInfo(
8803 info[i].getRat(), info[i].getFrequencyRange(),
8804 info[i].getTransmitTimeMillis(),
8805 (int) info[i].getReceiveTimeMillis());
8806 }
8807 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008808 }
8809
Jack Yu85bd38a2015-11-09 11:34:32 -08008810 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008811 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008812 */
8813 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008814 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8815 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8816 Phone phone = PhoneFactory.getPhone(slotIndex);
8817 if (phone == null) {
8818 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8819 return null;
8820 }
8821
8822 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008824 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008825 return null;
8826 }
8827
joonhunshin4ac60942023-11-15 15:23:39 +00008828 enforceTelephonyFeatureWithException(callingPackage,
8829 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8830
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008831 boolean hasFinePermission = false;
8832 boolean hasCoarsePermission = false;
8833 if (!renounceFineLocationAccess) {
8834 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8835 LocationAccessPolicy.checkLocationPermission(mApp,
8836 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8837 .setCallingPackage(callingPackage)
8838 .setCallingFeatureId(callingFeatureId)
8839 .setCallingPid(Binder.getCallingPid())
8840 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008841 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008842 .setLogAsInfo(true)
8843 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8844 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8845 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8846 .build());
8847 hasFinePermission =
8848 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8849 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008850
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008851 if (!renounceCoarseLocationAccess) {
8852 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8853 LocationAccessPolicy.checkLocationPermission(mApp,
8854 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8855 .setCallingPackage(callingPackage)
8856 .setCallingFeatureId(callingFeatureId)
8857 .setCallingPid(Binder.getCallingPid())
8858 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008859 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008860 .setLogAsInfo(true)
8861 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8862 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8863 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8864 .build());
8865 hasCoarsePermission =
8866 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8867 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008868
Jordan Liu0f2bc442020-11-18 16:47:37 -08008869 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008870 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008871 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8872 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008873 if (subInfo != null && !subInfo.isActive()) {
8874 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008875 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008876 }
8877
Hall Liuf19c44f2018-11-27 14:38:17 -08008878 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008879 boolean isCallingPackageDataService = phone.getDataServicePackages()
8880 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008881
8882 // Scrub out the location info in ServiceState depending on what level of access
8883 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008884 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008885 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8886 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008887 } finally {
8888 Binder.restoreCallingIdentity(identity);
8889 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008890 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008891
8892 /**
8893 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8894 *
8895 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8896 * voicemail ringtone.
8897 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8898 * PhoneAccount.
8899 */
8900 @Override
8901 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008902 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8903 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008905 final long identity = Binder.clearCallingIdentity();
8906 try {
8907 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8908 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008909 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008910 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008912 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8913 } finally {
8914 Binder.restoreCallingIdentity(identity);
8915 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008916 }
8917
8918 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008919 * Sets the per-account voicemail ringtone.
8920 *
8921 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8922 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8923 *
8924 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8925 * voicemail ringtone.
8926 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8927 * PhoneAccount.
8928 */
8929 @Override
8930 public void setVoicemailRingtoneUri(String callingPackage,
8931 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008932 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008933 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008934 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8935 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8937 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8938 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008940
joonhunshin4ac60942023-11-15 15:23:39 +00008941 enforceTelephonyFeatureWithException(callingPackage,
8942 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008944 final long identity = Binder.clearCallingIdentity();
8945 try {
8946 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8947 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008948 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008949 }
8950 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8951 } finally {
8952 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008953 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008954 }
8955
8956 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008957 * Returns whether vibration is set for voicemail notification in Phone settings.
8958 *
8959 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8960 * voicemail vibration setting.
8961 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8962 */
8963 @Override
8964 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008965 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8966 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008968 final long identity = Binder.clearCallingIdentity();
8969 try {
8970 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8971 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008972 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008973 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8976 } finally {
8977 Binder.restoreCallingIdentity(identity);
8978 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008979 }
8980
Youhan Wange64578a2016-05-02 15:32:42 -07008981 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008982 * Sets the per-account voicemail vibration.
8983 *
8984 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8985 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8986 *
8987 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8988 * voicemail vibration setting.
8989 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8990 * specific PhoneAccount.
8991 */
8992 @Override
8993 public void setVoicemailVibrationEnabled(String callingPackage,
8994 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008995 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008996 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008997 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8998 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9000 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9001 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009002 }
9003
joonhunshin4ac60942023-11-15 15:23:39 +00009004 enforceTelephonyFeatureWithException(callingPackage,
9005 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009007 final long identity = Binder.clearCallingIdentity();
9008 try {
9009 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9010 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009011 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009012 }
9013 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9014 } finally {
9015 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009016 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009017 }
9018
9019 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009020 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9021 *
9022 * @throws SecurityException if the caller does not have the required permission
9023 */
arunvoddud7401012022-12-15 16:08:12 +00009024 @VisibleForTesting
9025 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009026 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009027 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009028 }
9029
9030 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009031 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9032 * permission.
9033 *
9034 * @throws SecurityException if the caller does not have the required permission
9035 */
9036 private void enforceSendSmsPermission() {
9037 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9038 }
9039
9040 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009041 * Make sure either called from same process as self (phone) or IPC caller has interact across
9042 * users permission.
9043 *
9044 * @throws SecurityException if the caller does not have the required permission
9045 */
9046 private void enforceInteractAcrossUsersPermission(String message) {
9047 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9048 }
9049
9050 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009051 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009052 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009053 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009054 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009055 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009056 final long identity = Binder.clearCallingIdentity();
9057 try {
9058 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009059 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009060 if (componentName == null) {
9061 throw new SecurityException(
9062 "Caller not current active visual voicemail package[null]");
9063 }
9064 String vvmPackage = componentName.getPackageName();
9065 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009066 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009067 }
9068 } finally {
9069 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009070 }
9071 }
9072
9073 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009074 * Return the application ID for the app type.
9075 *
9076 * @param subId the subscription ID that this request applies to.
9077 * @param appType the uicc app type.
9078 * @return Application ID for specificied app type, or null if no uicc.
9079 */
9080 @Override
9081 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009082 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009083
9084 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9085 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9086
Youhan Wange64578a2016-05-02 15:32:42 -07009087 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009088
9089 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009090 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009091 if (phone == null) {
9092 return null;
9093 }
9094 String aid = null;
9095 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009096 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009097 .getApplicationByType(appType).getAid();
9098 } catch (Exception e) {
9099 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9100 }
9101 return aid;
9102 } finally {
9103 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009104 }
Youhan Wange64578a2016-05-02 15:32:42 -07009105 }
9106
Youhan Wang4001d252016-05-11 10:29:41 -07009107 /**
9108 * Return the Electronic Serial Number.
9109 *
9110 * @param subId the subscription ID that this request applies to.
9111 * @return ESN or null if error.
9112 */
9113 @Override
9114 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009115 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009116 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009117
9118 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009119 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009120 if (phone == null) {
9121 return null;
9122 }
9123 String esn = null;
9124 try {
9125 esn = phone.getEsn();
9126 } catch (Exception e) {
9127 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9128 }
9129 return esn;
9130 } finally {
9131 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009132 }
Youhan Wang4001d252016-05-11 10:29:41 -07009133 }
9134
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009135 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009136 * Return the Preferred Roaming List Version.
9137 *
9138 * @param subId the subscription ID that this request applies to.
9139 * @return PRLVersion or null if error.
9140 */
9141 @Override
9142 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009143 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009144
9145 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9146 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9147
Youhan Wang66ad5d72016-07-18 17:56:58 -07009148 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009149
9150 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009151 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009152 if (phone == null) {
9153 return null;
9154 }
9155 String cdmaPrlVersion = null;
9156 try {
9157 cdmaPrlVersion = phone.getCdmaPrlVersion();
9158 } catch (Exception e) {
9159 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9160 }
9161 return cdmaPrlVersion;
9162 } finally {
9163 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009164 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009165 }
9166
9167 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009168 * Get snapshot of Telephony histograms
9169 * @return List of Telephony histograms
9170 * @hide
9171 */
9172 @Override
9173 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9175 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009176
9177 final long identity = Binder.clearCallingIdentity();
9178 try {
9179 return RIL.getTelephonyRILTimingHistograms();
9180 } finally {
9181 Binder.restoreCallingIdentity(identity);
9182 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009183 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009184
9185 /**
9186 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009187 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9188 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009189 * Require system privileges. In the future we may add this to carrier APIs.
9190 *
Michele Berionne482f8202018-11-27 18:57:59 -08009191 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009192 */
9193 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009194 @TelephonyManager.SetCarrierRestrictionResult
9195 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009196 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009197
9198 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9199 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9200
vagdeviaf9a5b92018-08-15 16:01:53 -07009201 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009202
Michele Berionne482f8202018-11-27 18:57:59 -08009203 if (carrierRestrictionRules == null) {
9204 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009205 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009207 final long identity = Binder.clearCallingIdentity();
9208 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009209 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009210 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009214 }
9215
9216 /**
9217 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009218 * Get the allowed carrier list and the excluded carrier list, including the priority between
9219 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009220 * Require system privileges. In the future we may add this to carrier APIs.
9221 *
Michele Berionne482f8202018-11-27 18:57:59 -08009222 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009223 */
9224 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009225 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009226 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009227
9228 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9229 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9230
vagdeviaf9a5b92018-08-15 16:01:53 -07009231 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009232
9233 final long identity = Binder.clearCallingIdentity();
9234 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009235 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9236 if (response instanceof CarrierRestrictionRules) {
9237 return (CarrierRestrictionRules) response;
9238 }
9239 // Response is an Exception of some kind,
9240 // which is signalled to the user as a NULL retval
9241 return null;
9242 } catch (Exception e) {
9243 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9244 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009245 } finally {
9246 Binder.restoreCallingIdentity(identity);
9247 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009248 }
9249
fionaxu59545b42016-05-25 15:53:37 -07009250 /**
arunvoddud7401012022-12-15 16:08:12 +00009251 * Fetches the carrier restriction status of the device and sends the status to the caller
9252 * through the callback.
9253 *
9254 * @param callback The callback that will be used to send the result.
9255 * @throws SecurityException if the caller does not have the required permission/privileges or
9256 * the caller is not allowlisted.
9257 */
9258 @Override
9259 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9260 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009261
9262 enforceTelephonyFeatureWithException(packageName,
9263 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9264
Steve Statia28b7cb32024-03-11 23:58:50 +00009265 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9266 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009267 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9268 throw new SecurityException("Not an authorized caller");
9269 }
9270 final long identity = Binder.clearCallingIdentity();
9271 try {
9272 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009273 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009274 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9275 } finally {
9276 Binder.restoreCallingIdentity(identity);
9277 }
9278 }
9279
arunvoddu567f2b42023-04-25 17:22:00 +00009280 @Override
9281 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9282 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9283 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9284 return allowListInfo.getShaIdList(pkgName, carrierId);
9285 }
9286
arunvoddud7401012022-12-15 16:08:12 +00009287 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009288 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009289 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009290 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009291 }
9292
9293 /**
fionaxu59545b42016-05-25 15:53:37 -07009294 * Action set from carrier signalling broadcast receivers to enable/disable radio
9295 * @param subId the subscription ID that this action applies to.
9296 * @param enabled control enable or disable radio.
9297 * {@hide}
9298 */
9299 @Override
9300 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9301 enforceModifyPermission();
9302 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009303
9304 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009305 if (phone == null) {
9306 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9307 return;
9308 }
9309 try {
9310 phone.carrierActionSetRadioEnabled(enabled);
9311 } catch (Exception e) {
9312 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009313 } finally {
9314 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009315 }
9316 }
9317
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009318 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009319 * Enable or disable Voice over NR (VoNR)
9320 * @param subId the subscription ID that this action applies to.
9321 * @param enabled enable or disable VoNR.
9322 * @return operation result.
9323 */
9324 @Override
9325 public int setVoNrEnabled(int subId, boolean enabled) {
9326 enforceModifyPermission();
9327 final Phone phone = getPhone(subId);
9328
9329 final long identity = Binder.clearCallingIdentity();
9330 if (phone == null) {
9331 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9332 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9333 }
9334
9335 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9336 try {
9337 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9338 workSource);
9339 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009340
9341 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9342 if (DBG) {
9343 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9344 }
9345 SubscriptionManager.setSubscriptionProperty(
9346 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9347 (enabled ? "1" : "0"));
9348 }
9349
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009350 return result;
9351 } finally {
9352 Binder.restoreCallingIdentity(identity);
9353 }
9354 }
9355
9356 /**
9357 * Is voice over NR enabled
9358 * @return true if VoNR is enabled else false
9359 */
9360 @Override
9361 public boolean isVoNrEnabled(int subId) {
9362 enforceReadPrivilegedPermission("isVoNrEnabled");
9363 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9364 final long identity = Binder.clearCallingIdentity();
9365 try {
9366 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9367 null, subId, workSource);
9368 if (DBG) log("isVoNrEnabled: " + isEnabled);
9369 return isEnabled;
9370 } finally {
9371 Binder.restoreCallingIdentity(identity);
9372 }
9373 }
9374
9375 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009376 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9377 * network status based on which carrier apps could apply actions accordingly,
9378 * enable/disable default url handler for example.
9379 *
9380 * @param subId the subscription ID that this action applies to.
9381 * @param report control start/stop reporting the default network status.
9382 * {@hide}
9383 */
9384 @Override
9385 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9386 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009387
9388 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9389 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9390 "carrierActionReportDefaultNetworkStatus");
9391
fionaxu8da9cb12017-05-23 15:02:46 -07009392 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009393
9394 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009395 if (phone == null) {
9396 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9397 return;
9398 }
9399 try {
9400 phone.carrierActionReportDefaultNetworkStatus(report);
9401 } catch (Exception e) {
9402 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009403 } finally {
9404 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009405 }
9406 }
9407
9408 /**
fionaxud9622282017-07-17 17:51:30 -07009409 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9410 * @param subId the subscription ID that this action applies to.
9411 * {@hide}
9412 */
9413 @Override
9414 public void carrierActionResetAll(int subId) {
9415 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009416
9417 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9418 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9419
fionaxud9622282017-07-17 17:51:30 -07009420 final Phone phone = getPhone(subId);
9421 if (phone == null) {
9422 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9423 return;
9424 }
9425 try {
9426 phone.carrierActionResetAll();
9427 } catch (Exception e) {
9428 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9429 }
9430 }
9431
9432 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009433 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9434 * bug report is being generated.
9435 */
9436 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009437 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009438 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9439 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009440 writer.println("Permission Denial: can't dump Phone from pid="
9441 + Binder.getCallingPid()
9442 + ", uid=" + Binder.getCallingUid()
9443 + "without permission "
9444 + android.Manifest.permission.DUMP);
9445 return;
9446 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009447 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009448 }
Jack Yueb89b242016-06-22 13:27:47 -07009449
Brad Ebingerdac2f002018-04-03 15:17:52 -07009450 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009451 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9452 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9453 @NonNull String[] args) {
9454 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9455 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009456 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009457 }
9458
Jack Yueb89b242016-06-22 13:27:47 -07009459 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009460 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009461 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009462 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009463 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009464 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009465 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009466 */
9467 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009468 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009469 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009470 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9471 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9472 try {
9473 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009474 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009475 } catch (SecurityException se) {
9476 enforceModifyPermission();
9477 }
9478 } else {
9479 enforceModifyPermission();
9480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009481
joonhunshin4ac60942023-11-15 15:23:39 +00009482 enforceTelephonyFeatureWithException(callingPackage,
9483 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9484
Nate Myren116695d2024-02-09 09:36:01 -08009485 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009486 final long identity = Binder.clearCallingIdentity();
9487 try {
Nate Myren116695d2024-02-09 09:36:01 -08009488 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9489 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009490 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009491 callingUid, callingPackage, null, null);
9492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009493 Phone phone = getPhone(subId);
9494 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009495 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9496 phone.carrierActionSetMeteredApnsEnabled(enabled);
9497 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009498 phone.getDataSettingsManager().setDataEnabled(
9499 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009500 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009501 }
9502 } finally {
9503 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009504 }
9505 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009506
9507 /**
9508 * Get Client request stats
9509 * @return List of Client Request Stats
9510 * @hide
9511 */
9512 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009513 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9514 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009516 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009517 return null;
9518 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009519 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009521 final long identity = Binder.clearCallingIdentity();
9522 try {
9523 if (phone != null) {
9524 return phone.getClientRequestStats();
9525 }
9526
9527 return null;
9528 } finally {
9529 Binder.restoreCallingIdentity(identity);
9530 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009531 }
9532
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009533 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009534 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009535 if (uid == Process.ROOT_UID && packageName == null) {
9536 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9537 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9538 // exception. ROOT_UID seems not to have a valid package name returned by
9539 // PackageManager, so just fake it here to avoid issues when running telephony shell
9540 // commands that plumb through the RIL as root, like so:
9541 // $ adb root
9542 // $ adb shell cmd phone ...
9543 packageName = "root";
9544 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009545 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009546 }
Jack Yueb4124c2017-02-16 15:32:43 -08009547
9548 /**
Grace Chen70990072017-03-24 17:21:30 -07009549 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009550 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009551 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009552 * @param state State of SIM (power down, power up, pass through)
9553 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9554 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9555 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009556 *
9557 **/
9558 @Override
Grace Chen70990072017-03-24 17:21:30 -07009559 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009560 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009561
9562 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9563 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9564
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009565 Phone phone = PhoneFactory.getPhone(slotIndex);
9566
vagdeviaf9a5b92018-08-15 16:01:53 -07009567 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9568
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009569 final long identity = Binder.clearCallingIdentity();
9570 try {
9571 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009572 phone.setSimPowerState(state, null, workSource);
9573 }
9574 } finally {
9575 Binder.restoreCallingIdentity(identity);
9576 }
9577 }
9578
9579 /**
9580 * Set SIM card power state.
9581 *
9582 * @param slotIndex SIM slot id.
9583 * @param state State of SIM (power down, power up, pass through)
9584 * @param callback callback to trigger after success or failure
9585 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9586 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9587 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9588 *
9589 **/
9590 @Override
9591 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9592 IIntegerConsumer callback) {
9593 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009594
9595 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9596 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9597 "setSimPowerStateForSlotWithCallback");
9598
Jordan Liu109698e2020-11-24 14:50:34 -08009599 Phone phone = PhoneFactory.getPhone(slotIndex);
9600
9601 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9602
9603 final long identity = Binder.clearCallingIdentity();
9604 try {
9605 if (phone != null) {
9606 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9607 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009608 }
9609 } finally {
9610 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009611 }
9612 }
Shuo Qiandd210312017-04-12 22:11:33 +00009613
Tyler Gunn65d45c22017-06-05 11:22:26 -07009614 private boolean isUssdApiAllowed(int subId) {
9615 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009616 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009617 if (configManager == null) {
9618 return false;
9619 }
9620 PersistableBundle pb = configManager.getConfigForSubId(subId);
9621 if (pb == null) {
9622 return false;
9623 }
9624 return pb.getBoolean(
9625 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9626 }
9627
Shuo Qiandd210312017-04-12 22:11:33 +00009628 /**
Ling Mac28f0212023-03-24 16:07:15 -07009629 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009630 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009631 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009632 */
goneil9c5f4872017-12-05 14:07:56 -08009633 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009634 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009635 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009636
9637 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9638 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009640 final long identity = Binder.clearCallingIdentity();
9641 try {
Ling Mac28f0212023-03-24 16:07:15 -07009642 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009643 } finally {
9644 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009645 }
9646 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009647
9648 /**
9649 * Get the current signal strength information for the given subscription.
9650 * Because this information is not updated when the device is in a low power state
9651 * it should not be relied-upon to be current.
9652 * @param subId Subscription index
9653 * @return the most recent cached signal strength info from the modem
9654 */
9655 @Override
9656 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009657 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9658 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009660 final long identity = Binder.clearCallingIdentity();
9661 try {
9662 Phone p = getPhone(subId);
9663 if (p == null) {
9664 return null;
9665 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009667 return p.getSignalStrength();
9668 } finally {
9669 Binder.restoreCallingIdentity(identity);
9670 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009671 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009672
Pengquan Meng77b7f132018-08-22 14:49:57 -07009673 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009674 * Get the current modem radio state for the given slot.
9675 * @param slotIndex slot index.
9676 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009677 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009678 * @return the current radio power state from the modem
9679 */
9680 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009681 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009682 Phone phone = PhoneFactory.getPhone(slotIndex);
9683 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9685 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009686 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9687 }
9688
joonhunshin4ac60942023-11-15 15:23:39 +00009689 enforceTelephonyFeatureWithException(callingPackage,
9690 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9691
Chen Xuf792fd62018-10-17 17:54:36 +00009692 final long identity = Binder.clearCallingIdentity();
9693 try {
9694 return phone.getRadioPowerState();
9695 } finally {
9696 Binder.restoreCallingIdentity(identity);
9697 }
9698 }
9699 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9700 }
9701
9702 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009703 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9704 *
9705 * <p>Requires one of the following permissions:
9706 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009707 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009708 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9709 * privileges.
9710 *
9711 * @param subId subscription id
9712 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9713 * {@code false}.
9714 */
9715 @Override
9716 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009717 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009718 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009719 try {
9720 mApp.enforceCallingOrSelfPermission(
9721 android.Manifest.permission.ACCESS_NETWORK_STATE,
9722 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009723 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009724 mApp.enforceCallingOrSelfPermission(
9725 permission.READ_BASIC_PHONE_STATE, functionName);
9726 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009727 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009728 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009729 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009730 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009731
joonhunshin4ac60942023-11-15 15:23:39 +00009732 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9733 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9734
Pengquan Menga1bb6272018-09-06 09:59:22 -07009735 boolean isEnabled = false;
9736 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009737 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009738 Phone phone = getPhone(subId);
9739 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009740 } finally {
9741 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009742 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009743 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009744 }
9745
9746
9747 /**
9748 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9749 *
9750 * <p> Requires permission:
9751 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9752 * privileges.
9753 *
9754 * @param subId subscription id
9755 * @param isEnabled {@code true} means enable, {@code false} means disable.
9756 */
9757 @Override
9758 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9760 mApp, subId, "setDataRoamingEnabled");
9761
joonhunshin4ac60942023-11-15 15:23:39 +00009762 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9763 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9764
Pengquan Menga1bb6272018-09-06 09:59:22 -07009765 final long identity = Binder.clearCallingIdentity();
9766 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009767 Phone phone = getPhone(subId);
9768 if (phone != null) {
9769 phone.setDataRoamingEnabled(isEnabled);
9770 }
9771 } finally {
9772 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009773 }
9774 }
9775
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009776 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009777 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009778 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009779 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009780 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009781
joonhunshin4ac60942023-11-15 15:23:39 +00009782 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9783 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9784
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009785 boolean isAllowed = true;
9786 final long identity = Binder.clearCallingIdentity();
9787 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009788 Phone phone = getPhone(subId);
9789 if (phone != null) {
9790 isAllowed = phone.isCspPlmnEnabled();
9791 }
9792 } finally {
9793 Binder.restoreCallingIdentity(identity);
9794 }
9795 return isAllowed;
9796 }
9797
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009798 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9799 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009800 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009801 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009802 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009803 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9804 if (phone == null) {
9805 return false;
9806 }
9807 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9808 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9809 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009810 }
9811
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009812 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009813 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009814 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009815 mApp.getSystemService(AppOpsManager.class)
9816 .checkPackage(Binder.getCallingUid(), callingPackage);
9817
Jordan Liu1e142fc2019-04-22 15:10:43 -07009818 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009819 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009820 try {
9821 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009822 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009823 } catch (SecurityException e) {
9824 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9825 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009826 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009827 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009828 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009829 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009830 }
joonhunshin4ac60942023-11-15 15:23:39 +00009831
9832 enforceTelephonyFeatureWithException(callingPackage,
9833 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9834
sandeepjsb6c87872021-09-27 15:34:44 +00009835 // checking compatibility, if calling app's target SDK is T and beyond.
9836 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9837 Binder.getCallingUid())) {
9838 isIccIdAccessRestricted = true;
9839 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009840 final long identity = Binder.clearCallingIdentity();
9841 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009842 UiccController uiccController = UiccController.getInstance();
9843 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009844 if (hasReadPermission) {
9845 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009846 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009847
9848 // Remove private info if the caller doesn't have access
9849 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9850 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009851 //setting the value after compatibility check
9852 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009853 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9854 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009855 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009856 if (card == null) {
9857 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009858 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009859 continue;
9860 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009861 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9862 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009863 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009864 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009865 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009866 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9867 for (UiccPortInfo portInfo : portInfos) {
9868 UiccPort port = uiccController.getUiccPortForSlot(
9869 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9870 if (port == null) {
9871 // assume no access if port is null
9872 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9873 continue;
9874 }
9875 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9876 uiccPortInfos.add(portInfo);
9877 } else {
9878 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9879 }
9880 }
9881 filteredInfos.add(new UiccCardInfo(
9882 cardInfo.isEuicc(),
9883 cardInfo.getCardId(),
9884 null,
9885 cardInfo.getPhysicalSlotIndex(),
9886 cardInfo.isRemovable(),
9887 cardInfo.isMultipleEnabledProfilesSupported(),
9888 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009889 }
9890 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009891 } finally {
9892 Binder.restoreCallingIdentity(identity);
9893 }
9894 }
9895
sandeepjsb6c87872021-09-27 15:34:44 +00009896 /**
9897 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9898 * generally private and require carrier privileges to view.
9899 *
9900 * @hide
9901 */
9902 @NonNull
9903 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9904 List<UiccPortInfo> portinfo = new ArrayList<>();
9905 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9906 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9907 }
9908 return new UiccCardInfo(
9909 cardInfo.isEuicc(),
9910 cardInfo.getCardId(),
9911 null,
9912 cardInfo.getPhysicalSlotIndex(),
9913 cardInfo.isRemovable(),
9914 cardInfo.isMultipleEnabledProfilesSupported(),
9915 portinfo
9916 );
9917 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009918
sandeepjsb6c87872021-09-27 15:34:44 +00009919 /**
9920 * @hide
9921 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9922 * These values are generally private and require carrier privileges to view.
9923 */
9924 @NonNull
9925 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9926 return new UiccPortInfo(
9927 UiccPortInfo.ICCID_REDACTED,
9928 portInfo.getPortIndex(),
9929 portInfo.getLogicalSlotIndex(),
9930 portInfo.isActive()
9931 );
9932 }
9933 @Override
9934 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009935 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009936 mApp.getSystemService(AppOpsManager.class)
9937 .checkPackage(Binder.getCallingUid(), callingPackage);
9938
sandeepjsb6c87872021-09-27 15:34:44 +00009939 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009940
Aman Guptaf3c90b32022-03-17 04:54:16 +00009941 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9942 // we are reading iccId which is PII data.
9943 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009944
joonhunshin4ac60942023-11-15 15:23:39 +00009945 enforceTelephonyFeatureWithException(callingPackage,
9946 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9947
sandeepjsb6c87872021-09-27 15:34:44 +00009948 // checking compatibility, if calling app's target SDK is T and beyond.
9949 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9950 Binder.getCallingUid())) {
9951 isLogicalSlotAccessRestricted = true;
9952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009953 final long identity = Binder.clearCallingIdentity();
9954 try {
9955 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009956 if (slots == null || slots.length == 0) {
9957 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009958 return null;
9959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009960 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9961 for (int i = 0; i < slots.length; i++) {
9962 UiccSlot slot = slots[i];
9963 if (slot == null) {
9964 continue;
9965 }
9966
Jordan Liu7be7e652019-05-06 18:55:02 +00009967 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009968 UiccCard card = slot.getUiccCard();
9969 if (card != null) {
9970 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009971 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009972 cardId = slot.getEid();
9973 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009974 // If cardId is null, use iccId of default port as cardId.
9975 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009977 }
9978
Jordan Liu857451f2019-05-09 16:35:35 -07009979 if (cardId != null) {
9980 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9981 // if cardId is an EID, it's all digits so this is fine
9982 cardId = IccUtils.stripTrailingFs(cardId);
9983 }
9984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009985 int cardState = 0;
9986 switch (slot.getCardState()) {
9987 case CARDSTATE_ABSENT:
9988 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9989 break;
9990 case CARDSTATE_PRESENT:
9991 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9992 break;
9993 case CARDSTATE_ERROR:
9994 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9995 break;
9996 case CARDSTATE_RESTRICTED:
9997 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9998 break;
9999 default:
10000 break;
10001
10002 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010003 List<UiccPortInfo> portInfos = new ArrayList<>();
10004 int[] portIndexes = slot.getPortList();
10005 for (int portIdx : portIndexes) {
10006 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010007 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010008 portInfos.add(new UiccPortInfo(iccId, portIdx,
10009 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010011 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010012 slot.isEuicc(),
10013 cardId,
10014 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010015 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010016 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010017 //setting the value after compatibility check
10018 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010019 }
10020 return infos;
10021 } finally {
10022 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010023 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010024 }
10025
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010026 /* Returns null if doesn't have read permission or carrier privilege access. */
10027 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10028 boolean hasReadPermission) {
10029 String iccId = slot.getIccId(portIndex);
10030 if (hasReadPermission) { // if has read permission
10031 return iccId;
10032 } else {
10033 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10034 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10035 // if no read permission, checking carrier privilege access
10036 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10037 return iccId;
10038 }
10039 }
10040 }
10041 // No read permission or carrier privilege access.
10042 return UiccPortInfo.ICCID_REDACTED;
10043 }
10044
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010045 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010046 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010047 public boolean switchSlots(int[] physicalSlots) {
10048 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010049
joonhunshin4ac60942023-11-15 15:23:39 +000010050 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10051 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10052
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010053 final long identity = Binder.clearCallingIdentity();
10054 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010055 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10056 for (int i = 0; i < physicalSlots.length; i++) {
10057 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10058 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10059 physicalSlots[i], i));
10060 }
10061 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010062 } finally {
10063 Binder.restoreCallingIdentity(identity);
10064 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010065 }
Jack Yu4c988042018-02-27 15:30:01 -080010066
10067 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010068 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10069 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10070 enforceModifyPermission();
10071
joonhunshin4ac60942023-11-15 15:23:39 +000010072 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10073 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10074
sandeepjsb6c87872021-09-27 15:34:44 +000010075 final long identity = Binder.clearCallingIdentity();
10076 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010077 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010078 } finally {
10079 Binder.restoreCallingIdentity(identity);
10080 }
10081 }
10082
10083 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010084 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010085 enforceTelephonyFeatureWithException(callingPackage,
10086 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10087
Jordan Liu7de49fa2018-12-06 14:48:49 -080010088 final long identity = Binder.clearCallingIdentity();
10089 try {
10090 return UiccController.getInstance().getCardIdForDefaultEuicc();
10091 } finally {
10092 Binder.restoreCallingIdentity(identity);
10093 }
10094 }
10095
Pengquan Meng85728fb2018-03-12 16:31:21 -070010096 /**
goneil47ffb6e2018-04-06 15:40:58 -070010097 * A test API to reload the UICC profile.
10098 *
10099 * <p>Requires that the calling app has permission
10100 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10101 * @hide
10102 */
10103 @Override
10104 public void refreshUiccProfile(int subId) {
10105 enforceModifyPermission();
10106
10107 final long identity = Binder.clearCallingIdentity();
10108 try {
10109 Phone phone = getPhone(subId);
10110 if (phone == null) {
10111 return;
10112 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010113 UiccPort uiccPort = phone.getUiccPort();
10114 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010115 return;
10116 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010117 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010118 if (uiccProfile == null) {
10119 return;
10120 }
10121 uiccProfile.refresh();
10122 } finally {
10123 Binder.restoreCallingIdentity(identity);
10124 }
10125 }
10126
10127 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010128 * Returns false if the mobile data is disabled by default, otherwise return true.
10129 */
10130 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010131 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010132 }
10133
10134 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010135 * Returns the default network type for the given {@code subId}, if the default network type is
10136 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10137 */
10138 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010139 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010140 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010141 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10142 return list.get(phoneId);
10143 }
10144 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010145 }
fionaxua13278b2018-03-21 00:08:13 -070010146
10147 @Override
10148 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010149 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010150 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010151
10152 final long identity = Binder.clearCallingIdentity();
10153 try {
10154 final Phone phone = getPhone(subId);
10155 if (phone == null) {
10156 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10157 return;
10158 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010159 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10160 if (cpt != null) {
10161 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10162 }
10163 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010164 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10165 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010166 if (carrierPrivilegeRules == null) {
10167 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10168 } else {
10169 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010171 } finally {
10172 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010173 }
fionaxua13278b2018-03-21 00:08:13 -070010174 }
10175
10176 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010177 public void setCarrierServicePackageOverride(
10178 int subId, String carrierServicePackage, String callingPackage) {
10179 TelephonyPermissions.enforceShellOnly(
10180 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10181
Benedict Wong66477622023-02-03 23:30:57 +000010182 final long identity = Binder.clearCallingIdentity();
10183 try {
10184 final Phone phone = getPhone(subId);
10185 if (phone == null || phone.getSubId() != subId) {
10186 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10187 throw new IllegalArgumentException("No phone for subid");
10188 }
10189 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10190 if (cpt == null) {
10191 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10192 throw new IllegalStateException("No CPT for phone");
10193 }
10194 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10195 } finally {
10196 Binder.restoreCallingIdentity(identity);
10197 }
10198 }
10199
10200 @Override
fionaxua13278b2018-03-21 00:08:13 -070010201 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010202 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010203
10204 final long identity = Binder.clearCallingIdentity();
10205 try {
10206 final Phone phone = getPhone(subId);
10207 if (phone == null) {
10208 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10209 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10210 }
10211 return phone.getCarrierIdListVersion();
10212 } finally {
10213 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010214 }
fionaxua13278b2018-03-21 00:08:13 -070010215 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010216
10217 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010218 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10219 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010221 mApp, subId, callingPackage, callingFeatureId,
10222 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010223 return -1;
10224 }
10225
10226 final long identity = Binder.clearCallingIdentity();
10227 try {
10228 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10229 } finally {
10230 Binder.restoreCallingIdentity(identity);
10231 }
10232 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010233
10234 @Override
10235 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010236 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010237 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010238 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010239
joonhunshin4ac60942023-11-15 15:23:39 +000010240 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10241 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10242
Pengquan Menga1bb6272018-09-06 09:59:22 -070010243 final long identity = Binder.clearCallingIdentity();
10244 try {
10245 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10246 } finally {
10247 Binder.restoreCallingIdentity(identity);
10248 }
10249 }
10250
10251 @Override
10252 public boolean setCdmaRoamingMode(int subId, int mode) {
10253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10254 mApp, subId, "setCdmaRoamingMode");
10255
joonhunshin4ac60942023-11-15 15:23:39 +000010256 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10257 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10258
Pengquan Menga1bb6272018-09-06 09:59:22 -070010259 final long identity = Binder.clearCallingIdentity();
10260 try {
10261 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10262 } finally {
10263 Binder.restoreCallingIdentity(identity);
10264 }
10265 }
10266
10267 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010268 public int getCdmaSubscriptionMode(int subId) {
10269 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010270 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010271 mApp, subId, "getCdmaSubscriptionMode");
10272
joonhunshin4ac60942023-11-15 15:23:39 +000010273 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10274 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10275
Sarah Chinbaab1432020-10-28 13:46:24 -070010276 final long identity = Binder.clearCallingIdentity();
10277 try {
10278 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10279 } finally {
10280 Binder.restoreCallingIdentity(identity);
10281 }
10282 }
10283
10284 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010285 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10287 mApp, subId, "setCdmaSubscriptionMode");
10288
joonhunshin4ac60942023-11-15 15:23:39 +000010289 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10290 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10291
Pengquan Menga1bb6272018-09-06 09:59:22 -070010292 final long identity = Binder.clearCallingIdentity();
10293 try {
10294 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10295 } finally {
10296 Binder.restoreCallingIdentity(identity);
10297 }
10298 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010299
sqianc5eccab2018-10-19 18:46:41 -070010300 @Override
sqian8c685422019-02-22 15:55:18 -080010301 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010302 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010304 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10305 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010306 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10307 }
joonhunshin4ac60942023-11-15 15:23:39 +000010308
10309 enforceTelephonyFeatureWithException(callingPackage,
10310 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10311
sqian11b7a0e2018-12-05 18:48:28 -080010312 final long identity = Binder.clearCallingIdentity();
10313 try {
sqian854d44b2018-12-12 16:48:18 -080010314 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10315 for (Phone phone: PhoneFactory.getPhones()) {
10316 if (phone.getEmergencyNumberTracker() != null
10317 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10318 emergencyNumberListInternal.put(
10319 phone.getSubId(),
10320 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10321 }
sqian11b7a0e2018-12-05 18:48:28 -080010322 }
sqian854d44b2018-12-12 16:48:18 -080010323 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010324 } finally {
10325 Binder.restoreCallingIdentity(identity);
10326 }
sqianc5eccab2018-10-19 18:46:41 -070010327 }
10328
10329 @Override
sqian8c685422019-02-22 15:55:18 -080010330 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010331 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010332 if (!exactMatch) {
10333 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010334 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010335 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010336 }
joonhunshin4ac60942023-11-15 15:23:39 +000010337
10338 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10339 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10340
sqian11b7a0e2018-12-05 18:48:28 -080010341 final long identity = Binder.clearCallingIdentity();
10342 try {
sqian854d44b2018-12-12 16:48:18 -080010343 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010344 //Note: we ignore passed in param exactMatch. We can remove it once
10345 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010346 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010347 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010348 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010349 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010350 }
sqian11b7a0e2018-12-05 18:48:28 -080010351 }
10352 return false;
10353 } finally {
10354 Binder.restoreCallingIdentity(identity);
10355 }
10356 }
10357
sqianf4ca7ed2019-01-15 18:32:07 -080010358 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010359 * Start emergency callback mode for GsmCdmaPhone for testing.
10360 */
10361 @Override
10362 public void startEmergencyCallbackMode() {
10363 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10364 "startEmergencyCallbackMode");
10365 enforceModifyPermission();
10366 final long identity = Binder.clearCallingIdentity();
10367 try {
10368 for (Phone phone : PhoneFactory.getPhones()) {
10369 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10370 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10371 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10372 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10373 gsmCdmaPhone.obtainMessage(
10374 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10375 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10376 }
10377 }
10378 } finally {
10379 Binder.restoreCallingIdentity(identity);
10380 }
10381 }
10382
10383 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010384 * Update emergency number list for test mode.
10385 */
10386 @Override
10387 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10388 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10389 "updateEmergencyNumberListTestMode");
10390
10391 final long identity = Binder.clearCallingIdentity();
10392 try {
10393 for (Phone phone: PhoneFactory.getPhones()) {
10394 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10395 if (tracker != null) {
10396 tracker.executeEmergencyNumberTestModeCommand(action, num);
10397 }
10398 }
10399 } finally {
10400 Binder.restoreCallingIdentity(identity);
10401 }
10402 }
10403
10404 /**
10405 * Get the full emergency number list for test mode.
10406 */
10407 @Override
10408 public List<String> getEmergencyNumberListTestMode() {
10409 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10410 "getEmergencyNumberListTestMode");
10411
10412 final long identity = Binder.clearCallingIdentity();
10413 try {
10414 Set<String> emergencyNumbers = new HashSet<>();
10415 for (Phone phone: PhoneFactory.getPhones()) {
10416 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10417 if (tracker != null) {
10418 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10419 emergencyNumbers.add(num.getNumber());
10420 }
10421 }
10422 }
10423 return new ArrayList<>(emergencyNumbers);
10424 } finally {
10425 Binder.restoreCallingIdentity(identity);
10426 }
10427 }
10428
chen xud6b45bd2018-10-30 22:27:10 -070010429 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010430 public int getEmergencyNumberDbVersion(int subId) {
10431 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10432
joonhunshin4ac60942023-11-15 15:23:39 +000010433 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10434 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10435
Shuo Qian3b6ee772019-11-13 17:43:31 -080010436 final long identity = Binder.clearCallingIdentity();
10437 try {
10438 final Phone phone = getPhone(subId);
10439 if (phone == null) {
10440 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10441 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10442 }
10443 return phone.getEmergencyNumberDbVersion();
10444 } finally {
10445 Binder.restoreCallingIdentity(identity);
10446 }
10447 }
10448
10449 @Override
10450 public void notifyOtaEmergencyNumberDbInstalled() {
10451 enforceModifyPermission();
10452
joonhunshin4ac60942023-11-15 15:23:39 +000010453 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10454 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10455
Shuo Qian3b6ee772019-11-13 17:43:31 -080010456 final long identity = Binder.clearCallingIdentity();
10457 try {
10458 for (Phone phone: PhoneFactory.getPhones()) {
10459 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10460 if (tracker != null) {
10461 tracker.updateOtaEmergencyNumberDatabase();
10462 }
10463 }
10464 } finally {
10465 Binder.restoreCallingIdentity(identity);
10466 }
10467 }
10468
10469 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010470 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010471 enforceActiveEmergencySessionPermission();
10472
joonhunshin4ac60942023-11-15 15:23:39 +000010473 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10474 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10475
Shuo Qian3b6ee772019-11-13 17:43:31 -080010476 final long identity = Binder.clearCallingIdentity();
10477 try {
10478 for (Phone phone: PhoneFactory.getPhones()) {
10479 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10480 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010481 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10482 }
10483 }
10484 } finally {
10485 Binder.restoreCallingIdentity(identity);
10486 }
10487 }
10488
10489 @Override
10490 public void resetOtaEmergencyNumberDbFilePath() {
10491 enforceActiveEmergencySessionPermission();
10492
joonhunshin4ac60942023-11-15 15:23:39 +000010493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10494 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10495
Shuo Qianc373f112020-03-05 17:55:34 -080010496 final long identity = Binder.clearCallingIdentity();
10497 try {
10498 for (Phone phone: PhoneFactory.getPhones()) {
10499 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10500 if (tracker != null) {
10501 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010502 }
10503 }
10504 } finally {
10505 Binder.restoreCallingIdentity(identity);
10506 }
10507 }
10508
10509 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010510 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10511 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10512 Phone phone = getPhone(subId);
10513 if (phone == null) {
10514 return null;
10515 }
10516 final long identity = Binder.clearCallingIdentity();
10517 try {
10518 UiccProfile profile = UiccController.getInstance()
10519 .getUiccProfileForPhone(phone.getPhoneId());
10520 if (profile != null) {
10521 return profile.getCertsFromCarrierPrivilegeAccessRules();
10522 }
10523 } finally {
10524 Binder.restoreCallingIdentity(identity);
10525 }
10526 return null;
10527 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010528
10529 /**
10530 * Enable or disable a modem stack.
10531 */
10532 @Override
10533 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10534 enforceModifyPermission();
10535
joonhunshin4ac60942023-11-15 15:23:39 +000010536 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10537 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10538
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010539 final long identity = Binder.clearCallingIdentity();
10540 try {
10541 Phone phone = PhoneFactory.getPhone(slotIndex);
10542 if (phone == null) {
10543 return false;
10544 } else {
10545 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10546 }
10547 } finally {
10548 Binder.restoreCallingIdentity(identity);
10549 }
10550 }
Michelecea4cf22018-12-21 15:00:11 -080010551
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010552 /**
10553 * Whether a modem stack is enabled or not.
10554 */
10555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010556 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10557 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010558 Phone phone = PhoneFactory.getPhone(slotIndex);
10559 if (phone == null) return false;
10560
10561 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010562 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10563 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010564 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10565 }
10566
joonhunshin4ac60942023-11-15 15:23:39 +000010567 enforceTelephonyFeatureWithException(callingPackage,
10568 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10569
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010570 final long identity = Binder.clearCallingIdentity();
10571 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010572 try {
10573 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10574 } catch (NoSuchElementException ex) {
10575 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10576 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010577 } finally {
10578 Binder.restoreCallingIdentity(identity);
10579 }
10580 }
10581
Michelecea4cf22018-12-21 15:00:11 -080010582 @Override
Michele0ea7d782019-03-19 14:58:42 -070010583 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010584 enforceModifyPermission();
10585
joonhunshin4ac60942023-11-15 15:23:39 +000010586 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10587 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10588
Michelecea4cf22018-12-21 15:00:11 -080010589 final long identity = Binder.clearCallingIdentity();
10590 try {
10591 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010592 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010593 .commit();
10594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
10598
10599 @Override
Michele0ea7d782019-03-19 14:58:42 -070010600 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010601 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010603 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10604 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010605 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010606 }
Michelecea4cf22018-12-21 15:00:11 -080010607
joonhunshin4ac60942023-11-15 15:23:39 +000010608 enforceTelephonyFeatureWithException(callingPackage,
10609 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10610
Michelecea4cf22018-12-21 15:00:11 -080010611 final long identity = Binder.clearCallingIdentity();
10612 try {
Michele0ea7d782019-03-19 14:58:42 -070010613 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010614 } finally {
10615 Binder.restoreCallingIdentity(identity);
10616 }
10617 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010618
Michele0ea7d782019-03-19 14:58:42 -070010619 @TelephonyManager.IsMultiSimSupportedResult
10620 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010621 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10622 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10623 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010624 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10625 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010626 }
10627 // Check if the hardware supports multisim functionality. If usage of multisim is not
10628 // supported by the modem, indicate that it is restricted.
10629 PhoneCapability staticCapability =
10630 mPhoneConfigurationManager.getStaticPhoneCapability();
10631 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010632 loge("isMultiSimSupportedInternal: no static configuration available");
10633 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010634 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010635 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010636 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10637 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010638 }
10639 // Check if support of multiple SIMs is restricted by carrier
10640 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010641 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010642 }
10643
Michele0ea7d782019-03-19 14:58:42 -070010644 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010645 }
10646
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010647 /**
10648 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010649 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10650 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10651 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010652 * @param numOfSims number of active sims we want to switch to
10653 */
10654 @Override
10655 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010656 if (numOfSims == 1) {
10657 enforceModifyPermission();
10658 } else {
10659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10660 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10661 }
joonhunshin4ac60942023-11-15 15:23:39 +000010662
10663 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10664 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10665
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010666 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010667
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010668 try {
Michele30b57b22019-03-01 12:01:14 -080010669 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010670 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010671 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10672 return;
10673 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010674 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10675 } finally {
10676 Binder.restoreCallingIdentity(identity);
10677 }
10678 }
10679
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010680 @Override
10681 public boolean isApplicationOnUicc(int subId, int appType) {
10682 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010683
10684 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10685 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10686
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010687 Phone phone = getPhone(subId);
10688 if (phone == null) {
10689 return false;
10690 }
10691 final long identity = Binder.clearCallingIdentity();
10692 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010693 UiccPort uiccPort = phone.getUiccPort();
10694 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010695 return false;
10696 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010697 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010698 if (uiccProfile == null) {
10699 return false;
10700 }
10701 if (TelephonyManager.APPTYPE_SIM <= appType
10702 && appType <= TelephonyManager.APPTYPE_ISIM) {
10703 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10704 }
10705 return false;
10706 } finally {
10707 Binder.restoreCallingIdentity(identity);
10708 }
10709 }
10710
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010711 /**
chen xub4baa772019-04-03 10:23:41 -070010712 * Get whether making changes to modem configurations will trigger reboot.
10713 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010714 */
10715 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010716 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10717 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010719 mApp, subId, callingPackage, callingFeatureId,
10720 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010721 return false;
10722 }
joonhunshin4ac60942023-11-15 15:23:39 +000010723
10724 enforceTelephonyFeatureWithException(callingPackage,
10725 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10726 "doesSwitchMultiSimConfigTriggerReboot");
10727
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010728 final long identity = Binder.clearCallingIdentity();
10729 try {
10730 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10731 } finally {
10732 Binder.restoreCallingIdentity(identity);
10733 }
10734 }
10735
Nathan Harold29f5f052019-02-15 13:41:57 -080010736 private void updateModemStateMetrics() {
10737 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10738 // TODO: check the state for each modem if the api is ready.
10739 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10740 }
10741
Pengquan Meng3889a572019-01-23 11:16:29 -080010742 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010743 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010744 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010745 // Verify that the callingPackage belongs to the calling UID
10746 mApp.getSystemService(AppOpsManager.class)
10747 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010748
10749 enforceTelephonyFeatureWithException(callingPackage,
10750 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10751
Pengquan Meng3889a572019-01-23 11:16:29 -080010752 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010753 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010754 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010755 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10756 if (slotInfos != null) {
10757 for (int i = 0; i < slotInfos.length; i++) {
10758 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10759 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10760 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10761 portInfo.getLogicalSlotIndex()));
10762 }
10763 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010764 }
10765 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010766 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010767 } finally {
10768 Binder.restoreCallingIdentity(identity);
10769 }
10770 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010771
10772 /**
10773 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010774 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010775 */
jimsunf9ec1622022-09-13 21:18:43 +080010776 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010777 @Override
10778 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010779 return getHalVersion(HAL_SERVICE_RADIO);
10780 }
10781
10782 /**
10783 * Get the HAL Version of a specific service
10784 */
10785 @Override
10786 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010787 Phone phone = getDefaultPhone();
10788 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010789 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010790 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10791 return hv.major * 100 + hv.minor;
10792 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010793
10794 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010795 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010796 *
10797 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010798 */
10799 @Override
sangyun097dcf72024-01-04 10:35:49 +090010800 public @Nullable String getCurrentPackageName() {
10801 PackageManager pm = mApp.getPackageManager();
10802 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10803 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010804 }
10805
10806 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010807 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10808 * corresponding network requests on a subId.
10809 *
10810 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010811 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010812 * 2) APN is un-metered for this subscription, or
10813 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010814 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010815 *
10816 * @return whether data is allowed for a apn type.
10817 *
10818 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010819 */
10820 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010821 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010822 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10823 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010824
joonhunshin4ac60942023-11-15 15:23:39 +000010825 enforceTelephonyFeatureWithException(callingPackage,
10826 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10827
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010828 // Now that all security checks passes, perform the operation as ourselves.
10829 final long identity = Binder.clearCallingIdentity();
10830 try {
10831 Phone phone = getPhone(subId);
10832 if (phone == null) return false;
10833
Jack Yu27422a52022-03-21 10:38:05 -070010834 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010835 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010836 isMetered = phone.getDataNetworkController().getDataConfigManager()
10837 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10838 phone.getServiceState().getDataRoaming());
10839 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010840 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010841 } finally {
10842 Binder.restoreCallingIdentity(identity);
10843 }
10844 }
10845
10846 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010847 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010848 enforceReadPrivilegedPermission("isApnMetered");
10849
joonhunshin4ac60942023-11-15 15:23:39 +000010850 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10851 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10852
Malcolm Chene5ad5792019-04-18 13:51:02 -070010853 // Now that all security checks passes, perform the operation as ourselves.
10854 final long identity = Binder.clearCallingIdentity();
10855 try {
10856 Phone phone = getPhone(subId);
10857 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010858 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10859 DataUtils.apnTypeToNetworkCapability(apnType),
10860 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010861 } finally {
10862 Binder.restoreCallingIdentity(identity);
10863 }
10864 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010865
10866 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010867 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10868 int subscriptionId, IBooleanConsumer resultCallback) {
10869 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010870
10871 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10872 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10873
Hall Liu73f5d362020-01-20 13:42:00 -080010874 long token = Binder.clearCallingIdentity();
10875 try {
10876 Phone phone = getPhone(subscriptionId);
10877 if (phone == null) {
10878 try {
10879 if (resultCallback != null) {
10880 resultCallback.accept(false);
10881 }
10882 } catch (RemoteException e) {
10883 // ignore
10884 }
10885 return;
10886 }
10887 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10888 Pair.create(specifiers, (x) -> {
10889 try {
10890 if (resultCallback != null) {
10891 resultCallback.accept(x);
10892 }
10893 } catch (RemoteException e) {
10894 // ignore
10895 }
10896 });
10897 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10898 } finally {
10899 Binder.restoreCallingIdentity(token);
10900 }
10901 }
10902
10903 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010904 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10905 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010906 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010907 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010908
10909 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10910 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10911
Sarah Chin679c08a2020-11-18 13:39:35 -080010912 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10913 final long identity = Binder.clearCallingIdentity();
10914 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010915 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10916 if (result instanceof IllegalStateException) {
10917 throw (IllegalStateException) result;
10918 }
10919 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010920 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10921 return specifiers;
10922 } finally {
10923 Binder.restoreCallingIdentity(identity);
10924 }
10925 }
10926
10927 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010928 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010929 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010930
10931 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10932 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10933
Jack Yu8b766fc2022-03-21 09:42:33 -070010934 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010935 }
10936
10937 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010938 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10939 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010940 if (callingPackage == null) {
10941 callingPackage = getCurrentPackageName();
10942 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010943 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10944 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010945 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10946 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010947 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10948 }
10949 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10950 Intent intent = new Intent();
10951 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10952 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10953 // Bring up choose default SMS subscription dialog right now
10954 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10955 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10956 mApp.startActivity(intent);
10957 }
chen xud5ca2d52019-05-28 15:20:57 -070010958
10959 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010960 public void showSwitchToManagedProfileDialog() {
10961 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010962 try {
10963 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10964 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10965 // for work telephony.
10966 Intent intent = new Intent(Intent.ACTION_SENDTO);
10967 intent.setData(Uri.parse("smsto:"));
10968 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10969 mApp.startActivity(intent);
10970 } catch (ActivityNotFoundException e) {
10971 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10972 Intent intent = new Intent();
10973 intent.setClass(mApp, ErrorDialogActivity.class);
10974 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10975 mApp.startActivity(intent);
10976 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010977 }
10978
10979 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010980 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010981 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10982 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10983
chen xud5ca2d52019-05-28 15:20:57 -070010984 //TODO investigate if this API should require proper permission check in R b/133791609
10985 final long identity = Binder.clearCallingIdentity();
10986 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010987 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10988 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10989 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10990 return carrierUAProfUrl;
10991 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010992 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10993 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010994 } finally {
10995 Binder.restoreCallingIdentity(identity);
10996 }
10997 }
10998
10999 @Override
11000 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011001 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11002 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11003
chen xud5ca2d52019-05-28 15:20:57 -070011004 //TODO investigate if this API should require proper permission check in R b/133791609
11005 final long identity = Binder.clearCallingIdentity();
11006 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011007 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11008 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11009 if (!TextUtils.isEmpty(carrierUserAgent)) {
11010 return carrierUserAgent;
11011 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011012 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11013 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011014 } finally {
11015 Binder.restoreCallingIdentity(identity);
11016 }
11017 }
Jack Yub07d4972019-05-28 16:12:25 -070011018
11019 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011020 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11021 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011022
joonhunshin4ac60942023-11-15 15:23:39 +000011023 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11024 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11025
Jack Yub07d4972019-05-28 16:12:25 -070011026 final long identity = Binder.clearCallingIdentity();
11027 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011028 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011029 if (phone == null) return false;
11030
Ling Maf188d502022-09-16 15:22:36 -070011031 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011032 } finally {
11033 Binder.restoreCallingIdentity(identity);
11034 }
11035 }
11036
11037 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011038 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011039 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011040 enforceModifyPermission();
11041
joonhunshin4ac60942023-11-15 15:23:39 +000011042 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11043 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11044
changbettyd5c246e2019-12-24 15:40:37 +080011045 final long identity = Binder.clearCallingIdentity();
11046 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011047 Phone phone = getPhone(subscriptionId);
11048 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011049
Ling Maf188d502022-09-16 15:22:36 -070011050 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011051 } finally {
11052 Binder.restoreCallingIdentity(identity);
11053 }
11054 }
11055
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011056 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011057 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011058 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11059 * otherwise.
11060 */
11061 @Override
11062 public void setCepEnabled(boolean isCepEnabled) {
11063 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11064
11065 final long identity = Binder.clearCallingIdentity();
11066 try {
11067 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11068 for (Phone phone : PhoneFactory.getPhones()) {
11069 Phone defaultPhone = phone.getImsPhone();
11070 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11071 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11072 ImsPhoneCallTracker imsPhoneCallTracker =
11073 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11074 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11075 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11076 + imsPhone.getMsisdn());
11077 }
11078 }
11079 } finally {
11080 Binder.restoreCallingIdentity(identity);
11081 }
11082 }
allenwtsu46dcc572020-01-08 18:24:03 +080011083
11084 /**
11085 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11086 *
11087 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11088 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11089 * before being read.
11090 */
11091 @Override
11092 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11093 isCompressed) {
11094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11095 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011096 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11097 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11098 }
joonhunshin4ac60942023-11-15 15:23:39 +000011099
11100 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11101 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11102 Binder.getCallingUserHandle())) {
11103 if (!isImsAvailableOnDevice()) {
11104 // ProvisioningManager can not handle ServiceSpecificException.
11105 // Throw the IllegalStateException and annotate ProvisioningManager.
11106 throw new IllegalStateException("IMS not available on device.");
11107 }
11108 } else {
11109 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11110 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11111 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011112 }
11113
11114 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011115 try {
Hui Wang761a6682020-10-31 05:12:53 +000011116 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11117 } finally {
11118 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011119 }
11120 }
zoey chene02881a2019-12-30 16:11:23 +080011121
11122 @Override
11123 public boolean isIccLockEnabled(int subId) {
11124 enforceReadPrivilegedPermission("isIccLockEnabled");
11125
joonhunshin4ac60942023-11-15 15:23:39 +000011126 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11127 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11128
zoey chene02881a2019-12-30 16:11:23 +080011129 // Now that all security checks passes, perform the operation as ourselves.
11130 final long identity = Binder.clearCallingIdentity();
11131 try {
11132 Phone phone = getPhone(subId);
11133 if (phone != null && phone.getIccCard() != null) {
11134 return phone.getIccCard().getIccLockEnabled();
11135 } else {
11136 return false;
11137 }
11138 } finally {
11139 Binder.restoreCallingIdentity(identity);
11140 }
11141 }
11142
11143 /**
11144 * Set the ICC pin lock enabled or disabled.
11145 *
11146 * @return an integer representing the status of IccLock enabled or disabled in the following
11147 * three cases:
11148 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11149 * successfully.
11150 * - Positive number and zero for remaining password attempts.
11151 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11152 *
11153 */
11154 @Override
11155 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11156 enforceModifyPermission();
11157
joonhunshin4ac60942023-11-15 15:23:39 +000011158 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11159 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11160
zoey chene02881a2019-12-30 16:11:23 +080011161 Phone phone = getPhone(subId);
11162 if (phone == null) {
11163 return 0;
11164 }
11165 // Now that all security checks passes, perform the operation as ourselves.
11166 final long identity = Binder.clearCallingIdentity();
11167 try {
11168 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11169 new Pair<Boolean, String>(enabled, password), phone, null);
11170 return attemptsRemaining;
11171
11172 } catch (Exception e) {
11173 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11174 } finally {
11175 Binder.restoreCallingIdentity(identity);
11176 }
11177 return 0;
11178 }
11179
11180 /**
11181 * Change the ICC password used in ICC pin lock.
11182 *
11183 * @return an integer representing the status of IccLock changed in the following three cases:
11184 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11185 * - Positive number and zero for remaining password attempts.
11186 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11187 *
11188 */
11189 @Override
11190 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11191 enforceModifyPermission();
11192
joonhunshin4ac60942023-11-15 15:23:39 +000011193 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11194 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11195
zoey chene02881a2019-12-30 16:11:23 +080011196 Phone phone = getPhone(subId);
11197 if (phone == null) {
11198 return 0;
11199 }
11200 // Now that all security checks passes, perform the operation as ourselves.
11201 final long identity = Binder.clearCallingIdentity();
11202 try {
11203 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11204 new Pair<String, String>(oldPassword, newPassword), phone, null);
11205 return attemptsRemaining;
11206
11207 } catch (Exception e) {
11208 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11209 } finally {
11210 Binder.restoreCallingIdentity(identity);
11211 }
11212 return 0;
11213 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011214
11215 /**
11216 * Request for receiving user activity notification
11217 */
11218 @Override
11219 public void requestUserActivityNotification() {
11220 if (!mNotifyUserActivity.get()
11221 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11222 mNotifyUserActivity.set(true);
11223 }
11224 }
11225
11226 /**
11227 * Called when userActivity is signalled in the power manager.
11228 * This is safe to call from any thread, with any window manager locks held or not.
11229 */
11230 @Override
11231 public void userActivity() {
11232 // ***************************************
11233 // * Inherited from PhoneWindowManager *
11234 // ***************************************
11235 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11236 // WITH ITS LOCKS HELD.
11237 //
11238 // This code must be VERY careful about the locks
11239 // it acquires.
11240 // In fact, the current code acquires way too many,
11241 // and probably has lurking deadlocks.
11242
11243 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11244 throw new SecurityException("Only the OS may call notifyUserActivity()");
11245 }
11246
11247 if (mNotifyUserActivity.getAndSet(false)) {
11248 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11249 USER_ACTIVITY_NOTIFICATION_DELAY);
11250 }
11251 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011252
11253 @Override
11254 public boolean canConnectTo5GInDsdsMode() {
11255 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11256 }
Jack Yud10cdd42020-09-28 20:28:01 -070011257
11258 @Override
11259 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11260 String callingFeatureId) {
11261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11262 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11263 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11264 }
11265
joonhunshin4ac60942023-11-15 15:23:39 +000011266 enforceTelephonyFeatureWithException(callingPackage,
11267 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11268
Jack Yud10cdd42020-09-28 20:28:01 -070011269 Phone phone = getPhone(subId);
11270 if (phone == null) {
11271 throw new RuntimeException("phone is not available");
11272 }
11273 // Now that all security checks passes, perform the operation as ourselves.
11274 final long identity = Binder.clearCallingIdentity();
11275 try {
11276 return phone.getEquivalentHomePlmns();
11277 } finally {
11278 Binder.restoreCallingIdentity(identity);
11279 }
11280 }
Daniel Bright59e67312020-11-13 11:49:37 -080011281
11282 @Override
11283 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011284 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011285 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11286 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11287 "isRadioInterfaceCapabilitySupported");
11288
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011289 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011290 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011291 if (radioInterfaceCapabilities == null) {
11292 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011293 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011294 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011295 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011296
Hui Wang641e81c2020-10-12 12:14:23 -070011297 @Override
11298 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11299 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011300 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11301 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11302 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11303 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11304 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011305
11306 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11307 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11308
Hui Wang641e81c2020-10-12 12:14:23 -070011309 if (DBG) {
11310 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11311 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11312 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11313 }
11314
11315 if (!SubscriptionManager.isValidSubscriptionId(subId)
11316 || appType < TelephonyManager.APPTYPE_UNKNOWN
11317 || appType > TelephonyManager.APPTYPE_ISIM
11318 || nafUrl == null || securityProtocol == null || callback == null) {
11319 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11320 if (callback != null) {
11321 try {
11322 callback.onAuthenticationFailure(
11323 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11324 } catch (RemoteException exception) {
11325 log("Fail to notify onAuthenticationFailure due to " + exception);
11326 }
11327 return;
11328 }
11329 }
11330
11331 final long token = Binder.clearCallingIdentity();
11332 try {
11333 getGbaManager(subId).bootstrapAuthenticationRequest(
11334 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011335 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011336 } finally {
11337 Binder.restoreCallingIdentity(token);
11338 }
11339 }
11340
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011341 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011342 * Attempts to set the radio power state for all phones for thermal reason.
11343 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011344 * requested radio power state will actually be set. See {@link
11345 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11346 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011347 * @param enable {@code true} if trying to turn radio on.
11348 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11349 * false}.
11350 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011351 private boolean setRadioPowerForThermal(boolean enable) {
11352 boolean isPhoneAvailable = false;
11353 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11354 Phone phone = PhoneFactory.getPhone(i);
11355 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011356 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011357 isPhoneAvailable = true;
11358 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011359 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011360
11361 // return true if successfully informed the phone object about the thermal radio power
11362 // request.
11363 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011364 }
11365
11366 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011367 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011368 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11369 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11370 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11371 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11372 throw new IllegalArgumentException("modem does not support data throttling");
11373 }
11374
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011375 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11376 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011377 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011378 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11379 }
11380
Sarah Chinecc78c42022-03-31 21:16:48 -070011381 setDataEnabledForReason(
11382 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011383
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011384 if (isDataThrottlingSupported) {
11385 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011386 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011387 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11388 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11389 } else if (thermalMitigationResult
11390 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011391 log("Modem likely does not support data throttling on secondary carrier. Data " +
11392 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11393 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011394 }
11395 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011396 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011397
11398 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011399 }
11400
Jack Nudelman644b91a2021-03-12 14:09:48 -080011401 private static List<String> getThermalMitigationAllowlist(Context context) {
11402 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11403 for (String pckg : context.getResources()
11404 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11405 sThermalMitigationAllowlistedPackages.add(pckg);
11406 }
11407 }
11408
11409 return sThermalMitigationAllowlistedPackages;
11410 }
11411
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011412 private boolean isAnyPhoneInEmergencyState() {
11413 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11414 if (tm.isInEmergencyCall()) {
11415 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11416 return true;
11417 }
11418 for (Phone phone : PhoneFactory.getPhones()) {
11419 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11420 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011421 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11422 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011423 return true;
11424 }
11425 }
11426
11427 return false;
11428 }
11429
Jack Nudelman644b91a2021-03-12 14:09:48 -080011430 /**
11431 * Used by shell commands to add an authorized package name for thermal mitigation.
11432 * @param packageName name of package to be allowlisted
11433 * @param context
11434 */
11435 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11436 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11437 sThermalMitigationAllowlistedPackages.add(packageName);
11438 }
11439
11440 /**
11441 * Used by shell commands to remove an authorized package name for thermal mitigation.
11442 * @param packageName name of package to remove from allowlist
11443 * @param context
11444 */
11445 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11446 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11447 sThermalMitigationAllowlistedPackages.remove(packageName);
11448 }
11449
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011450 /**
11451 * Thermal mitigation request to control functionalities at modem.
11452 *
11453 * @param subId the id of the subscription.
11454 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011455 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011456 *
11457 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11458 */
11459 @Override
11460 @ThermalMitigationResult
11461 public int sendThermalMitigationRequest(
11462 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011463 ThermalMitigationRequest thermalMitigationRequest,
11464 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011465 enforceModifyPermission();
11466
Jack Nudelman644b91a2021-03-12 14:09:48 -080011467 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011468
11469 enforceTelephonyFeatureWithException(callingPackage,
11470 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11471
Jack Nudelman644b91a2021-03-12 14:09:48 -080011472 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11473 .contains(callingPackage)) {
11474 throw new SecurityException("Calling package must be configured in the device config. "
11475 + "calling package: " + callingPackage);
11476 }
11477
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011478 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11479 final long identity = Binder.clearCallingIdentity();
11480
11481 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11482 try {
11483 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11484 switch (thermalMitigationAction) {
11485 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11486 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011487 handleDataThrottlingRequest(subId,
11488 thermalMitigationRequest.getDataThrottlingRequest(),
11489 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011490 break;
11491 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11492 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11493 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11494 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11495 }
11496
11497 // Ensure that radio is on. If not able to power on due to phone being
11498 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011499 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011500 thermalMitigationResult =
11501 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11502 break;
11503 }
11504
11505 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011506 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011507 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11508 break;
11509 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11510 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11511 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11512 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11513 }
11514
11515 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11516 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011517 Phone phone = getPhone(subId);
11518 if (phone == null) {
11519 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011520 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011521 break;
11522 }
11523
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011524 TelephonyConnectionService service =
11525 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011526 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011527 Log.e(LOG_TAG, "An emergency call is pending");
11528 thermalMitigationResult =
11529 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11530 break;
11531 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011532 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011533 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011534 break;
11535 }
11536 } else {
11537 thermalMitigationResult =
11538 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11539 break;
11540 }
11541
11542 // Turn radio off. If not able to power off due to phone being unavailable,
11543 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011544 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011545 thermalMitigationResult =
11546 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11547 break;
11548 }
11549 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011550 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011551 break;
11552 default:
11553 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11554 + "not exist. Requested action: " + thermalMitigationAction);
11555 }
11556 } catch (IllegalArgumentException e) {
11557 throw e;
11558 } catch (Exception e) {
11559 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11560 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11561 } finally {
11562 Binder.restoreCallingIdentity(identity);
11563 }
11564
11565 if (DBG) {
11566 log("thermalMitigationRequest returning with thermalMitigationResult: "
11567 + thermalMitigationResult);
11568 }
11569
11570 return thermalMitigationResult;
11571 }
Hui Wang641e81c2020-10-12 12:14:23 -070011572
11573 /**
11574 * Set the GbaService Package Name that Telephony will bind to.
11575 *
11576 * @param subId The sim that the GbaService is associated with.
11577 * @param packageName The name of the package to be replaced with.
11578 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11579 */
11580 @Override
11581 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11582 enforceModifyPermission();
11583
11584 final long identity = Binder.clearCallingIdentity();
11585 try {
11586 return getGbaManager(subId).overrideServicePackage(packageName);
11587 } finally {
11588 Binder.restoreCallingIdentity(identity);
11589 }
11590 }
11591
11592 /**
11593 * Return the package name of the currently bound GbaService.
11594 *
11595 * @param subId The sim that the GbaService is associated with.
11596 * @return the package name of the GbaService configuration, null if GBA is not supported.
11597 */
11598 @Override
11599 public String getBoundGbaService(int subId) {
11600 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11601
11602 final long identity = Binder.clearCallingIdentity();
11603 try {
11604 return getGbaManager(subId).getServicePackage();
11605 } finally {
11606 Binder.restoreCallingIdentity(identity);
11607 }
11608 }
11609
11610 /**
11611 * Set the release time for telephony to unbind GbaService.
11612 *
11613 * @param subId The sim that the GbaService is associated with.
11614 * @param interval The release time to unbind GbaService by millisecond.
11615 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11616 */
11617 @Override
11618 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11619 enforceModifyPermission();
11620
11621 final long identity = Binder.clearCallingIdentity();
11622 try {
11623 return getGbaManager(subId).overrideReleaseTime(interval);
11624 } finally {
11625 Binder.restoreCallingIdentity(identity);
11626 }
11627 }
11628
11629 /**
11630 * Return the release time for telephony to unbind GbaService.
11631 *
11632 * @param subId The sim that the GbaService is associated with.
11633 * @return The release time to unbind GbaService by millisecond.
11634 */
11635 @Override
11636 public int getGbaReleaseTime(int subId) {
11637 enforceReadPrivilegedPermission("getGbaReleaseTime");
11638
11639 final long identity = Binder.clearCallingIdentity();
11640 try {
11641 return getGbaManager(subId).getReleaseTime();
11642 } finally {
11643 Binder.restoreCallingIdentity(identity);
11644 }
11645 }
11646
11647 private GbaManager getGbaManager(int subId) {
11648 GbaManager instance = GbaManager.getInstance(subId);
11649 if (instance == null) {
11650 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11651 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11652 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11653 }
11654 return instance;
11655 }
Hui Wang761a6682020-10-31 05:12:53 +000011656
11657 /**
11658 * indicate whether the device and the carrier can support
11659 * RCS VoLTE single registration.
11660 */
11661 @Override
11662 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011663 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11664 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11665 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11666 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011667
11668 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11669 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11670 }
11671
11672 final long identity = Binder.clearCallingIdentity();
11673 try {
11674 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11675 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011676 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11677 if (isCapable != null) {
11678 return isCapable;
11679 }
Hui Wang761a6682020-10-31 05:12:53 +000011680 }
Hui Wang67af90e2021-06-04 16:57:15 -070011681 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11682 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011683 } finally {
11684 Binder.restoreCallingIdentity(identity);
11685 }
11686 }
11687
11688 /**
11689 * Register RCS provisioning callback.
11690 */
11691 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011692 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011693 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011694 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011695 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011696 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11697 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011698
11699 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11700 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11701 }
joonhunshin4ac60942023-11-15 15:23:39 +000011702 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11703 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11704 Binder.getCallingUserHandle())) {
11705 if (!isImsAvailableOnDevice()) {
11706 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11707 "IMS not available on device.");
11708 }
11709 } else {
11710 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11711 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011712 }
11713
11714 final long identity = Binder.clearCallingIdentity();
11715 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011716 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011717 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011718 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11719 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011720 }
Hui Wang761a6682020-10-31 05:12:53 +000011721 } finally {
11722 Binder.restoreCallingIdentity(identity);
11723 }
11724 }
11725
11726 /**
11727 * Unregister RCS provisioning callback.
11728 */
11729 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011730 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011731 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011732 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011733 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011734 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11735 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011736
11737 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11738 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11739 }
joonhunshin4ac60942023-11-15 15:23:39 +000011740
11741 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11742 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11743 Binder.getCallingUserHandle())) {
11744 if (!isImsAvailableOnDevice()) {
11745 // operation failed silently
11746 Rlog.w(LOG_TAG, "IMS not available on device.");
11747 return;
11748 }
11749 } else {
11750 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11751 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11752 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011753 }
11754
11755 final long identity = Binder.clearCallingIdentity();
11756 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011757 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011758 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011759 } finally {
11760 Binder.restoreCallingIdentity(identity);
11761 }
11762 }
11763
11764 /**
11765 * trigger RCS reconfiguration.
11766 */
11767 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011768 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11769 "triggerRcsReconfiguration",
11770 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011771
11772 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11773 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11774 }
joonhunshin4ac60942023-11-15 15:23:39 +000011775 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11776 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11777 Binder.getCallingUserHandle())) {
11778 if (!isImsAvailableOnDevice()) {
11779 // ProvisioningManager can not handle ServiceSpecificException.
11780 // Throw the IllegalStateException and annotate ProvisioningManager.
11781 throw new IllegalStateException("IMS not available on device.");
11782 }
11783 } else {
11784 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11785 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011786 }
11787
11788 final long identity = Binder.clearCallingIdentity();
11789 try {
11790 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11791 } finally {
11792 Binder.restoreCallingIdentity(identity);
11793 }
11794 }
11795
11796 /**
11797 * Provide the client configuration parameters of the RCS application.
11798 */
11799 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011800 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11801 "setRcsClientConfiguration",
11802 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011803
11804 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11805 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11806 }
joonhunshin4ac60942023-11-15 15:23:39 +000011807 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11808 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11809 Binder.getCallingUserHandle())) {
11810 if (!isImsAvailableOnDevice()) {
11811 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11812 "IMS not available on device.");
11813 }
11814 } else {
11815 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11816 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011817 }
11818
11819 final long identity = Binder.clearCallingIdentity();
11820
11821 try {
11822 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11823 if (configBinder == null) {
11824 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011825 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11826 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011827 } else {
11828 configBinder.setRcsClientConfiguration(rcc);
11829 }
joonhunshin3e154242021-09-17 06:33:39 +000011830
11831 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11832 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011833 } catch (RemoteException e) {
11834 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011835 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11836 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011837 } finally {
11838 Binder.restoreCallingIdentity(identity);
11839 }
11840 }
11841
11842 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011843 * Enables or disables the test mode for RCS VoLTE single registration.
11844 */
11845 @Override
11846 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11848 "setRcsSingleRegistrationTestModeEnabled");
11849
11850 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11851 }
11852
11853 /**
11854 * Gets the test mode for RCS VoLTE single registration.
11855 */
11856 @Override
11857 public boolean getRcsSingleRegistrationTestModeEnabled() {
11858 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11859 "getRcsSingleRegistrationTestModeEnabled");
11860
11861 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11862 }
11863
11864 /**
Hui Wang761a6682020-10-31 05:12:53 +000011865 * Overrides the config of RCS VoLTE single registration enabled for the device.
11866 */
11867 @Override
11868 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11869 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11870 "setDeviceSingleRegistrationEnabledOverride");
11871 enforceModifyPermission();
11872
11873 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11874 : Boolean.parseBoolean(enabledStr);
11875 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011876 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011877 }
11878
11879 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011880 * Sends a device to device communication message. Only usable via shell.
11881 * @param message message to send.
11882 * @param value message value.
11883 */
11884 @Override
11885 public void sendDeviceToDeviceMessage(int message, int value) {
11886 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011887 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011888 enforceModifyPermission();
11889
11890 final long identity = Binder.clearCallingIdentity();
11891 try {
11892 TelephonyConnectionService service =
11893 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11894 if (service == null) {
11895 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11896 return;
11897 }
11898 service.sendTestDeviceToDeviceMessage(message, value);
11899 } finally {
11900 Binder.restoreCallingIdentity(identity);
11901 }
11902 }
11903
Tyler Gunnbabbda02021-02-10 11:05:02 -080011904 /**
11905 * Sets the specified device to device transport active.
11906 * @param transport The transport to set active.
11907 */
11908 @Override
11909 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11910 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11911 "setActiveDeviceToDeviceTransport");
11912 enforceModifyPermission();
11913
11914 final long identity = Binder.clearCallingIdentity();
11915 try {
11916 TelephonyConnectionService service =
11917 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11918 if (service == null) {
11919 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11920 return;
11921 }
11922 service.setActiveDeviceToDeviceTransport(transport);
11923 } finally {
11924 Binder.restoreCallingIdentity(identity);
11925 }
11926 }
Tyler Gunn92479152021-01-20 16:30:10 -080011927
Tyler Gunnd4339262021-05-03 14:46:49 -070011928 @Override
11929 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11930 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11931 "setDeviceToDeviceForceEnabled");
11932
11933 final long identity = Binder.clearCallingIdentity();
11934 try {
11935 Arrays.stream(PhoneFactory.getPhones()).forEach(
11936 p -> {
11937 Phone thePhone = p.getImsPhone();
11938 if (thePhone != null && thePhone instanceof ImsPhone) {
11939 ImsPhone imsPhone = (ImsPhone) thePhone;
11940 CallTracker tracker = imsPhone.getCallTracker();
11941 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11942 ImsPhoneCallTracker imsPhoneCallTracker =
11943 (ImsPhoneCallTracker) tracker;
11944 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11945 }
11946 }
11947 }
11948 );
11949 } finally {
11950 Binder.restoreCallingIdentity(identity);
11951 }
11952 }
11953
Tyler Gunn92479152021-01-20 16:30:10 -080011954 /**
Hui Wang761a6682020-10-31 05:12:53 +000011955 * Gets the config of RCS VoLTE single registration enabled for the device.
11956 */
11957 @Override
11958 public boolean getDeviceSingleRegistrationEnabled() {
11959 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11960 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11961 }
11962
11963 /**
11964 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11965 */
11966 @Override
11967 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11968 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11969 "setCarrierSingleRegistrationEnabledOverride");
11970 enforceModifyPermission();
11971
11972 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11973 : Boolean.parseBoolean(enabledStr);
11974 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11975 subId, enabled);
11976 }
11977
11978 /**
11979 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11980 */
11981 @Override
11982 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11983 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11984 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11985 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011986
11987 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011988 * Overrides the ims feature validation result
11989 */
11990 @Override
11991 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11992 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11993 "setImsFeatureValidationOverride");
11994
11995 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11996 : Boolean.parseBoolean(enabledStr);
11997 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11998 subId, enabled);
11999 }
12000
12001 /**
12002 * Gets the ims feature validation override value
12003 */
12004 @Override
12005 public boolean getImsFeatureValidationOverride(int subId) {
12006 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12007 "getImsFeatureValidationOverride");
12008 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12009 }
12010
12011 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012012 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12013 * their mobile plan.
12014 */
12015 @Override
12016 public String getMobileProvisioningUrl() {
12017 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12018 final long identity = Binder.clearCallingIdentity();
12019 try {
12020 return getDefaultPhone().getMobileProvisioningUrl();
12021 } finally {
12022 Binder.restoreCallingIdentity(identity);
12023 }
12024 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012025
James.cf Linbcdf8b32021-01-14 16:44:13 +080012026 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012027 * Get the EAB contact from the EAB database.
12028 */
12029 @Override
12030 public String getContactFromEab(String contact) {
12031 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12032 enforceModifyPermission();
12033 final long identity = Binder.clearCallingIdentity();
12034 try {
12035 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12036 } finally {
12037 Binder.restoreCallingIdentity(identity);
12038 }
12039 }
12040
12041 /**
Calvin Pana1434322021-07-01 19:27:01 +080012042 * Get the EAB capability from the EAB database.
12043 */
12044 @Override
12045 public String getCapabilityFromEab(String contact) {
12046 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12047 enforceModifyPermission();
12048 final long identity = Binder.clearCallingIdentity();
12049 try {
12050 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12051 } finally {
12052 Binder.restoreCallingIdentity(identity);
12053 }
12054 }
12055
12056 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012057 * Remove the EAB contacts from the EAB database.
12058 */
12059 @Override
12060 public int removeContactFromEab(int subId, String contacts) {
12061 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12062 enforceModifyPermission();
12063 final long identity = Binder.clearCallingIdentity();
12064 try {
12065 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12066 } finally {
12067 Binder.restoreCallingIdentity(identity);
12068 }
12069 }
12070
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012071 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012072 public boolean getDeviceUceEnabled() {
12073 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12074 final long identity = Binder.clearCallingIdentity();
12075 try {
12076 return mApp.getDeviceUceEnabled();
12077 } finally {
12078 Binder.restoreCallingIdentity(identity);
12079 }
12080 }
12081
12082 @Override
12083 public void setDeviceUceEnabled(boolean isEnabled) {
12084 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12085 final long identity = Binder.clearCallingIdentity();
12086 try {
12087 mApp.setDeviceUceEnabled(isEnabled);
12088 } finally {
12089 Binder.restoreCallingIdentity(identity);
12090 }
12091 }
12092
Brad Ebinger14d467f2021-02-12 06:18:28 +000012093 /**
12094 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12095 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12096 */
12097 // Used for SHELL command only right now.
12098 @Override
12099 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12100 List<String> featureTags) {
12101 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12102 "addUceRegistrationOverrideShell");
12103 final long identity = Binder.clearCallingIdentity();
12104 try {
12105 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12106 new ArraySet<>(featureTags));
12107 } catch (ImsException e) {
12108 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12109 } finally {
12110 Binder.restoreCallingIdentity(identity);
12111 }
12112 }
12113
12114 /**
12115 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12116 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12117 */
12118 // Used for SHELL command only right now.
12119 @Override
12120 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12121 List<String> featureTags) {
12122 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12123 "removeUceRegistrationOverrideShell");
12124 final long identity = Binder.clearCallingIdentity();
12125 try {
12126 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12127 new ArraySet<>(featureTags));
12128 } catch (ImsException e) {
12129 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12130 } finally {
12131 Binder.restoreCallingIdentity(identity);
12132 }
12133 }
12134
12135 /**
12136 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12137 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12138 */
12139 // Used for SHELL command only right now.
12140 @Override
12141 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12142 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12143 "clearUceRegistrationOverrideShell");
12144 final long identity = Binder.clearCallingIdentity();
12145 try {
12146 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12147 } catch (ImsException e) {
12148 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12149 } finally {
12150 Binder.restoreCallingIdentity(identity);
12151 }
12152 }
12153
12154 /**
12155 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12156 */
12157 // Used for SHELL command only right now.
12158 @Override
12159 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12160 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12161 "getLatestRcsContactUceCapabilityShell");
12162 final long identity = Binder.clearCallingIdentity();
12163 try {
12164 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12165 } catch (ImsException e) {
12166 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12167 } finally {
12168 Binder.restoreCallingIdentity(identity);
12169 }
12170 }
12171
12172 /**
12173 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12174 * device does not have an active PUBLISH.
12175 */
12176 // Used for SHELL command only right now.
12177 @Override
12178 public String getLastUcePidfXmlShell(int subId) {
12179 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12180 final long identity = Binder.clearCallingIdentity();
12181 try {
12182 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12183 } catch (ImsException e) {
12184 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12185 } finally {
12186 Binder.restoreCallingIdentity(identity);
12187 }
12188 }
12189
James.cf Line8713a42021-04-29 16:04:26 +080012190 /**
12191 * Remove UCE requests cannot be sent to the network status.
12192 */
12193 // Used for SHELL command only right now.
12194 @Override
12195 public boolean removeUceRequestDisallowedStatus(int subId) {
12196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12197 final long identity = Binder.clearCallingIdentity();
12198 try {
12199 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12200 } catch (ImsException e) {
12201 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12202 } finally {
12203 Binder.restoreCallingIdentity(identity);
12204 }
12205 }
12206
James.cf Lin18bb9002021-05-25 01:37:38 +080012207 /**
12208 * Remove UCE requests cannot be sent to the network status.
12209 */
12210 // Used for SHELL command only.
12211 @Override
12212 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12213 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12214 final long identity = Binder.clearCallingIdentity();
12215 try {
12216 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12217 } catch (ImsException e) {
12218 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12219 } finally {
12220 Binder.restoreCallingIdentity(identity);
12221 }
12222 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012223
James.cf Lin4b784aa2021-01-31 03:25:15 +080012224 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012225 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12226 String callingPackage) {
12227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12228 mApp, subId, "setSignalStrengthUpdateRequest");
12229
joonhunshin4ac60942023-11-15 15:23:39 +000012230 enforceTelephonyFeatureWithException(callingPackage,
12231 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12232
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012233 final int callingUid = Binder.getCallingUid();
12234 // Verify that tha callingPackage belongs to the calling UID
12235 mApp.getSystemService(AppOpsManager.class)
12236 .checkPackage(callingUid, callingPackage);
12237
Rambo Wang3607f502021-02-01 21:51:40 -080012238 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012239
12240 final long identity = Binder.clearCallingIdentity();
12241 try {
12242 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12243 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12244
12245 if (result instanceof IllegalStateException) {
12246 throw (IllegalStateException) result;
12247 }
12248 } finally {
12249 Binder.restoreCallingIdentity(identity);
12250 }
12251 }
12252
12253 @Override
12254 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12255 String callingPackage) {
12256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12257 mApp, subId, "clearSignalStrengthUpdateRequest");
12258
joonhunshin4ac60942023-11-15 15:23:39 +000012259 enforceTelephonyFeatureWithException(callingPackage,
12260 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12261
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012262 final int callingUid = Binder.getCallingUid();
12263 // Verify that tha callingPackage belongs to the calling UID
12264 mApp.getSystemService(AppOpsManager.class)
12265 .checkPackage(callingUid, callingPackage);
12266
12267 final long identity = Binder.clearCallingIdentity();
12268 try {
12269 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12270 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12271
12272 if (result instanceof IllegalStateException) {
12273 throw (IllegalStateException) result;
12274 }
12275 } finally {
12276 Binder.restoreCallingIdentity(identity);
12277 }
12278 }
12279
Rambo Wang3607f502021-02-01 21:51:40 -080012280 private static void validateSignalStrengthUpdateRequest(Context context,
12281 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012282 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12283 // phone/system process do not have further restriction on request
12284 return;
12285 }
12286
12287 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012288 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012289 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012290 context.enforceCallingOrSelfPermission(
12291 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12292 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012293 }
12294
12295 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012296 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012297 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012298 || info.isEnabled()) {
12299 throw new IllegalArgumentException(
12300 "Only system can set hide fields in SignalThresholdInfo");
12301 }
12302
12303 // Thresholds length for each RAN need in range. This has been validated in
12304 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12305 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12306 final int[] thresholds = info.getThresholds();
12307 Objects.requireNonNull(thresholds);
12308 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12309 || thresholds.length
12310 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12311 throw new IllegalArgumentException(
12312 "thresholds length is out of range: " + thresholds.length);
12313 }
12314 }
12315 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012316
12317 /**
12318 * Gets the current phone capability.
12319 *
12320 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12321 * @return the PhoneCapability which describes the data connection capability of modem.
12322 * It's used to evaluate possible phone config change, for example from single
12323 * SIM device to multi-SIM device.
12324 */
12325 @Override
12326 public PhoneCapability getPhoneCapability() {
12327 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012328
12329 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12330 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12331
SongFerngWang8236caa2021-01-17 21:51:44 +080012332 final long identity = Binder.clearCallingIdentity();
12333 try {
12334 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12335 } finally {
12336 Binder.restoreCallingIdentity(identity);
12337 }
12338 }
Michele Berionne5e411512020-11-13 02:36:59 +000012339
12340 /**
12341 * Prepare TelephonyManager for an unattended reboot. The reboot is
12342 * required to be done shortly after the API is invoked.
12343 */
12344 @Override
12345 @TelephonyManager.PrepareUnattendedRebootResult
12346 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012347 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012348 enforceRebootPermission();
12349
joonhunshin4ac60942023-11-15 15:23:39 +000012350 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12351 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12352
Michele Berionne5e411512020-11-13 02:36:59 +000012353 final long identity = Binder.clearCallingIdentity();
12354 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012355 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012356 } finally {
12357 Binder.restoreCallingIdentity(identity);
12358 }
12359 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012360
12361 /**
12362 * Request to get the current slicing configuration including URSP rules and
12363 * NSSAIs (configured, allowed and rejected).
12364 *
12365 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12366 */
12367 @Override
12368 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012369 TelephonyPermissions
12370 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12371 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012372
joonhunshin4ac60942023-11-15 15:23:39 +000012373 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12374 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12375 "getSlicingConfig");
12376
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012377 final long identity = Binder.clearCallingIdentity();
12378 try {
12379 Phone phone = getDefaultPhone();
12380 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12381 } finally {
12382 Binder.restoreCallingIdentity(identity);
12383 }
12384 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012385
12386 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012387 * Check whether the given premium capability is available for purchase from the carrier.
12388 *
12389 * @param capability The premium capability to check.
12390 * @param subId The subId to check the premium capability for.
12391 *
12392 * @return Whether the given premium capability is available to purchase.
12393 */
12394 @Override
12395 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12396 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12397 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12398 log("Premium capability "
12399 + TelephonyManager.convertPremiumCapabilityToString(capability)
12400 + " is not available for purchase due to missing permissions.");
12401 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12402 + "permission READ_BASIC_PHONE_STATE.");
12403 }
12404
joonhunshin4ac60942023-11-15 15:23:39 +000012405 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12406 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12407
Sarah Chin2ec39f62022-08-31 17:03:26 -070012408 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012409 if (phone == null) {
12410 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12411 return false;
12412 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012413 final long identity = Binder.clearCallingIdentity();
12414 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012415 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012416 .isPremiumCapabilityAvailableForPurchase(capability);
12417 } finally {
12418 Binder.restoreCallingIdentity(identity);
12419 }
12420 }
12421
12422 /**
12423 * Purchase the given premium capability from the carrier.
12424 *
12425 * @param capability The premium capability to purchase.
12426 * @param callback The result of the purchase request.
12427 * @param subId The subId to purchase the premium capability for.
12428 */
12429 @Override
12430 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12431 log("purchasePremiumCapability: capability="
12432 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12433 + getCurrentPackageName());
12434
12435 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12436 mApp, "purchasePremiumCapability")) {
12437 log("purchasePremiumCapability "
12438 + TelephonyManager.convertPremiumCapabilityToString(capability)
12439 + " failed due to missing permissions.");
12440 throw new SecurityException("purchasePremiumCapability requires permission "
12441 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012442 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12443 mApp, "purchasePremiumCapability")) {
12444 log("purchasePremiumCapability "
12445 + TelephonyManager.convertPremiumCapabilityToString(capability)
12446 + " failed due to missing permissions.");
12447 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012448 }
12449
joonhunshin4ac60942023-11-15 15:23:39 +000012450 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12451 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12452
Sarah Chin2ec39f62022-08-31 17:03:26 -070012453 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012454 if (phone == null) {
12455 try {
12456 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12457 callback.accept(result);
12458 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12459 } catch (RemoteException e) {
12460 String logStr = "Purchase premium capability "
12461 + TelephonyManager.convertPremiumCapabilityToString(capability)
12462 + " failed due to RemoteException handling null phone: " + e;
12463 if (DBG) log(logStr);
12464 AnomalyReporter.reportAnomaly(
12465 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12466 }
12467 return;
12468 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012469
12470 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012471 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012472 callingProcess = mApp.getPackageManager().getApplicationInfo(
12473 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012474 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012475 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012476 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012477
12478 boolean isVisible = false;
12479 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12480 if (am != null) {
12481 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12482 if (processes != null) {
12483 for (ActivityManager.RunningAppProcessInfo process : processes) {
12484 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012485 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012486 if (process.processName.equals(callingProcess) && process.importance
12487 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12488 isVisible = true;
12489 break;
12490 }
12491 }
12492 }
12493 }
12494
12495 if (!isVisible) {
12496 try {
12497 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12498 callback.accept(result);
12499 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12500 } catch (RemoteException e) {
12501 String logStr = "Purchase premium capability "
12502 + TelephonyManager.convertPremiumCapabilityToString(capability)
12503 + " failed due to RemoteException handling background application: " + e;
12504 if (DBG) log(logStr);
12505 AnomalyReporter.reportAnomaly(
12506 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12507 }
12508 return;
12509 }
12510
Sarah Chin71b3a852022-09-28 15:54:19 -070012511 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012512 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012513 }
12514
12515 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012516 * Register an IMS connection state callback
12517 */
12518 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012519 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12520 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012521 if (feature == ImsFeature.FEATURE_MMTEL) {
12522 // ImsMmTelManager
12523 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12524 TelephonyPermissions
12525 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12526 mApp, subId, "registerImsStateCallback");
12527 } else if (feature == ImsFeature.FEATURE_RCS) {
12528 // ImsRcsManager or SipDelegateManager
12529 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12530 Binder.getCallingUid(), "registerImsStateCallback",
12531 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12532 Manifest.permission.READ_PRECISE_PHONE_STATE,
12533 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12534 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12535 }
12536
12537 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12538 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12539 "IMS not available on device.");
12540 }
12541
12542 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12543 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12544 }
12545
12546 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12547 if (controller == null) {
12548 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12549 "IMS not available on device.");
12550 }
12551
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012552 if (callingPackage == null) {
12553 callingPackage = getCurrentPackageName();
12554 }
12555
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012556 final long token = Binder.clearCallingIdentity();
12557 try {
12558 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012559 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012560 } catch (ImsException e) {
12561 throw new ServiceSpecificException(e.getCode());
12562 } finally {
12563 Binder.restoreCallingIdentity(token);
12564 }
12565 }
12566
12567 /**
12568 * Unregister an IMS connection state callback
12569 */
12570 @Override
12571 public void unregisterImsStateCallback(IImsStateCallback cb) {
12572 final long token = Binder.clearCallingIdentity();
12573 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12574 if (controller == null) {
12575 return;
12576 }
12577 try {
12578 controller.unregisterImsStateCallback(cb);
12579 } finally {
12580 Binder.restoreCallingIdentity(token);
12581 }
12582 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012583
12584 /**
12585 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12586 *
12587 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012588 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012589 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012590 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012591 * If there is current registered network this value will be same as the registered cell
12592 * identity. If the device goes out of service the previous cell identity is cached and
12593 * will be returned. If the cache age of the Cell identity is more than 24 hours
12594 * it will be cleared and null will be returned.
12595 *
12596 */
12597 @Override
12598 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12599 String callingFeatureId) {
12600 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12601 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12602 LocationAccessPolicy.checkLocationPermission(mApp,
12603 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12604 .setCallingPackage(callingPackage)
12605 .setCallingFeatureId(callingFeatureId)
12606 .setCallingPid(Binder.getCallingPid())
12607 .setCallingUid(Binder.getCallingUid())
12608 .setMethod("getLastKnownCellIdentity")
12609 .setLogAsInfo(true)
12610 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12611 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12612 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12613 .build());
12614
12615 boolean hasFinePermission =
12616 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12617 if (!hasFinePermission
12618 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12619 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012620 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012621 }
12622
12623 final long identity = Binder.clearCallingIdentity();
12624 try {
Ling Mac28f0212023-03-24 16:07:15 -070012625 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012626 if (sst == null) return null;
12627 return sst.getLastKnownCellIdentity();
12628 } finally {
12629 Binder.restoreCallingIdentity(identity);
12630 }
12631 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012632
jimsun3b9ccac2021-10-26 15:01:23 +080012633 /**
12634 * Sets the modem service class Name that Telephony will bind to.
12635 *
12636 * @param serviceName The class name of the modem service.
12637 * @return true if the operation is succeed, otherwise false.
12638 */
12639 public boolean setModemService(String serviceName) {
12640 Log.d(LOG_TAG, "setModemService - " + serviceName);
12641 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012643 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12644 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012645 return mPhoneConfigurationManager.setModemService(serviceName);
12646 }
12647
12648 /**
12649 * Return the class name of the currently bounded modem service.
12650 *
12651 * @return the class name of the modem service.
12652 */
12653 public String getModemService() {
12654 String result;
12655 Log.d(LOG_TAG, "getModemService");
12656 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12657 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012658 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012659 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12660 "getModemService");
12661 result = mPhoneConfigurationManager.getModemService();
12662 Log.d(LOG_TAG, "result = " + result);
12663 return result;
12664 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012665
Hakjun Choi3ee81112023-12-19 15:40:58 +000012666 /**
12667 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12668 * including carrier config, entitlement server, and config update.
12669 *
12670 * @param subId subId The subscription ID of the carrier.
12671 *
12672 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12673 * be returned.
12674 *
12675 * @throws SecurityException if the caller doesn't have the required permission.
12676 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012677 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12678 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012679 final long identity = Binder.clearCallingIdentity();
12680 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012681 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012682 } finally {
12683 Binder.restoreCallingIdentity(identity);
12684 }
12685 }
12686
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012687 @Override
12688 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12689 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12690 mApp.enforceCallingOrSelfPermission(
12691 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12692 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12693
12694 final long identity = Binder.clearCallingIdentity();
12695 try {
12696 Phone phone = getPhone(subId);
12697 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012698 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12699 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012700 phone.setVoiceServiceStateOverride(hasService);
12701 } finally {
12702 Binder.restoreCallingIdentity(identity);
12703 }
12704 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012705
12706 /**
12707 * set removable eSIM as default eUICC.
12708 *
12709 * @hide
12710 */
12711 @Override
12712 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12713 enforceModifyPermission();
12714 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12715
12716 final long identity = Binder.clearCallingIdentity();
12717 try {
12718 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12719 } finally {
12720 Binder.restoreCallingIdentity(identity);
12721 }
12722 }
12723
12724 /**
12725 * Returns whether the removable eSIM is default eUICC or not.
12726 *
12727 * @hide
12728 */
12729 @Override
12730 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12731 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12733
12734 final long identity = Binder.clearCallingIdentity();
12735 try {
12736 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12737 } finally {
12738 Binder.restoreCallingIdentity(identity);
12739 }
12740 }
12741
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012742 /**
12743 * Get the component name of the default app to direct respond-via-message intent for the
12744 * user associated with this subscription, update the cache if there is no respond-via-message
12745 * application currently configured for this user.
12746 * @return component name of the app and class to direct Respond Via Message intent to, or
12747 * {@code null} if the functionality is not supported.
12748 * @hide
12749 */
12750 @Override
12751 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12752 boolean updateIfNeeded) {
12753 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012754
joonhunshin4ac60942023-11-15 15:23:39 +000012755 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12756 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12757 "getDefaultRespondViaMessageApplication");
12758
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012759 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12760
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012761 UserHandle userHandle = null;
12762 final long identity = Binder.clearCallingIdentity();
12763 try {
12764 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12765 } finally {
12766 Binder.restoreCallingIdentity(identity);
12767 }
12768 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12769 updateIfNeeded, userHandle);
12770 }
Jack Yuf5badd92022-12-08 00:50:53 -080012771
12772 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012773 * Set whether the device is able to connect with null ciphering or integrity
12774 * algorithms. This is a global setting and will apply to all active subscriptions
12775 * and all new subscriptions after this.
12776 *
12777 * @param enabled when true, null cipher and integrity algorithms are allowed.
12778 * @hide
12779 */
12780 @Override
12781 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12782 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12783 enforceModifyPermission();
12784 checkForNullCipherAndIntegritySupport();
12785
12786 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12787 // for listening to these preference changes and applying them immediately.
12788 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12789 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12790 editor.apply();
12791
12792 for (Phone phone: PhoneFactory.getPhones()) {
12793 phone.handleNullCipherEnabledChange();
12794 }
12795 }
12796
12797
12798 /**
12799 * Get whether the device is able to connect with null ciphering or integrity
12800 * algorithms. Note that this retrieves the phone-global preference and not
12801 * the state of the radio.
12802 *
12803 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12804 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12805 * version for this feature.
12806 * @hide
12807 */
12808 @Override
12809 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12810 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12811 enforceReadPermission();
12812 checkForNullCipherAndIntegritySupport();
12813 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12814 }
12815
12816 private void checkForNullCipherAndIntegritySupport() {
12817 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12818 throw new UnsupportedOperationException(
12819 "Null cipher and integrity operations require HAL 2.1 or above");
12820 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012821 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12822 throw new UnsupportedOperationException(
12823 "Null cipher and integrity operations unsupported by modem");
12824 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012825 }
12826
Gil Cukierman06403e12023-11-29 16:33:03 +000012827 private void checkForIdentifierDisclosureNotificationSupport() {
12828 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12829 throw new UnsupportedOperationException(
12830 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12831 + "above");
12832 }
12833 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12834 throw new UnsupportedOperationException(
12835 "Cellular identifier disclosure transparency operations unsupported by modem");
12836 }
12837 }
12838
Michael Groover826b71d2023-12-21 22:08:06 -060012839 private void checkForNullCipherNotificationSupport() {
12840 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12841 throw new UnsupportedOperationException(
12842 "Null cipher notification operations require HAL 2.2 or above");
12843 }
12844 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12845 throw new UnsupportedOperationException(
12846 "Null cipher notification operations unsupported by modem");
12847 }
12848 }
12849
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012850 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012851 * Get the SIM state for the slot index.
12852 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12853 *
12854 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12855 */
12856 @Override
12857 @SimState
12858 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012859 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12860 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12861
Jack Yuf5badd92022-12-08 00:50:53 -080012862 IccCardConstants.State simState;
12863 if (slotIndex < 0) {
12864 simState = IccCardConstants.State.UNKNOWN;
12865 } else {
12866 Phone phone = null;
12867 try {
12868 phone = PhoneFactory.getPhone(slotIndex);
12869 } catch (IllegalStateException e) {
12870 // ignore
12871 }
12872 if (phone == null) {
12873 simState = IccCardConstants.State.UNKNOWN;
12874 } else {
12875 IccCard icc = phone.getIccCard();
12876 if (icc == null) {
12877 simState = IccCardConstants.State.UNKNOWN;
12878 } else {
12879 simState = icc.getState();
12880 }
12881 }
12882 }
12883 return simState.ordinal();
12884 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012885
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012886 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12887 boolean enableLogcat,
12888 long logcatStartTimestampMillis, boolean enableTelecomDump,
12889 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012890 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012891 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12892 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12893 ecdDataBuilder
12894 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12895 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012896 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012897 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012898 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012899 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12900 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012901 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12902 Executors.newCachedThreadPool(), db,
12903 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012904 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012905 }
12906
12907 /**
12908 * Request telephony to persist state for debugging emergency call failures.
12909 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012910 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012911 * @param enableLogcat whether to collect logcat output
12912 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12913 * @param enableTelecomDump whether to collect telecom dumpsys
12914 * @param enableTelephonyDump whether to collect telephony dumpsys
12915 */
12916 @Override
12917 @RequiresPermission(android.Manifest.permission.DUMP)
12918 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12919 long logcatStartTimestampMillis, boolean enableTelecomDump,
12920 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012921 // Verify that the caller has READ_DROPBOX_DATA permission.
12922 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12923 && Flags.enableReadDropboxPermission()) {
12924 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12925 "persistEmergencyCallDiagnosticData");
12926 } else {
12927 // Otherwise, enforce legacy permission.
12928 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12929 "persistEmergencyCallDiagnosticData");
12930 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012931 final long identity = Binder.clearCallingIdentity();
12932 try {
12933 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12934 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12935
12936 } finally {
12937 Binder.restoreCallingIdentity(identity);
12938 }
12939 }
12940
Hui Wang9b5793a2022-12-05 14:38:06 -060012941 /**
12942 * Get current cell broadcast ranges.
12943 */
12944 @Override
12945 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12946 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12947 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12948 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012949
12950 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12951 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12952
Hui Wang9b5793a2022-12-05 14:38:06 -060012953 final long identity = Binder.clearCallingIdentity();
12954 try {
12955 return getPhone(subId).getCellBroadcastIdRanges();
12956 } finally {
12957 Binder.restoreCallingIdentity(identity);
12958 }
12959 }
12960
12961 /**
12962 * Set reception of cell broadcast messages with the list of the given ranges
12963 *
12964 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12965 */
12966 @Override
12967 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12968 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12969 @Nullable IIntegerConsumer callback) {
12970 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12971 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012972
12973 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12974 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12975
Hui Wang9b5793a2022-12-05 14:38:06 -060012976 final long identity = Binder.clearCallingIdentity();
12977 try {
12978 Phone phone = getPhoneFromSubId(subId);
12979 if (DBG) {
12980 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12981 }
12982 phone.setCellBroadcastIdRanges(ranges, result -> {
12983 if (callback != null) {
12984 try {
12985 callback.accept(result);
12986 } catch (RemoteException e) {
12987 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12988 }
12989 }
12990 });
12991 } finally {
12992 Binder.restoreCallingIdentity(identity);
12993 }
12994 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012995
12996 /**
12997 * Returns whether the device supports the domain selection service.
12998 *
12999 * @return {@code true} if the device supports the domain selection service.
13000 */
13001 @Override
13002 public boolean isDomainSelectionSupported() {
13003 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13004 "isDomainSelectionSupported");
13005
13006 final long identity = Binder.clearCallingIdentity();
13007 try {
13008 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13009 } finally {
13010 Binder.restoreCallingIdentity(identity);
13011 }
13012 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013013
13014 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013015 * Returns whether the AOSP domain selection service is supported.
13016 *
13017 * @return {@code true} if the AOSP domain selection service is supported,
13018 * {@code false} otherwise.
13019 */
13020 @Override
13021 public boolean isAospDomainSelectionService() {
13022 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13023 "isAospDomainSelectionService");
13024
13025 final long identity = Binder.clearCallingIdentity();
13026 try {
13027 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13028 String dssComponentName = mApp.getResources().getString(
13029 R.string.config_domain_selection_service_component_name);
13030 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13031 TelephonyDomainSelectionService.class.getName());
13032 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13033 + ", aosp=" + componentName.flattenToString());
13034 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13035 }
13036 } finally {
13037 Binder.restoreCallingIdentity(identity);
13038 }
13039 return false;
13040 }
13041
13042 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013043 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13044 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13045 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013046 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013047 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013048 * @param enableSatellite {@code true} to enable the satellite modem and
13049 * {@code false} to disable.
13050 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013051 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013052 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013053 *
13054 * @throws SecurityException if the caller doesn't have the required permission.
13055 */
13056 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013057 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013058 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013059 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013060 if (enableSatellite) {
13061 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13062 @Override
13063 protected void onReceiveResult(int resultCode, Bundle resultData) {
13064 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13065 + ", resultData=" + resultData);
13066 boolean isAllowed = false;
13067 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13068 callback::accept);
13069 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13070 if (resultData != null
13071 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13072 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13073 } else {
13074 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13075 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013076 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013077 result.accept(resultCode);
13078 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013079 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013080 if (isAllowed) {
13081 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013082 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013083 } else {
13084 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13085 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013086 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013087 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013088 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013089 subId, resultReceiver);
13090 } else {
13091 // No need to check if satellite is allowed at current location when disabling satellite
13092 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013093 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013094 }
Sarah Chin503828c2023-02-01 23:54:20 -080013095 }
13096
13097 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013098 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013099 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013100 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013101 * @param result The result receiver that returns whether the satellite modem is enabled
13102 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013103 *
13104 * @throws SecurityException if the caller doesn't have the required permission.
13105 */
13106 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013107 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13108 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013109 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013110 }
13111
13112 /**
Sarah Chin43457982023-02-15 17:50:38 -080013113 * Request to get whether the satellite service demo mode is enabled.
13114 *
13115 * @param subId The subId of the subscription to check whether the satellite demo mode
13116 * is enabled for.
13117 * @param result The result receiver that returns whether the satellite demo mode is enabled
13118 * if the request is successful or an error code if the request failed.
13119 *
13120 * @throws SecurityException if the caller doesn't have the required permission.
13121 */
13122 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013123 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13124 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13125 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013126 }
13127
13128 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013129 * Request to get whether the satellite service is enabled with emergency mode.
13130 *
13131 * @param subId The subId of the subscription to check whether the satellite demo mode
13132 * is enabled for.
13133 * @param result The result receiver that returns whether the satellite emergency mode is
13134 * enabled if the request is successful or an error code if the request failed.
13135 *
13136 * @throws SecurityException if the caller doesn't have the required permission.
13137 */
13138 @Override
13139 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13140 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13141 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13142 }
13143
13144 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013145 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013146 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013147 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013148 * @param result The result receiver that returns whether the satellite service is supported on
13149 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013150 */
13151 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013152 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013153 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013154 }
13155
13156 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013157 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013158 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013159 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013160 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13161 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013162 *
13163 * @throws SecurityException if the caller doesn't have required permission.
13164 */
13165 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013166 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13167 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013168 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013169 }
13170
13171 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013172 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013173 * This can be called by the pointing UI when the user starts pointing to the satellite.
13174 * Modem should continue to report the pointing input as the device or satellite moves.
13175 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013176 * @param subId The subId of the subscription to start satellite transmission updates for.
13177 * @param resultCallback The callback to get the result of the request.
13178 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013179 *
13180 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013181 */
13182 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013183 public void startSatelliteTransmissionUpdates(int subId,
13184 @NonNull IIntegerConsumer resultCallback,
13185 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13186 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13187 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013188 }
13189
13190 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013191 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013192 * This can be called by the pointing UI when the user stops pointing to the satellite.
13193 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013194 * @param subId The subId of the subscription to stop satellite transmission updates for.
13195 * @param resultCallback The callback to get the result of the request.
13196 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13197 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013198 *
13199 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013200 */
13201 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013202 public void stopSatelliteTransmissionUpdates(int subId,
13203 @NonNull IIntegerConsumer resultCallback,
13204 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13205 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13206 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013207 }
13208
13209 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013210 * Register the subscription with a satellite provider.
13211 * This is needed to register the subscription if the provider allows dynamic registration.
13212 *
13213 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013214 * @param token The token to be used as a unique identifier for provisioning with satellite
13215 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013216 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013217 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013218 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013219 * @return The signal transport used by the caller to cancel the provision request,
13220 * or {@code null} if the request failed.
13221 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013222 * @throws SecurityException if the caller doesn't have the required permission.
13223 */
13224 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013225 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013226 @NonNull String token, @NonNull byte[] provisionData,
13227 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013228 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013229 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13230 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013231 }
13232
13233 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013234 * Unregister the device/subscription with the satellite provider.
13235 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013236 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013237 * should report as deprovisioned.
13238 *
13239 * @param subId The subId of the subscription to be deprovisioned.
13240 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013241 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013242 *
13243 * @throws SecurityException if the caller doesn't have the required permission.
13244 */
13245 @Override
13246 public void deprovisionSatelliteService(int subId,
13247 @NonNull String token, @NonNull IIntegerConsumer callback) {
13248 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013249 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013250 }
13251
13252 /**
Sarah Chin43457982023-02-15 17:50:38 -080013253 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013254 *
Sarah Chin43457982023-02-15 17:50:38 -080013255 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013256 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013257 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013258 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013259 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013260 * @throws SecurityException if the caller doesn't have the required permission.
13261 */
13262 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013263 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13264 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013265 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013266 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013267 }
13268
13269 /**
Sarah Chin43457982023-02-15 17:50:38 -080013270 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013271 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013272 *
Sarah Chin43457982023-02-15 17:50:38 -080013273 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013274 * @param callback The callback that was passed to
13275 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013276 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013277 * @throws SecurityException if the caller doesn't have the required permission.
13278 */
13279 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013280 public void unregisterForSatelliteProvisionStateChanged(
13281 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013282 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013283 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013284 }
13285
13286 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013287 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013288 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013289 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013290 * @param result The result receiver that returns whether the device is provisioned with a
13291 * satellite provider if the request is successful or an error code if the
13292 * request failed.
13293 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013294 * @throws SecurityException if the caller doesn't have the required permission.
13295 */
13296 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013297 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13298 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013299 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013300 }
13301
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013302 /**
Sarah Chin43457982023-02-15 17:50:38 -080013303 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013304 *
Sarah Chin43457982023-02-15 17:50:38 -080013305 * @param subId The subId of the subscription to register for satellite modem state changed.
13306 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013307 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013308 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013309 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013310 * @throws SecurityException if the caller doesn't have the required permission.
13311 */
13312 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013313 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013314 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013315 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013316 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013317 }
13318
13319 /**
Sarah Chin43457982023-02-15 17:50:38 -080013320 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013321 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013322 *
Sarah Chin43457982023-02-15 17:50:38 -080013323 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013324 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013325 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013326 *
13327 * @throws SecurityException if the caller doesn't have the required permission.
13328 */
13329 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013330 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013331 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013332 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13333 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013334 }
13335
13336 /**
13337 * Register to receive incoming datagrams over satellite.
13338 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013339 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013340 * @param callback The callback to handle incoming datagrams over satellite.
13341 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013342 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013343 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013344 * @throws SecurityException if the caller doesn't have the required permission.
13345 */
13346 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013347 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013348 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013349 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13350 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013351 }
13352
13353 /**
13354 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013355 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013356 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013357 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13358 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013359 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013360 *
13361 * @throws SecurityException if the caller doesn't have the required permission.
13362 */
13363 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013364 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013365 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013366 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13367 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013368 }
13369
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013370 /**
13371 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013372 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013373 * This method requests modem to check if there are any pending datagrams to be received over
13374 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013375 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013376 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013377 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013378 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013379 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013380 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013381 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013382 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13383 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13384 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013385 }
13386
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013387 /**
13388 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013389 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013390 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13391 * input to this method. Datagram received here will be passed down to modem without any
13392 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013393 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013394 * @param subId The subId of the subscription to send satellite datagrams for.
13395 * @param datagramType datagram type indicating whether the datagram is of type
13396 * SOS_SMS or LOCATION_SHARING.
13397 * @param datagram encoded gateway datagram which is encrypted by the caller.
13398 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013399 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13400 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013401 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013402 *
13403 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013404 */
13405 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013406 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013407 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13408 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013409 enforceSatelliteCommunicationPermission("sendDatagram");
13410 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13411 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013412 }
13413
Sarah Chindf715ec2023-02-13 13:46:24 -080013414 /**
13415 * Request to get whether satellite communication is allowed for the current location.
13416 *
13417 * @param subId The subId of the subscription to check whether satellite communication is
13418 * allowed for the current location for.
13419 * @param result The result receiver that returns whether satellite communication is allowed
13420 * for the current location if the request is successful or an error code
13421 * if the request failed.
13422 *
13423 * @throws SecurityException if the caller doesn't have the required permission.
13424 */
13425 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013426 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013427 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013428 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13429 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13430 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013431 }
13432
13433 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013434 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013435 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013436 * @param subId The subId to get the time after which the satellite will be visible for.
13437 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013438 * be visible if the request is successful or an error code if the request failed.
13439 *
13440 * @throws SecurityException if the caller doesn't have the required permission.
13441 */
13442 @Override
13443 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13444 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013445 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013446 }
13447
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013448 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013449 * Inform that Device is aligned to satellite for demo mode.
13450 *
13451 * @param subId The subId to get the time after which the satellite will be visible for.
13452 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13453 * {@code false} Device fails to align with the satellite for demo mode.
13454 *
13455 * @throws SecurityException if the caller doesn't have required permission.
13456 */
13457 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13458
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013459 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013460 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013461 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013462 }
13463
13464 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013465 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13466 * by modem.
13467 *
13468 * @param subId The subId of the subscription to request for.
13469 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013470 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013471 * operation.
13472 *
13473 * @throws SecurityException if the caller doesn't have required permission.
13474 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013475 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013476 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13477 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013478 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013479 final long identity = Binder.clearCallingIdentity();
13480 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013481 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013482 } finally {
13483 Binder.restoreCallingIdentity(identity);
13484 }
13485 }
13486
13487 /**
13488 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13489 * by modem.
13490 *
13491 * @param subId The subId of the subscription to request for.
13492 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013493 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013494 * operation.
13495 *
13496 * @throws SecurityException if the caller doesn't have required permission.
13497 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013498 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013499 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13500 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013501 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013502 final long identity = Binder.clearCallingIdentity();
13503 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013504 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013505 } finally {
13506 Binder.restoreCallingIdentity(identity);
13507 }
13508 }
13509
13510 /**
13511 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013512 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013513 *
13514 * @param subId The subId of the subscription to request for.
13515 *
13516 * @return Integer array of reasons for disallowing satellite communication.
13517 *
13518 * @throws SecurityException if the caller doesn't have the required permission.
13519 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013520 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013521 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013522 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013523 final long identity = Binder.clearCallingIdentity();
13524 try {
13525 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013526 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013527 return reasonSet.stream().mapToInt(i->i).toArray();
13528 } finally {
13529 Binder.restoreCallingIdentity(identity);
13530 }
13531 }
13532
13533 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013534 * Request to get the signal strength of the satellite connection.
13535 *
13536 * @param subId The subId of the subscription to request for.
13537 * @param result Result receiver to get the error code of the request and the current signal
13538 * strength of the satellite connection.
13539 *
13540 * @throws SecurityException if the caller doesn't have required permission.
13541 */
13542 @Override
13543 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13544 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13545 final long identity = Binder.clearCallingIdentity();
13546 try {
13547 mSatelliteController.requestNtnSignalStrength(subId, result);
13548 } finally {
13549 Binder.restoreCallingIdentity(identity);
13550 }
13551 }
13552
13553 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013554 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13555 * is not successful, a {@link ServiceSpecificException} that contains
13556 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013557 *
13558 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013559 * @param callback The callback to handle the NTN signal strength changed event. If the
13560 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13561 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13562 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13563 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013564 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013565 * @throws SecurityException If the caller doesn't have the required permission.
13566 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013567 */
13568 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013569 public void registerForNtnSignalStrengthChanged(int subId,
13570 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013571 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13572 final long identity = Binder.clearCallingIdentity();
13573 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013574 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013575 } finally {
13576 Binder.restoreCallingIdentity(identity);
13577 }
13578 }
13579
13580 /**
13581 * Unregisters for NTN signal strength changed from satellite modem.
13582 * If callback was not registered before, the request will be ignored.
13583 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013584 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13585 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013586 * @param callback The callback that was passed to
13587 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13588 *
13589 * @throws SecurityException if the caller doesn't have the required permission.
13590 */
13591 @Override
13592 public void unregisterForNtnSignalStrengthChanged(
13593 int subId, @NonNull INtnSignalStrengthCallback callback) {
13594 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13595 final long identity = Binder.clearCallingIdentity();
13596 try {
13597 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13598 } finally {
13599 Binder.restoreCallingIdentity(identity);
13600 }
13601 }
13602
13603 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013604 * Registers for satellite capabilities change event from the satellite service.
13605 *
13606 * @param subId The subId of the subscription to request for.
13607 * @param callback The callback to handle the satellite capabilities changed event.
13608 *
13609 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13610 *
13611 * @throws SecurityException if the caller doesn't have required permission.
13612 */
13613 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013614 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013615 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013616 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013617 final long identity = Binder.clearCallingIdentity();
13618 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013619 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013620 } finally {
13621 Binder.restoreCallingIdentity(identity);
13622 }
13623 }
13624
13625 /**
13626 * Unregisters for satellite capabilities change event from the satellite service.
13627 * If callback was not registered before, the request will be ignored.
13628 *
13629 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13630 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013631 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013632 *
13633 * @throws SecurityException if the caller doesn't have required permission.
13634 */
13635 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013636 public void unregisterForCapabilitiesChanged(int subId,
13637 @NonNull ISatelliteCapabilitiesCallback callback) {
13638 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013639 final long identity = Binder.clearCallingIdentity();
13640 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013641 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013642 } finally {
13643 Binder.restoreCallingIdentity(identity);
13644 }
13645 }
13646
13647 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013648 * Registers for the satellite supported state changed.
13649 *
13650 * @param subId The subId of the subscription to register for supported state changed.
13651 * @param callback The callback to handle the satellite supported state changed event.
13652 *
13653 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13654 *
13655 * @throws SecurityException if the caller doesn't have the required permission.
13656 */
13657 @Override
13658 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13659 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13660 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13661 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13662 }
13663
13664 /**
13665 * Unregisters for the satellite supported state changed.
13666 * If callback was not registered before, the request will be ignored.
13667 *
13668 * @param subId The subId of the subscription to unregister for supported state changed.
13669 * @param callback The callback that was passed to
13670 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13671 *
13672 * @throws SecurityException if the caller doesn't have the required permission.
13673 */
13674 @Override
13675 public void unregisterForSatelliteSupportedStateChanged(
13676 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13677 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13678 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13679 }
13680
13681 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013682 * This API can be used by only CTS to update satellite vendor service package name.
13683 *
13684 * @param servicePackageName The package name of the satellite vendor service.
13685 * @return {@code true} if the satellite vendor service is set successfully,
13686 * {@code false} otherwise.
13687 */
13688 public boolean setSatelliteServicePackageName(String servicePackageName) {
13689 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13690 TelephonyPermissions.enforceShellOnly(
13691 Binder.getCallingUid(), "setSatelliteServicePackageName");
13692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13693 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13694 "setSatelliteServicePackageName");
13695 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13696 }
13697
13698 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013699 * This API can be used by only CTS to update satellite gateway service package name.
13700 *
13701 * @param servicePackageName The package name of the satellite gateway service.
13702 * @return {@code true} if the satellite gateway service is set successfully,
13703 * {@code false} otherwise.
13704 */
13705 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13706 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13707 TelephonyPermissions.enforceShellOnly(
13708 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13710 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13711 "setSatelliteGatewayServicePackageName");
13712 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13713 }
13714
13715 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013716 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13717 *
13718 * @param packageName The package name of the satellite pointing UI app.
13719 * @param className The class name of the satellite pointing UI app.
13720 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13721 * {@code false} otherwise.
13722 */
13723 public boolean setSatellitePointingUiClassName(
13724 @Nullable String packageName, @Nullable String className) {
13725 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13726 + ", className=" + className);
13727 TelephonyPermissions.enforceShellOnly(
13728 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13730 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13731 "setSatelliteGatewayServicePackageName");
13732 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13733 }
13734
13735 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013736 * This API can be used by only CTS to update the timeout duration in milliseconds that
13737 * satellite should stay at listening mode to wait for the next incoming page before disabling
13738 * listening mode.
13739 *
13740 * @param timeoutMillis The timeout duration in millisecond.
13741 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13742 */
13743 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13744 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13745 TelephonyPermissions.enforceShellOnly(
13746 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13748 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13749 "setSatelliteListeningTimeoutDuration");
13750 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13751 }
13752
13753 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013754 * This API can be used by only CTS to override the timeout durations used by the
13755 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013756 *
13757 * @param timeoutMillis The timeout duration in millisecond.
13758 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13759 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013760 public boolean setDatagramControllerTimeoutDuration(
13761 boolean reset, int timeoutType, long timeoutMillis) {
13762 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13763 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013764 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013765 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13767 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013768 "setDatagramControllerTimeoutDuration");
13769 return mSatelliteController.setDatagramControllerTimeoutDuration(
13770 reset, timeoutType, timeoutMillis);
13771 }
13772
13773 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013774 * This API can be used by only CTS to override the boolean configs used by the
13775 * DatagramController module.
13776 *
13777 * @param enable Whether to enable or disable boolean config.
13778 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13779 */
13780 public boolean setDatagramControllerBooleanConfig(
13781 boolean reset, int booleanType, boolean enable) {
13782 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13783 + ", reset=" + reset + ", enable=" + enable);
13784 TelephonyPermissions.enforceShellOnly(
13785 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13787 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13788 "ssetDatagramControllerBooleanConfig");
13789 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13790 }
13791
13792
13793 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013794 * This API can be used by only CTS to override the timeout durations used by the
13795 * SatelliteController module.
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 setSatelliteControllerTimeoutDuration(
13801 boolean reset, int timeoutType, long timeoutMillis) {
13802 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13803 + reset + ", timeoutMillis=" + timeoutMillis);
13804 TelephonyPermissions.enforceShellOnly(
13805 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13807 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13808 "setSatelliteControllerTimeoutDuration");
13809 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13810 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013811 }
13812
13813 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013814 * This API can be used in only testing to override connectivity status in monitoring emergency
13815 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13816 *
13817 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13818 * of the following values to enable the override:
13819 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13820 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13821 * To disable the override, use -1 for handoverType.
13822 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13823 * delaySeconds after the emergency call starts.
13824 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13825 */
13826 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13827 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13828 TelephonyPermissions.enforceShellOnly(
13829 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13831 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13832 "setEmergencyCallToSatelliteHandoverType");
13833 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13834 handoverType, delaySeconds);
13835 }
13836
13837 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013838 * This API can be used in only testing to override oem-enabled satellite provision status.
13839 *
13840 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13841 * otherwise.
13842 * @param isProvisioned The overriding provision status.
13843 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13844 */
13845 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13846 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13847 + ", isProvisioned=" + isProvisioned);
13848 TelephonyPermissions.enforceShellOnly(
13849 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13851 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13852 "setOemEnabledSatelliteProvisionStatus");
13853 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13854 }
13855
13856 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013857 * This API should be used by only CTS tests to forcefully set telephony country codes.
13858 *
13859 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13860 */
13861 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13862 Map cachedNetworkCountryCodes, String locationCountryCode,
13863 long locationCountryCodeTimestampNanos) {
13864 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13865 + String.join(", ", currentNetworkCountryCodes)
13866 + ", locationCountryCode=" + locationCountryCode
13867 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13868 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13869 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13870 TelephonyPermissions.enforceShellOnly(
13871 Binder.getCallingUid(), "setCachedLocationCountryCode");
13872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13873 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13874 "setCachedLocationCountryCode");
13875 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13876 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13877 locationCountryCodeTimestampNanos);
13878 }
13879
13880 /**
13881 * This API should be used by only CTS tests to override the overlay configs of satellite
13882 * access controller.
13883 *
13884 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13885 * otherwise.
13886 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13887 */
13888 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13889 String s2CellFile, long locationFreshDurationNanos,
13890 List<String> satelliteCountryCodes) {
13891 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13892 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13893 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13894 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13895 ? String.join(", ", satelliteCountryCodes) : null));
13896 TelephonyPermissions.enforceShellOnly(
13897 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13899 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13900 "setSatelliteAccessControlOverlayConfigs");
13901 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13902 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13903 }
13904
13905 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013906 * This API can be used by only CTS to override the cached value for the device overlay config
13907 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13908 * outgoing satellite datagrams should be sent to modem in demo mode.
13909 *
13910 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13911 * satellite modem or not.
13912 *
13913 * @return {@code true} if the operation is successful, {@code false} otherwise.
13914 */
13915 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13916 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13917 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13918 + "disabled");
13919 return false;
13920 }
13921 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13922 TelephonyPermissions.enforceShellOnly(
13923 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13925 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13926 "setShouldSendDatagramToModemInDemoMode");
13927 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13928 shouldSendToModemInDemoMode);
13929 }
13930
13931 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013932 * Sets the service defined in ComponentName to be bound.
13933 *
13934 * This should only be used for testing.
13935 * @return {@code true} if the DomainSelectionService to bind to was set,
13936 * {@code false} otherwise.
13937 */
13938 @Override
13939 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13940 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13941
13942 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13943 "setDomainSelectionServiceOverride");
13944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13945 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13946
13947 final long identity = Binder.clearCallingIdentity();
13948 try {
13949 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13950 return DomainSelectionResolver.getInstance()
13951 .setDomainSelectionServiceOverride(componentName);
13952 }
13953 } finally {
13954 Binder.restoreCallingIdentity(identity);
13955 }
13956 return false;
13957 }
13958
13959 /**
13960 * Clears the DomainSelectionService override.
13961 *
13962 * This should only be used for testing.
13963 * @return {@code true} if the DomainSelectionService override was cleared,
13964 * {@code false} otherwise.
13965 */
13966 @Override
13967 public boolean clearDomainSelectionServiceOverride() {
13968 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13969
13970 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13971 "clearDomainSelectionServiceOverride");
13972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13973 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13974
13975 final long identity = Binder.clearCallingIdentity();
13976 try {
13977 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13978 return DomainSelectionResolver.getInstance()
13979 .clearDomainSelectionServiceOverride();
13980 }
13981 } finally {
13982 Binder.restoreCallingIdentity(identity);
13983 }
13984 return false;
13985 }
13986
13987 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013988 * Enable or disable notifications sent for cellular identifier disclosure events.
13989 *
13990 * Disclosure events are defined as instances where a device has sent a cellular identifier
13991 * on the Non-access stratum (NAS) before a security context is established. As a result the
13992 * identifier is sent in the clear, which has privacy implications for the user.
13993 *
13994 * @param enable if notifications about disclosure events should be enabled
13995 * @throws SecurityException if the caller does not have the required privileges
13996 * @throws UnsupportedOperationException if the modem does not support this feature.
13997 */
13998 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013999 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014000 enforceModifyPermission();
14001 checkForIdentifierDisclosureNotificationSupport();
14002
14003 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14004 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14005 editor.apply();
14006
14007 // Each phone instance is responsible for updating its respective modem immediately
14008 // after we've made a preference change.
14009 for (Phone phone : PhoneFactory.getPhones()) {
14010 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14011 }
14012 }
14013
14014 /**
14015 * Get whether or not cellular identifier disclosure notifications are enabled.
14016 *
14017 * @throws SecurityException if the caller does not have the required privileges
14018 * @throws UnsupportedOperationException if the modem does not support this feature.
14019 */
14020 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014021 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014022 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14023 checkForIdentifierDisclosureNotificationSupport();
14024 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14025 }
14026
14027 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014028 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14029 * are in use by the cellular modem.
14030 *
14031 * @throws IllegalStateException if the Telephony process is not currently available
14032 * @throws SecurityException if the caller does not have the required privileges
14033 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14034 * and integrity algorithms in use
14035 * @hide
14036 */
14037 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014038 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014039 enforceModifyPermission();
14040 checkForNullCipherNotificationSupport();
14041
14042 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14043 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14044 editor.apply();
14045
14046 // Each phone instance is responsible for updating its respective modem immediately
14047 // after a preference change.
14048 for (Phone phone : PhoneFactory.getPhones()) {
14049 phone.handleNullCipherNotificationPreferenceChanged();
14050 }
14051 }
14052
14053 /**
14054 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14055 * cellular modem.
14056 *
14057 * @throws IllegalStateException if the Telephony process is not currently available
14058 * @throws SecurityException if the caller does not have the required privileges
14059 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14060 * and integrity algorithms in use
14061 * @hide
14062 */
14063 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14064 public boolean isNullCipherNotificationsEnabled() {
14065 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14066 checkForNullCipherNotificationSupport();
14067 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14068 }
14069
14070 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014071 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14072 *
14073 * <p>This method behaves in one of the following ways:
14074 * <ul>
14075 * <li>return true : if the calling package has the appop permission {@link
14076 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14077 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14078 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14079 * Owner device identifier access check, or the calling package has carrier privileges</>
14080 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14081 * </ul>
14082 */
14083 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14084 String callingPackage, @Nullable String callingFeatureId, String message) {
14085 for (Phone phone : PhoneFactory.getPhones()) {
14086 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14087 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14088 return true;
14089 }
14090 }
14091 return false;
14092 }
arunvoddud7401012022-12-15 16:08:12 +000014093
14094 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014095 * @return The subscription manager service instance.
14096 */
14097 public SubscriptionManagerService getSubscriptionManagerService() {
14098 return SubscriptionManagerService.getInstance();
14099 }
14100
14101 /**
arunvoddud7401012022-12-15 16:08:12 +000014102 * Class binds the consumer[callback] and carrierId.
14103 */
14104 private static class CallerCallbackInfo {
14105 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014106 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014107
Steve Statia28b7cb32024-03-11 23:58:50 +000014108 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014109 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014110 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014111 }
14112
14113 public Consumer<Integer> getConsumer() {
14114 return mConsumer;
14115 }
14116
Steve Statia28b7cb32024-03-11 23:58:50 +000014117 public Set<Integer> getCarrierIds() {
14118 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014119 }
14120 }
joonhunshin4ac60942023-11-15 15:23:39 +000014121
14122 /*
14123 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14124 * But the context that is passed in is unused if the phone app is already alive.
14125 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14126 */
14127 @VisibleForTesting
14128 public void setPackageManager(PackageManager packageManager) {
14129 mPackageManager = packageManager;
14130 }
14131
14132 /*
Nate Myren453c3472024-03-13 11:28:11 -070014133 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14134 * But the context that is passed in is unused if the phone app is already alive.
14135 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14136 */
14137 @VisibleForTesting
14138 public void setAppOpsManager(AppOpsManager appOps) {
14139 mAppOps = appOps;
14140 }
14141
14142 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014143 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14144 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14145 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14146 */
14147 @VisibleForTesting
14148 public void setFeatureFlags(FeatureFlags featureFlags) {
14149 mFeatureFlags = featureFlags;
14150 }
14151
14152 /**
14153 * Make sure the device has required telephony feature
14154 *
14155 * @throws UnsupportedOperationException if the device does not have required telephony feature
14156 */
14157 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14158 @NonNull String telephonyFeature, @NonNull String methodName) {
14159 if (callingPackage == null || mPackageManager == null) {
14160 return;
14161 }
14162
14163 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14164 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014165 Binder.getCallingUserHandle())
14166 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14167 // Skip to check associated telephony feature,
14168 // if compatibility change is not enabled for the current process or
14169 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014170 return;
14171 }
14172
14173 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14174 throw new UnsupportedOperationException(
14175 methodName + " is unsupported without " + telephonyFeature);
14176 }
14177 }
youngtaecha5d483d52024-04-29 17:05:45 +000014178
14179 /**
14180 * Registers for the satellite communication allowed state changed.
14181 *
14182 * @param subId The subId of the subscription to register for the satellite communication
14183 * allowed state changed.
14184 * @param callback The callback to handle the satellite communication allowed
14185 * state changed event.
14186 *
14187 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14188 *
14189 * @throws SecurityException if the caller doesn't have the required permission.
14190 */
14191 @Override
14192 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14193 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14194 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14195 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14196 subId, callback);
14197 }
14198
14199 /**
14200 * Unregisters for the satellite communication allowed state changed.
14201 * If callback was not registered before, the request will be ignored.
14202 *
14203 * @param subId The subId of the subscription to unregister for the satellite communication
14204 * allowed state changed.
14205 * @param callback The callback that was passed to
14206 * {@link #registerForCommunicationAllowedStateChanged(int,
14207 * ISatelliteCommunicationAllowedStateCallback)}. *
14208 * @throws SecurityException if the caller doesn't have the required permission.
14209 */
14210 @Override
14211 public void unregisterForCommunicationAllowedStateChanged(
14212 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14213 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14214 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14215 }
Jack Yufa8ed012023-02-11 15:42:28 -080014216}