blob: e22f51a5aa7d7137da32ab69e657275a9670b96c [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);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270
joonhunshin4ac60942023-11-15 15:23:39 +00004271 enforceTelephonyFeatureWithException(callingPackage,
4272 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004277 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278 } finally {
4279 Binder.restoreCallingIdentity(identity);
4280 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004281 }
4282
4283 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004284 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4285 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286
joonhunshin4ac60942023-11-15 15:23:39 +00004287 enforceTelephonyFeatureWithException(callingPackage,
4288 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004293 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004294 } finally {
4295 Binder.restoreCallingIdentity(identity);
4296 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004297 }
4298
4299 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004300 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4301 String callingPackage, int subId) {
4302 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004303
4304 final long identity = Binder.clearCallingIdentity();
4305 try {
4306 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004307 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004311 }
4312
4313 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004314 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004315 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316
4317 final long identity = Binder.clearCallingIdentity();
4318 try {
4319 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004320 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004324 }
4325
4326 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004327 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4328 String callingAttributionTag, int subId, String number, int port, String text,
4329 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004330 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004331 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004332 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004333
4334 enforceTelephonyFeatureWithException(callingPackage,
4335 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4336
Amit Mahajandccb3f12019-05-13 13:48:32 -07004337 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004338 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4339 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004340 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004341
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004342 /**
fionaxu0152e512016-11-14 13:36:14 -08004343 * Sets the voice activation state of a given subId.
4344 */
4345 @Override
4346 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4348 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349
joonhunshin4ac60942023-11-15 15:23:39 +00004350 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4351 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 final Phone phone = getPhone(subId);
4356 if (phone != null) {
4357 phone.setVoiceActivationState(activationState);
4358 } else {
4359 loge("setVoiceActivationState fails with invalid subId: " + subId);
4360 }
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004363 }
4364 }
4365
4366 /**
4367 * Sets the data activation state of a given subId.
4368 */
4369 @Override
4370 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4372 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373
joonhunshin4ac60942023-11-15 15:23:39 +00004374 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4375 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377 final long identity = Binder.clearCallingIdentity();
4378 try {
4379 final Phone phone = getPhone(subId);
4380 if (phone != null) {
4381 phone.setDataActivationState(activationState);
4382 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004383 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384 }
4385 } finally {
4386 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004387 }
4388 }
4389
4390 /**
4391 * Returns the voice activation state of a given subId.
4392 */
4393 @Override
4394 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004395 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396
joonhunshin4ac60942023-11-15 15:23:39 +00004397 enforceTelephonyFeatureWithException(callingPackage,
4398 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4399
fionaxu0152e512016-11-14 13:36:14 -08004400 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 if (phone != null) {
4404 return phone.getVoiceActivationState();
4405 } else {
4406 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4407 }
4408 } finally {
4409 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004410 }
4411 }
4412
4413 /**
4414 * Returns the data activation state of a given subId.
4415 */
4416 @Override
4417 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004418 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419
joonhunshin4ac60942023-11-15 15:23:39 +00004420 enforceTelephonyFeatureWithException(callingPackage,
4421 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4422
fionaxu0152e512016-11-14 13:36:14 -08004423 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004424 final long identity = Binder.clearCallingIdentity();
4425 try {
4426 if (phone != null) {
4427 return phone.getDataActivationState();
4428 } else {
4429 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4430 }
4431 } finally {
4432 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004433 }
4434 }
4435
4436 /**
Wink Saville36469e72014-06-11 15:17:00 -07004437 * Returns the unread count of voicemails for a subId
4438 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004440 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4441 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004443 mApp, subId, callingPackage, callingFeatureId,
4444 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004445 return 0;
4446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 final long identity = Binder.clearCallingIdentity();
4448 try {
4449 final Phone phone = getPhone(subId);
4450 if (phone != null) {
4451 return phone.getVoiceMessageCount();
4452 } else {
4453 return 0;
4454 }
4455 } finally {
4456 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004458 }
4459
4460 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004461 * returns true, if the device is in a state where both voice and data
4462 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004463 */
4464 @Override
4465 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004466 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4467 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469 final long identity = Binder.clearCallingIdentity();
4470 try {
Ling Mac28f0212023-03-24 16:07:15 -07004471 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 } finally {
4473 Binder.restoreCallingIdentity(identity);
4474 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004475 }
4476
4477 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004478 * Send the dialer code if called from the current default dialer or the caller has
4479 * carrier privilege.
4480 * @param inputCode The dialer code to send
4481 */
4482 @Override
4483 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004484 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004486 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4487 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004488 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004489 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004490 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004491 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492
joonhunshin4ac60942023-11-15 15:23:39 +00004493 enforceTelephonyFeatureWithException(callingPackage,
4494 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496 final long identity = Binder.clearCallingIdentity();
4497 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004498 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
fionaxu235cc5e2017-03-06 22:25:57 -08004502 }
4503
Pengquan Menga1bb6272018-09-06 09:59:22 -07004504 @Override
4505 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004506 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004507 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4508 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004509
4510 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4511 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4512
shilufc958392020-01-20 11:36:01 -08004513 final long identity = Binder.clearCallingIdentity();
4514 try {
4515 if (!isActiveSubscription(subId)) {
4516 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4517 }
4518 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4519 } finally {
4520 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004522 }
4523
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004525 public boolean isInEmergencySmsMode() {
4526 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004527
4528 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4529 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4530
Brad Ebingerb2b65522019-03-15 13:48:47 -07004531 final long identity = Binder.clearCallingIdentity();
4532 try {
4533 for (Phone phone : PhoneFactory.getPhones()) {
4534 if (phone.isInEmergencySmsMode()) {
4535 return true;
4536 }
4537 }
4538 } finally {
4539 Binder.restoreCallingIdentity(identity);
4540 }
4541 return false;
4542 }
4543
shilu366312e2019-12-17 09:28:10 -08004544 /**
4545 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4546 * @param subId The subscription to use to check the configuration.
4547 * @param c The callback that will be used to send the result.
4548 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004549 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004550 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4551 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004552 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004553 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004554
4555 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4556 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4557 "IMS not available on device.");
4558 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004559 final long token = Binder.clearCallingIdentity();
4560 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004561 int slotId = getSlotIndexOrException(subId);
4562 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004563
4564 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4565 if (controller != null) {
4566 ImsManager imsManager = controller.getImsManager(subId);
4567 if (imsManager != null) {
4568 imsManager.addRegistrationCallbackForSubscription(c, subId);
4569 } else {
4570 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4571 }
4572 } else {
4573 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4574 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004575 } catch (ImsException e) {
4576 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004577 } finally {
4578 Binder.restoreCallingIdentity(token);
4579 }
4580 }
4581
shilu366312e2019-12-17 09:28:10 -08004582 /**
4583 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4584 * @param subId The subscription to use to check the configuration.
4585 * @param c The callback that will be used to send the result.
4586 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004587 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004588 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004589 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004590 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004591 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4592 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4593 }
Meng Wangafbc5852019-09-19 17:37:13 -07004594 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004595
Meng Wangafbc5852019-09-19 17:37:13 -07004596 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004597 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4598 if (controller != null) {
4599 ImsManager imsManager = controller.getImsManager(subId);
4600 if (imsManager != null) {
4601 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4602 } else {
4603 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4604 + "is inactive, ignoring unregister.");
4605 // If the ImsManager is not valid, just return, since the callback
4606 // will already have been removed internally.
4607 }
4608 }
Meng Wangafbc5852019-09-19 17:37:13 -07004609 } finally {
4610 Binder.restoreCallingIdentity(token);
4611 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004612 }
4613
Brad Ebingera34a6c22019-10-22 17:36:18 -07004614 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004615 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4616 * @param subId The subscription to use to check the configuration.
4617 * @param c The callback that will be used to send the result.
4618 */
4619 @Override
4620 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4621 throws RemoteException {
4622 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4623 mApp, subId, "registerImsEmergencyRegistrationCallback");
4624
4625 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4626 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4627 "IMS not available on device.");
4628 }
4629 final long token = Binder.clearCallingIdentity();
4630 try {
4631 int slotId = getSlotIndexOrException(subId);
4632 verifyImsMmTelConfiguredOrThrow(slotId);
4633
4634 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4635 if (controller != null) {
4636 ImsManager imsManager = controller.getImsManager(subId);
4637 if (imsManager != null) {
4638 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4639 } else {
4640 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4641 }
4642 } else {
4643 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4644 }
4645 } catch (ImsException e) {
4646 throw new ServiceSpecificException(e.getCode());
4647 } finally {
4648 Binder.restoreCallingIdentity(token);
4649 }
4650 }
4651
4652 /**
4653 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4654 * @param subId The subscription to use to check the configuration.
4655 * @param c The callback that will be used to send the result.
4656 */
4657 @Override
4658 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4659 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4660 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4661 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4662 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4663 }
4664 final long token = Binder.clearCallingIdentity();
4665
4666 try {
4667 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4668 if (controller != null) {
4669 ImsManager imsManager = controller.getImsManager(subId);
4670 if (imsManager != null) {
4671 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4672 } else {
4673 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4674 + "is inactive, ignoring unregister.");
4675 // If the ImsManager is not valid, just return, since the callback
4676 // will already have been removed internally.
4677 }
4678 }
4679 } finally {
4680 Binder.restoreCallingIdentity(token);
4681 }
4682 }
4683
4684 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004685 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4686 */
4687 @Override
4688 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4689 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4690 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4691 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4692 "IMS not available on device.");
4693 }
4694 final long token = Binder.clearCallingIdentity();
4695 try {
4696 Phone phone = getPhone(subId);
4697 if (phone == null) {
4698 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4699 + subId + "'");
4700 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4701 }
4702 phone.getImsRegistrationState(regState -> {
4703 try {
4704 consumer.accept((regState == null)
4705 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4706 } catch (RemoteException e) {
4707 // Ignore if the remote process is no longer available to call back.
4708 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4709 }
4710 });
4711 } finally {
4712 Binder.restoreCallingIdentity(token);
4713 }
4714 }
4715
4716 /**
4717 * Get the transport type for the IMS service registration state.
4718 */
4719 @Override
4720 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004721 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004722 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004723 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4724 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4725 "IMS not available on device.");
4726 }
4727 final long token = Binder.clearCallingIdentity();
4728 try {
4729 Phone phone = getPhone(subId);
4730 if (phone == null) {
4731 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4732 + subId + "'");
4733 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4734 }
4735 phone.getImsRegistrationTech(regTech -> {
4736 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4737 int regTechConverted = (regTech == null)
4738 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4739 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4740 regTechConverted);
4741 try {
4742 consumer.accept(regTechConverted);
4743 } catch (RemoteException e) {
4744 // Ignore if the remote process is no longer available to call back.
4745 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4746 }
4747 });
4748 } finally {
4749 Binder.restoreCallingIdentity(token);
4750 }
4751 }
4752
shilu366312e2019-12-17 09:28:10 -08004753 /**
4754 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4755 * @param subId The subscription to use to check the configuration.
4756 * @param c The callback that will be used to send the result.
4757 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004758 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004759 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4760 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004761 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004762 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004763 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4764 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4765 "IMS not available on device.");
4766 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004767 final long token = Binder.clearCallingIdentity();
4768 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004769 int slotId = getSlotIndexOrException(subId);
4770 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004771
4772 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4773 if (controller != null) {
4774 ImsManager imsManager = controller.getImsManager(subId);
4775 if (imsManager != null) {
4776 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4777 } else {
4778 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4779 }
4780 } else {
4781 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4782 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004783 } catch (ImsException e) {
4784 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 } finally {
4786 Binder.restoreCallingIdentity(token);
4787 }
4788 }
4789
shilu366312e2019-12-17 09:28:10 -08004790 /**
4791 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4792 * @param subId The subscription to use to check the configuration.
4793 * @param c The callback that will be used to send the result.
4794 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004795 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004796 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004797 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004798 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004799 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4800 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4801 }
Meng Wangafbc5852019-09-19 17:37:13 -07004802
4803 final long token = Binder.clearCallingIdentity();
4804 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004805 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4806 if (controller != null) {
4807 ImsManager imsManager = controller.getImsManager(subId);
4808 if (imsManager != null) {
4809 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4810 } else {
4811 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4812 + " is inactive, ignoring unregister.");
4813 // If the ImsManager is not valid, just return, since the callback
4814 // will already have been removed internally.
4815 }
4816 }
Meng Wangafbc5852019-09-19 17:37:13 -07004817 } finally {
4818 Binder.restoreCallingIdentity(token);
4819 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004820 }
4821
4822 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004823 public boolean isCapable(int subId, int capability, int regTech) {
4824 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004825
4826 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4827 FEATURE_TELEPHONY_IMS, "isCapable");
4828
Brad Ebinger35c841c2018-10-01 10:40:55 -07004829 final long token = Binder.clearCallingIdentity();
4830 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004831 int slotId = getSlotIndexOrException(subId);
4832 verifyImsMmTelConfiguredOrThrow(slotId);
4833 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4834 } catch (com.android.ims.ImsException e) {
4835 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4836 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004837 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004838 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4839 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004840 } finally {
4841 Binder.restoreCallingIdentity(token);
4842 }
4843 }
4844
4845 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004846 public boolean isAvailable(int subId, int capability, int regTech) {
4847 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004848
4849 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4850 FEATURE_TELEPHONY_IMS, "isAvailable");
4851
Brad Ebinger35c841c2018-10-01 10:40:55 -07004852 final long token = Binder.clearCallingIdentity();
4853 try {
4854 Phone phone = getPhone(subId);
4855 if (phone == null) return false;
4856 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004857 } catch (com.android.ims.ImsException e) {
4858 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4859 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004860 } finally {
4861 Binder.restoreCallingIdentity(token);
4862 }
4863 }
4864
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004865 /**
4866 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4867 * subscription.
4868 * @param subId The subscription to use to check the configuration.
4869 * @param callback The callback that will be used to send the result.
4870 * @param capability The MmTelFeature capability that will be used to send the result.
4871 * @param transportType The transport type of the MmTelFeature capability.
4872 */
4873 @Override
4874 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4875 int transportType) {
4876 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004877 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4878 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4879 "IMS not available on device.");
4880 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004881 final long token = Binder.clearCallingIdentity();
4882 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004883 int slotId = getSlotIndex(subId);
4884 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4885 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4886 + subId + "'");
4887 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4888 }
4889 verifyImsMmTelConfiguredOrThrow(slotId);
4890 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4891 transportType, aBoolean -> {
4892 try {
4893 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4894 } catch (RemoteException e) {
4895 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4896 + "running. Ignore");
4897 }
4898 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004899 } catch (ImsException e) {
4900 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004901 } finally {
4902 Binder.restoreCallingIdentity(token);
4903 }
4904 }
4905
shilu366312e2019-12-17 09:28:10 -08004906 /**
4907 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4908 * @param subId The subscription to use to check the configuration.
4909 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004910 @Override
4911 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004912 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004913 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004914
joonhunshin4ac60942023-11-15 15:23:39 +00004915 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4916 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4917
Brad Ebinger35c841c2018-10-01 10:40:55 -07004918 final long token = Binder.clearCallingIdentity();
4919 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004920 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004921 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004922 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004923 } catch (ImsException e) {
4924 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004925 } finally {
4926 Binder.restoreCallingIdentity(token);
4927 }
4928 }
4929
4930 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004931 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004933 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004934
4935 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4936 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4937
Brad Ebinger35c841c2018-10-01 10:40:55 -07004938 final long identity = Binder.clearCallingIdentity();
4939 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004940 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004941 // This setting doesn't require an active ImsService connection, so do not verify. The
4942 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004943 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004944 } catch (ImsException e) {
4945 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004946 } finally {
4947 Binder.restoreCallingIdentity(identity);
4948 }
4949 }
4950
shilu366312e2019-12-17 09:28:10 -08004951 /**
4952 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4953 * @param subId The subscription to use to check the configuration.
4954 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004955 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004956 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004957 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004958 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004959
4960 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4961 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4962
Brad Ebinger35c841c2018-10-01 10:40:55 -07004963 final long identity = Binder.clearCallingIdentity();
4964 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004965 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004966 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004967 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004968 } catch (ImsException e) {
4969 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
4973 }
4974
4975 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004976 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004978 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004979
4980 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4981 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4982
Brad Ebinger35c841c2018-10-01 10:40:55 -07004983 final long identity = Binder.clearCallingIdentity();
4984 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004985 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004986 // This setting doesn't require an active ImsService connection, so do not verify. The
4987 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004988 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004989 } catch (ImsException e) {
4990 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
4994 }
4995
shilu366312e2019-12-17 09:28:10 -08004996 /**
4997 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4998 * @param subId The subscription to use to check the configuration.
4999 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005000 @Override
5001 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005002 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005003 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005004
5005 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5006 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5007
Brad Ebinger35c841c2018-10-01 10:40:55 -07005008 final long identity = Binder.clearCallingIdentity();
5009 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005010 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005011 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005012 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005013 } catch (ImsException e) {
5014 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005015 } finally {
5016 Binder.restoreCallingIdentity(identity);
5017 }
5018 }
5019
5020 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005021 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005023 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005024
5025 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5026 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5027
Brad Ebinger35c841c2018-10-01 10:40:55 -07005028 final long identity = Binder.clearCallingIdentity();
5029 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005030 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005031 // This setting doesn't require an active ImsService connection, so do not verify. The
5032 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005033 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005034 } catch (ImsException e) {
5035 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005036 } finally {
5037 Binder.restoreCallingIdentity(identity);
5038 }
5039 }
5040
shilu366312e2019-12-17 09:28:10 -08005041 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005042 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5043 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5044 * @param subId The subscription to use to check the configuration.
5045 */
5046 @Override
5047 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005048 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005049 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005050
5051 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5052 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5053
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005056 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005057 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005058 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005059 } catch (ImsException e) {
5060 throw new ServiceSpecificException(e.getCode());
5061 } finally {
5062 Binder.restoreCallingIdentity(identity);
5063 }
5064 }
5065
5066 /**
5067 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5068 * Requires MODIFY_PHONE_STATE permission.
5069 * @param subId The subscription to use to check the configuration.
5070 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5071 * false otherwise
5072 */
5073 @Override
5074 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5076 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005077
5078 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5079 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5080
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005081 final long identity = Binder.clearCallingIdentity();
5082 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005083 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005084 // This setting doesn't require an active ImsService connection, so do not verify. The
5085 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005086 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005087 } catch (ImsException e) {
5088 throw new ServiceSpecificException(e.getCode());
5089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
5092 }
5093
5094 /**
shilu366312e2019-12-17 09:28:10 -08005095 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5096 * @param subId The subscription to use to check the configuration.
5097 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005098 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005099
Brad Ebinger35c841c2018-10-01 10:40:55 -07005100 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005101 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005102 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005103
5104 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5105 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5106
Brad Ebinger35c841c2018-10-01 10:40:55 -07005107 final long identity = Binder.clearCallingIdentity();
5108 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005109 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005110 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005111 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005112 } catch (ImsException e) {
5113 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
5117 }
5118
5119 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005120 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005122 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005123
5124 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5125 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5126
Brad Ebinger35c841c2018-10-01 10:40:55 -07005127 final long identity = Binder.clearCallingIdentity();
5128 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005129 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005130 // This setting doesn't require an active ImsService connection, so do not verify. The
5131 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005132 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005133 } catch (ImsException e) {
5134 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005135 } finally {
5136 Binder.restoreCallingIdentity(identity);
5137 }
5138 }
5139
5140 @Override
5141 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5143 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005144
5145 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5146 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5147
Brad Ebinger35c841c2018-10-01 10:40:55 -07005148 final long identity = Binder.clearCallingIdentity();
5149 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005150 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005151 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005152 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005153 } catch (ImsException e) {
5154 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005155 } finally {
5156 Binder.restoreCallingIdentity(identity);
5157 }
5158 }
5159
shilu366312e2019-12-17 09:28:10 -08005160 /**
5161 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5162 * @param subId The subscription to use to check the configuration.
5163 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005164 @Override
5165 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005166 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005167 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005168
5169 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5170 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5171
Brad Ebinger35c841c2018-10-01 10:40:55 -07005172 final long identity = Binder.clearCallingIdentity();
5173 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005174 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005175 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005176 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005177 } catch (ImsException e) {
5178 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005179 } finally {
5180 Binder.restoreCallingIdentity(identity);
5181 }
5182 }
5183
5184 @Override
5185 public void setVoWiFiModeSetting(int subId, int mode) {
5186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5187 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005188
5189 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5190 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5191
Brad Ebinger35c841c2018-10-01 10:40:55 -07005192 final long identity = Binder.clearCallingIdentity();
5193 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005194 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005195 // This setting doesn't require an active ImsService connection, so do not verify. The
5196 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005197 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005198 } catch (ImsException e) {
5199 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
5203 }
5204
5205 @Override
5206 public int getVoWiFiRoamingModeSetting(int subId) {
5207 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005208
5209 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5210 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5211
Brad Ebinger35c841c2018-10-01 10:40:55 -07005212 final long identity = Binder.clearCallingIdentity();
5213 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005214 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005215 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005216 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005217 } catch (ImsException e) {
5218 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005219 } finally {
5220 Binder.restoreCallingIdentity(identity);
5221 }
5222 }
5223
5224 @Override
5225 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5227 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005228
5229 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5230 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5231
Brad Ebinger35c841c2018-10-01 10:40:55 -07005232 final long identity = Binder.clearCallingIdentity();
5233 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005234 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005235 // This setting doesn't require an active ImsService connection, so do not verify. The
5236 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005237 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005238 } catch (ImsException e) {
5239 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
5243 }
5244
5245 @Override
5246 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5248 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005249
5250 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5251 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5252
Brad Ebinger35c841c2018-10-01 10:40:55 -07005253 final long identity = Binder.clearCallingIdentity();
5254 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005255 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005256 // This setting doesn't require an active ImsService connection, so do not verify. The
5257 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005258 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005259 } catch (ImsException e) {
5260 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005261 } finally {
5262 Binder.restoreCallingIdentity(identity);
5263 }
5264 }
5265
shilu366312e2019-12-17 09:28:10 -08005266 /**
5267 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5268 * @param subId The subscription to use to check the configuration.
5269 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005270 @Override
5271 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005272 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005273 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005274
5275 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5276 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5277
Brad Ebinger35c841c2018-10-01 10:40:55 -07005278 final long identity = Binder.clearCallingIdentity();
5279 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005280 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005281 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005282 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005283 } catch (ImsException e) {
5284 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
5288 }
5289
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005290 @Override
5291 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5292 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005293
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005294 final long identity = Binder.clearCallingIdentity();
5295 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005296 if (!isImsAvailableOnDevice()) {
5297 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5298 "IMS not available on device.");
5299 }
5300 int slotId = getSlotIndexOrException(subId);
5301 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005302
5303 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5304 if (controller != null) {
5305 ImsManager imsManager = controller.getImsManager(subId);
5306 if (imsManager != null) {
5307 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5308 } else {
5309 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5310 }
5311 } else {
5312 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5313 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005314 } catch (ImsException e) {
5315 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005316 } finally {
5317 Binder.restoreCallingIdentity(identity);
5318 }
5319 }
5320
5321 @Override
5322 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5323 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005324
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005325 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005326 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5327 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5328 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005329 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005330 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5331 if (controller != null) {
5332 ImsManager imsManager = controller.getImsManager(subId);
5333 if (imsManager != null) {
5334 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5335 } else {
5336 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5337 + " is inactive, ignoring unregister.");
5338 // If the ImsManager is not valid, just return, since the callback will already
5339 // have been removed internally.
5340 }
5341 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005342 } finally {
5343 Binder.restoreCallingIdentity(identity);
5344 }
5345 }
5346
joonhunshincffb7fc2021-11-28 07:32:01 +00005347 @Override
5348 public void registerFeatureProvisioningChangedCallback(int subId,
5349 IFeatureProvisioningCallback callback) {
5350 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5351 mApp, subId, "registerFeatureProvisioningChangedCallback");
5352
5353 final long identity = Binder.clearCallingIdentity();
5354 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5355 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5356 }
5357
joonhunshin91bc1952022-04-29 08:47:15 +00005358 try {
5359 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5360 if (controller == null) {
5361 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5362 "Device does not support IMS");
5363 }
5364 controller.addFeatureProvisioningChangedCallback(subId, callback);
5365 } finally {
5366 Binder.restoreCallingIdentity(identity);
5367 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005368 }
5369
5370 @Override
5371 public void unregisterFeatureProvisioningChangedCallback(int subId,
5372 IFeatureProvisioningCallback callback) {
5373 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5374 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5375
5376 final long identity = Binder.clearCallingIdentity();
5377 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5378 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5379 }
5380
joonhunshin91bc1952022-04-29 08:47:15 +00005381 try {
5382 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5383 if (controller == null) {
5384 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5385 return;
5386 }
5387 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5388 } finally {
5389 Binder.restoreCallingIdentity(identity);
5390 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005391 }
allenwtsu99c623b2020-01-03 18:24:23 +08005392
5393 private void checkModifyPhoneStatePermission(int subId, String message) {
5394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5395 message);
5396 }
5397
allenwtsu99c623b2020-01-03 18:24:23 +08005398 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005399 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005400 boolean isProvisioned) {
5401 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5402
joonhunshin4ac60942023-11-15 15:23:39 +00005403 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5404 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5405
allenwtsu99c623b2020-01-03 18:24:23 +08005406 final long identity = Binder.clearCallingIdentity();
5407 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005408 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5409 if (controller == null) {
5410 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5411 return;
5412 }
5413 controller.setRcsProvisioningStatusForCapability(
5414 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005415 } finally {
5416 Binder.restoreCallingIdentity(identity);
5417 }
allenwtsu99c623b2020-01-03 18:24:23 +08005418 }
5419
5420
5421 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005422 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5423 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5424 mApp, subId, "getRcsProvisioningStatusForCapability");
5425
joonhunshin4ac60942023-11-15 15:23:39 +00005426 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5427 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5428
allenwtsu99c623b2020-01-03 18:24:23 +08005429 final long identity = Binder.clearCallingIdentity();
5430 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005431 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5432 if (controller == null) {
5433 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5434
5435 // device does not support IMS, this method will return true always.
5436 return true;
5437 }
5438 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005439 } finally {
5440 Binder.restoreCallingIdentity(identity);
5441 }
5442 }
5443
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005444 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005445 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5446 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005447 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005448
joonhunshin4ac60942023-11-15 15:23:39 +00005449 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5450 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5451
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005452 final long identity = Binder.clearCallingIdentity();
5453 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005454 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5455 if (controller == null) {
5456 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5457 return;
5458 }
5459 controller.setImsProvisioningStatusForCapability(
5460 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
5464 }
5465
5466 @Override
5467 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005468 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5469 mApp, subId, "getProvisioningStatusForCapability");
5470
joonhunshin4ac60942023-11-15 15:23:39 +00005471 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5472 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5473
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005474 final long identity = Binder.clearCallingIdentity();
5475 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005476 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5477 if (controller == null) {
5478 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005479
joonhunshin91bc1952022-04-29 08:47:15 +00005480 // device does not support IMS, this method will return true always.
5481 return true;
5482 }
5483 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005484 } finally {
5485 Binder.restoreCallingIdentity(identity);
5486 }
5487 }
5488
5489 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005490 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5491 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5492 mApp, subId, "isProvisioningRequiredForCapability");
5493
joonhunshin4ac60942023-11-15 15:23:39 +00005494 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5495 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5496
joonhunshincffb7fc2021-11-28 07:32:01 +00005497 final long identity = Binder.clearCallingIdentity();
5498 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005499 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5500 if (controller == null) {
5501 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5502
5503 // device does not support IMS, this method will return false
5504 return false;
5505 }
5506 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005507 } finally {
5508 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005509 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005510 }
5511
5512 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005513 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5514 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5515 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005516
joonhunshin4ac60942023-11-15 15:23:39 +00005517 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5518 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5519
joonhunshincffb7fc2021-11-28 07:32:01 +00005520 final long identity = Binder.clearCallingIdentity();
5521 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005522 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5523 if (controller == null) {
5524 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5525
5526 // device does not support IMS, this method will return false
5527 return false;
5528 }
5529 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005530 } finally {
5531 Binder.restoreCallingIdentity(identity);
5532 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005533 }
5534
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005535 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005536 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005537 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5538 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5539 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005540 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5541 mApp, subId, "getImsProvisioningInt");
5542
joonhunshin4ac60942023-11-15 15:23:39 +00005543 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5544 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5545
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005546 final long identity = Binder.clearCallingIdentity();
5547 try {
5548 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005549 int slotId = getSlotIndex(subId);
5550 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5551 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5552 + subId + "' for key:" + key);
5553 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5554 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005555
joonhunshin91bc1952022-04-29 08:47:15 +00005556 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5557 if (controller == null) {
5558 loge("getImsProvisioningInt: Device does not support IMS");
5559
5560 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5561 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5562 }
5563 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005564 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5565 return retVal;
5566 }
5567
calvinpanb5a34062021-02-08 19:59:36 +08005568 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005569 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005570 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5571 + subId + "' for key:" + key);
5572 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
5576 }
5577
5578 @Override
5579 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005580 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5581 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5582 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005583 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5584 mApp, subId, "getImsProvisioningString");
5585
joonhunshin4ac60942023-11-15 15:23:39 +00005586 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5587 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5588
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005589 final long identity = Binder.clearCallingIdentity();
5590 try {
5591 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005592 int slotId = getSlotIndex(subId);
5593 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5594 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5595 + subId + "' for key:" + key);
5596 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5597 }
calvinpanb5a34062021-02-08 19:59:36 +08005598 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005599 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005600 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5601 + subId + "' for key:" + key);
5602 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005603 } finally {
5604 Binder.restoreCallingIdentity(identity);
5605 }
5606 }
5607
5608 @Override
5609 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005610 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5611 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5612 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5614 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005615
joonhunshin4ac60942023-11-15 15:23:39 +00005616 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5617 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5618
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005622 int slotId = getSlotIndex(subId);
5623 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5624 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5625 + subId + "' for key:" + key);
5626 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5627 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005628
joonhunshin91bc1952022-04-29 08:47:15 +00005629 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5630 if (controller == null) {
5631 loge("setImsProvisioningInt: Device does not support IMS");
5632
5633 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5634 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5635 }
5636 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005637 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5638 return retVal;
5639 }
5640
calvinpanb5a34062021-02-08 19:59:36 +08005641 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5642 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005643 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005644 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005645 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005646 } finally {
5647 Binder.restoreCallingIdentity(identity);
5648 }
5649 }
5650
5651 @Override
5652 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005653 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5654 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5655 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5657 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005658
5659 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5660 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5661
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005665 int slotId = getSlotIndex(subId);
5666 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5667 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5668 + subId + "' for key:" + key);
5669 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5670 }
calvinpanb5a34062021-02-08 19:59:36 +08005671 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5672 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005673 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005674 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005675 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005676 } finally {
5677 Binder.restoreCallingIdentity(identity);
5678 }
5679 }
5680
Brad Ebinger919631e2021-06-02 17:46:35 -07005681 /**
5682 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5683 * for the given slot ID or no ImsResolver instance has been created.
5684 * @param slotId The slot ID that the IMS service is created for.
5685 * @throws ImsException If there is no ImsService configured for this slot.
5686 */
5687 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5688 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5689 ImsFeature.FEATURE_MMTEL)) {
5690 throw new ImsException("This subscription does not support MMTEL over IMS",
5691 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5692 }
5693 }
5694
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005695 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005696 int slotId = SubscriptionManager.getSlotIndex(subId);
5697 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005698 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5699 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005700 }
5701 return slotId;
5702 }
5703
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005704 private int getSlotIndex(int subId) {
5705 int slotId = SubscriptionManager.getSlotIndex(subId);
5706 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5707 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5708 }
5709 return slotId;
5710 }
5711
Wink Saville36469e72014-06-11 15:17:00 -07005712 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005713 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005714 */
5715 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005716 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5717 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005718 try {
5719 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5720 } catch (SecurityException se) {
5721 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5722 throw new SecurityException("Package " + callingPackage + " does not belong to "
5723 + Binder.getCallingUid());
5724 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005725 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005726 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005727 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005728 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005729 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005730 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005731 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005732 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5733 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005734
joonhunshin4ac60942023-11-15 15:23:39 +00005735 enforceTelephonyFeatureWithException(callingPackage,
5736 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 final long identity = Binder.clearCallingIdentity();
5739 try {
5740 final Phone phone = getPhone(subId);
5741 if (phone != null) {
5742 return phone.getServiceState().getDataNetworkType();
5743 } else {
5744 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5745 }
5746 } finally {
5747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005749 }
5750
5751 /**
5752 * Returns the data network type
5753 */
5754 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005755 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005756 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005757 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005758 }
5759
5760 /**
5761 * Returns the data network type for a subId
5762 */
5763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005764 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5765 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005766 String functionName = "getDataNetworkTypeForSubscriber";
5767 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5768 mApp, functionName)) {
5769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5770 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5771 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5772 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005773 }
5774
joonhunshin4ac60942023-11-15 15:23:39 +00005775 enforceTelephonyFeatureWithException(callingPackage,
5776 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 final long identity = Binder.clearCallingIdentity();
5779 try {
5780 final Phone phone = getPhone(subId);
5781 if (phone != null) {
5782 return phone.getServiceState().getDataNetworkType();
5783 } else {
5784 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5785 }
5786 } finally {
5787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005789 }
5790
5791 /**
Wink Saville36469e72014-06-11 15:17:00 -07005792 * Returns the Voice network type for a subId
5793 */
5794 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005795 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5796 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005797 String functionName = "getVoiceNetworkTypeForSubscriber";
5798 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5799 mApp, functionName)) {
5800 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5801 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5802 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5803 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005804 }
5805
joonhunshin4ac60942023-11-15 15:23:39 +00005806 enforceTelephonyFeatureWithException(callingPackage,
5807 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809 final long identity = Binder.clearCallingIdentity();
5810 try {
5811 final Phone phone = getPhone(subId);
5812 if (phone != null) {
5813 return phone.getServiceState().getVoiceNetworkType();
5814 } else {
5815 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5816 }
5817 } finally {
5818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005820 }
5821
5822 /**
5823 * @return true if a ICC card is present
5824 */
5825 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005826 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005827 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005828 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005829 }
5830
5831 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005832 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005833 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005834 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005835 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005836 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5837 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 final long identity = Binder.clearCallingIdentity();
5840 try {
5841 final Phone phone = PhoneFactory.getPhone(slotIndex);
5842 if (phone != null) {
5843 return phone.getIccCard().hasIccCard();
5844 } else {
5845 return false;
5846 }
5847 } finally {
5848 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005850 }
5851
5852 /**
5853 * Return if the current radio is LTE on CDMA. This
5854 * is a tri-state return value as for a period of time
5855 * the mode may be unknown.
5856 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005857 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005858 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005859 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005860 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005861 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005862 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5863 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5864 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005865 }
5866
Sanket Padawe356d7632015-06-22 14:03:32 -07005867 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005868 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5869 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005870 try {
5871 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5872 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005873 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5874 }
5875
joonhunshin4ac60942023-11-15 15:23:39 +00005876 enforceTelephonyFeatureWithException(callingPackage,
5877 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 final long identity = Binder.clearCallingIdentity();
5880 try {
5881 final Phone phone = getPhone(subId);
5882 if (phone == null) {
5883 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5884 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005885 return TelephonyProperties.lte_on_cdma_device()
5886 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 }
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005890 }
Wink Saville36469e72014-06-11 15:17:00 -07005891 }
5892
Wink Saville36469e72014-06-11 15:17:00 -07005893 /**
5894 * {@hide}
5895 * Returns Default subId, 0 in the case of single standby.
5896 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005897 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005898 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005899 }
5900
Shishir Agrawala9f32182016-04-12 12:00:16 -07005901 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005902 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005903 }
5904
Wink Savilleb564aae2014-10-23 10:18:09 -07005905 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005906 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005907 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005908
Pengquan Menge92a50d2018-09-21 15:54:48 -07005909 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005910 return getSubscriptionManagerService().isActiveSubId(subId,
5911 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005912 }
5913
Ihab Awadf2177b72013-11-25 13:33:23 -08005914 /**
5915 * @see android.telephony.TelephonyManager.WifiCallingChoices
5916 */
5917 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 final long identity = Binder.clearCallingIdentity();
5919 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005920 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5922 getWhenToMakeWifiCallsDefaultPreference());
5923 } finally {
5924 Binder.restoreCallingIdentity(identity);
5925 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005926 }
5927
5928 /**
5929 * @see android.telephony.TelephonyManager.WifiCallingChoices
5930 */
5931 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 final long identity = Binder.clearCallingIdentity();
5933 try {
5934 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005935 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005940 }
5941
Sailesh Nepald1e68152013-12-12 19:08:02 -08005942 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005943 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005944 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005945 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005946
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005947 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5948 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5949 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005950 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005951 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005952 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005953 }
5954 return PhoneFactory.getPhone(phoneId);
5955 }
5956
Shishir Agrawal566b7612013-10-28 14:41:00 -07005957 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005958 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005959 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005960
Rambo Wanga1782702021-11-10 20:15:19 -08005961 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5962 /*message=*/ "iccOpenLogicalChannel");
5963
5964 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5965 // Verify that the callingPackage in the request belongs to the calling UID
5966 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5967
joonhunshin4ac60942023-11-15 15:23:39 +00005968 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5969 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5970
Rambo Wanga1782702021-11-10 20:15:19 -08005971 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005972 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005973
Rambo Wanga1782702021-11-10 20:15:19 -08005974 private Phone getPhoneFromValidIccLogicalChannelRequest(
5975 @NonNull IccLogicalChannelRequest request, String message) {
5976 Phone phone;
5977 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5979 mApp, request.subId, message);
5980 phone = getPhoneFromSubId(request.subId);
5981 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5982 enforceModifyPermission();
5983 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5984 } else {
5985 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005986 }
Rambo Wanga1782702021-11-10 20:15:19 -08005987 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005988 }
5989
5990 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005991 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 final long identity = Binder.clearCallingIdentity();
5993 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005994 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005996 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5997 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005998 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5999 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 loge("The calling package is not allowed to access ISD-R.");
6001 throw new SecurityException(
6002 "The calling package is not allowed to access ISD-R.");
6003 }
Derek Tan740e1672017-06-27 14:56:27 -07006004 }
Derek Tan740e1672017-06-27 14:56:27 -07006005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006007 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6008 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 return response;
6010 } finally {
6011 Binder.restoreCallingIdentity(identity);
6012 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006013 }
6014
6015 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006016 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006017 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6018 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6019
Rambo Wanga1782702021-11-10 20:15:19 -08006020 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6021 /*message=*/"iccCloseLogicalChannel");
6022
6023 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6024
6025 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006026 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006027
Rambo Wanga1782702021-11-10 20:15:19 -08006028 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6029 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006030 // before this feature is enabled, this API should only return false if
6031 // the operation fails instead of throwing runtime exception for
6032 // backward-compatibility.
6033 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6034 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 final long identity = Binder.clearCallingIdentity();
6036 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006037 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006038 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 }
Chen Xue9d737e2022-01-01 23:41:31 -08006040 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006041 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006042 Boolean success = false;
6043 if (result instanceof RuntimeException) {
6044 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006045 if (shouldThrowExceptionOnFailure) {
6046 throw (RuntimeException) result;
6047 } else {
6048 return false;
6049 }
Chen Xue9d737e2022-01-01 23:41:31 -08006050 } else if (result instanceof Boolean) {
6051 success = (Boolean) result;
6052 } else {
6053 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6054 }
Rambo Wanga1782702021-11-10 20:15:19 -08006055 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 return success;
6057 } finally {
6058 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006059 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006060 }
6061
6062 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006063 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006064 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6066 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006067
6068 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6069 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6070
Jordan Liu4c733742019-02-28 12:03:40 -08006071 if (DBG) {
6072 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6073 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6074 + p3 + " data=" + data);
6075 }
6076 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6077 command, p1, p2, p3, data);
6078 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006079
Jordan Liu4c733742019-02-28 12:03:40 -08006080 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006081 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006082 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006083 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006084
6085 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6086 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6087 "iccTransmitApduLogicalChannelBySlot");
6088
Jordan Liu4c733742019-02-28 12:03:40 -08006089 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006090 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006091 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6092 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006093 }
6094 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006095 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6096 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006097 }
6098
6099 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6100 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101 final long identity = Binder.clearCallingIdentity();
6102 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006103 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104 return "";
6105 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006108 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6109 null /* workSource */);
6110 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 // Append the returned status code to the end of the response payload.
6113 String s = Integer.toHexString(
6114 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6115 if (response.payload != null) {
6116 s = IccUtils.bytesToHexString(response.payload) + s;
6117 }
6118 return s;
6119 } finally {
6120 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006121 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006122 }
Jake Hambye994d462014-02-03 13:10:13 -08006123
Evan Charltonc66da362014-05-16 14:06:40 -07006124 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006125 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6126 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6128 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006130
6131 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6132 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6133
Jordan Liu4c733742019-02-28 12:03:40 -08006134 if (DBG) {
6135 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6136 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6137 }
6138 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6139 cla, command, p1, p2, p3, data);
6140 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006141
Jordan Liu4c733742019-02-28 12:03:40 -08006142 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006143 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006144 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006145 enforceModifyPermission();
6146 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006147
6148 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6149 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6150
Jordan Liu4c733742019-02-28 12:03:40 -08006151 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006152 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006153 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6154 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006155 }
6156
6157 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006158 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6159 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006160 }
6161
6162 // open APDU basic channel assuming the caller has sufficient permissions
6163 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6164 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 final long identity = Binder.clearCallingIdentity();
6166 try {
6167 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6168 && TextUtils.equals(ISDR_AID, data)) {
6169 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006170 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6171 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 if (bestComponent == null
6173 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6174 loge("The calling package is not allowed to select ISD-R.");
6175 throw new SecurityException(
6176 "The calling package is not allowed to select ISD-R.");
6177 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006178 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006180 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006181 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6182 null /* workSource */);
6183 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006185 // Append the returned status code to the end of the response payload.
6186 String s = Integer.toHexString(
6187 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6188 if (response.payload != null) {
6189 s = IccUtils.bytesToHexString(response.payload) + s;
6190 }
6191 return s;
6192 } finally {
6193 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006194 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006195 }
6196
6197 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006198 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006199 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6201 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006202
joonhunshin4ac60942023-11-15 15:23:39 +00006203 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6204 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6205
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006206 final long identity = Binder.clearCallingIdentity();
6207 try {
6208 if (DBG) {
6209 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6210 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6211 }
6212
6213 IccIoResult response =
6214 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6215 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6216 subId);
6217
6218 if (DBG) {
6219 log("Exchange SIM_IO [R]" + response);
6220 }
6221
6222 byte[] result = null;
6223 int length = 2;
6224 if (response.payload != null) {
6225 length = 2 + response.payload.length;
6226 result = new byte[length];
6227 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6228 } else {
6229 result = new byte[length];
6230 }
6231
6232 result[length - 1] = (byte) response.sw2;
6233 result[length - 2] = (byte) response.sw1;
6234 return result;
6235 } finally {
6236 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006237 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006238 }
6239
Nathan Haroldb3014052017-01-25 15:57:32 -08006240 /**
6241 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6242 * on a particular subscription
6243 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006244 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6245 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006247 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006248 return null;
6249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250
joonhunshin4ac60942023-11-15 15:23:39 +00006251 enforceTelephonyFeatureWithException(callingPackage,
6252 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006254 final long identity = Binder.clearCallingIdentity();
6255 try {
6256 if (appType != TelephonyManager.APPTYPE_USIM
6257 && appType != TelephonyManager.APPTYPE_SIM) {
6258 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6259 return null;
6260 }
6261 Object response = sendRequest(
6262 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6263 if (response instanceof String[]) {
6264 return (String[]) response;
6265 }
yincheng zhao2737e882019-09-06 17:06:54 -07006266 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006268 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269 } finally {
6270 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006271 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006272 }
6273
yincheng zhao2737e882019-09-06 17:06:54 -07006274 /**
6275 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6276 * subscription.
6277 *
6278 * @param subId the id of the subscription.
6279 * @param appType the uicc app type, must be USIM or SIM.
6280 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6281 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006282 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006283 * @return number of fplmns that is successfully written to the SIM.
6284 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006285 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6286 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006287 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6288 mApp, subId, "setForbiddenPlmns");
6289
joonhunshin4ac60942023-11-15 15:23:39 +00006290 enforceTelephonyFeatureWithException(callingPackage,
6291 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6292
yincheng zhao2737e882019-09-06 17:06:54 -07006293 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6294 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6295 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6296 }
6297 if (fplmns == null) {
6298 throw new IllegalArgumentException("Fplmn List provided is null");
6299 }
6300 for (String fplmn : fplmns) {
6301 if (!CellIdentity.isValidPlmn(fplmn)) {
6302 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6303 }
6304 }
6305 final long identity = Binder.clearCallingIdentity();
6306 try {
6307 Object response = sendRequest(
6308 CMD_SET_FORBIDDEN_PLMNS,
6309 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6310 subId);
6311 return (int) response;
6312 } finally {
6313 Binder.restoreCallingIdentity(identity);
6314 }
6315 }
6316
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006317 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006318 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6320 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006321
joonhunshin4ac60942023-11-15 15:23:39 +00006322 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6323 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325 final long identity = Binder.clearCallingIdentity();
6326 try {
6327 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6328 if (response.payload == null) {
6329 return "";
6330 }
Evan Charltonc66da362014-05-16 14:06:40 -07006331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 // Append the returned status code to the end of the response payload.
6333 String s = Integer.toHexString(
6334 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6335 s = IccUtils.bytesToHexString(response.payload) + s;
6336 return s;
6337 } finally {
6338 Binder.restoreCallingIdentity(identity);
6339 }
Evan Charltonc66da362014-05-16 14:06:40 -07006340 }
6341
Jake Hambye994d462014-02-03 13:10:13 -08006342 /**
6343 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6344 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6345 *
6346 * @param itemID the ID of the item to read
6347 * @return the NV item as a String, or null on error.
6348 */
6349 @Override
6350 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006351 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6353 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354
6355 final long identity = Binder.clearCallingIdentity();
6356 try {
6357 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006358 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6360 return value;
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
Jake Hambye994d462014-02-03 13:10:13 -08006364 }
6365
6366 /**
6367 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6368 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6369 *
6370 * @param itemID the ID of the item to read
6371 * @param itemValue the value to write, as a String
6372 * @return true on success; false on any failure
6373 */
6374 @Override
6375 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006376 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6378 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379
6380 final long identity = Binder.clearCallingIdentity();
6381 try {
6382 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6383 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006384 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6386 return success;
6387 } finally {
6388 Binder.restoreCallingIdentity(identity);
6389 }
Jake Hambye994d462014-02-03 13:10:13 -08006390 }
6391
6392 /**
6393 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6394 * Used for device configuration by some CDMA operators.
6395 *
6396 * @param preferredRoamingList byte array containing the new PRL
6397 * @return true on success; false on any failure
6398 */
6399 @Override
6400 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6402 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403
6404 final long identity = Binder.clearCallingIdentity();
6405 try {
6406 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6407 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6408 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6409 return success;
6410 } finally {
6411 Binder.restoreCallingIdentity(identity);
6412 }
Jake Hambye994d462014-02-03 13:10:13 -08006413 }
6414
6415 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006416 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006417 * Used for device configuration by some CDMA operators.
6418 *
chen xu6dac5ab2018-10-26 17:39:23 -07006419 * @param slotIndex - device slot.
6420 *
Jake Hambye994d462014-02-03 13:10:13 -08006421 * @return true on success; false on any failure
6422 */
6423 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006424 public boolean resetModemConfig(int slotIndex) {
6425 Phone phone = PhoneFactory.getPhone(slotIndex);
6426 if (phone != null) {
6427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6428 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429
joonhunshin4ac60942023-11-15 15:23:39 +00006430 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6431 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6432
chen xu6dac5ab2018-10-26 17:39:23 -07006433 final long identity = Binder.clearCallingIdentity();
6434 try {
6435 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6436 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6437 return success;
6438 } finally {
6439 Binder.restoreCallingIdentity(identity);
6440 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006441 }
chen xu6dac5ab2018-10-26 17:39:23 -07006442 return false;
6443 }
6444
6445 /**
6446 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6447 *
6448 * @param slotIndex - device slot.
6449 *
6450 * @return true on success; false on any failure
6451 */
6452 @Override
6453 public boolean rebootModem(int slotIndex) {
6454 Phone phone = PhoneFactory.getPhone(slotIndex);
6455 if (phone != null) {
6456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6457 mApp, phone.getSubId(), "rebootModem");
6458
joonhunshin4ac60942023-11-15 15:23:39 +00006459 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6460 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6461
chen xu6dac5ab2018-10-26 17:39:23 -07006462 final long identity = Binder.clearCallingIdentity();
6463 try {
6464 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6465 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6466 return success;
6467 } finally {
6468 Binder.restoreCallingIdentity(identity);
6469 }
6470 }
6471 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006472 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006473
Brad Ebinger51f743a2017-01-23 13:50:20 -08006474 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006475 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6476 * {@link #disableIms(int)}.
6477 * @param slotIndex device slot.
6478 */
6479 public void resetIms(int slotIndex) {
6480 enforceModifyPermission();
6481
joonhunshin4ac60942023-11-15 15:23:39 +00006482 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6483 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6484
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006485 final long identity = Binder.clearCallingIdentity();
6486 try {
6487 if (mImsResolver == null) {
6488 // may happen if the does not support IMS.
6489 return;
6490 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006491 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006492 } finally {
6493 Binder.restoreCallingIdentity(identity);
6494 }
6495 }
6496
6497 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006498 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6499 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006500 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006501 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006502 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006503
6504 final long identity = Binder.clearCallingIdentity();
6505 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006506 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006507 // may happen if the device does not support IMS.
6508 return;
6509 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006510 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006511 } finally {
6512 Binder.restoreCallingIdentity(identity);
6513 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006514 }
6515
6516 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006517 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6518 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006519 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006520 public void disableIms(int slotId) {
6521 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522
6523 final long identity = Binder.clearCallingIdentity();
6524 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006525 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006526 // may happen if the device does not support IMS.
6527 return;
6528 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006529 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530 } finally {
6531 Binder.restoreCallingIdentity(identity);
6532 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006533 }
6534
6535 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006536 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6537 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006538 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006539 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006540 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542
6543 final long identity = Binder.clearCallingIdentity();
6544 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006545 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006546 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6547 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006548 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006549 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550 } finally {
6551 Binder.restoreCallingIdentity(identity);
6552 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006553 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006554 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006555 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6556 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006557 @Override
6558 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006559 enforceModifyPermission();
6560
6561 final long identity = Binder.clearCallingIdentity();
6562 try {
6563 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006564 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006565 } finally {
6566 Binder.restoreCallingIdentity(identity);
6567 }
6568 }
6569
6570 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006571 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006572 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006573 */
6574 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576
6577 final long identity = Binder.clearCallingIdentity();
6578 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006579 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006580 // may happen if the device does not support IMS.
6581 return null;
6582 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006583 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584 } finally {
6585 Binder.restoreCallingIdentity(identity);
6586 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006587 }
6588
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006589 /**
6590 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006591 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006592 */
6593 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6594 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006595
6596 final long identity = Binder.clearCallingIdentity();
6597 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006598 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006599 // may happen if the device does not support IMS.
6600 return null;
6601 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006602 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603 } finally {
6604 Binder.restoreCallingIdentity(identity);
6605 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006606 }
6607
Brad Ebinger884c07b2018-02-15 16:17:40 -08006608 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006609 * Sets the ImsService Package Name that Telephony will bind to.
6610 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006611 * @param slotIndex the slot ID that the ImsService should bind for.
6612 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006613 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006614 * @param featureTypes An integer array of feature types associated with a packageName.
6615 * @param packageName The name of the package that the current configuration will be replaced
6616 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006617 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006618 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006619 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6620 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006621 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006623 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625 final long identity = Binder.clearCallingIdentity();
6626 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006627 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006628 // may happen if the device does not support IMS.
6629 return false;
6630 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006631 Map<Integer, String> featureConfig = new HashMap<>();
6632 for (int featureType : featureTypes) {
6633 featureConfig.put(featureType, packageName);
6634 }
6635 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6636 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637 } finally {
6638 Binder.restoreCallingIdentity(identity);
6639 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006640 }
6641
6642 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006643 * Clears any carrier ImsService overrides for the slot index specified that were previously
6644 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6645 *
6646 * This should only be used for testing.
6647 *
6648 * @param slotIndex the slot ID that the ImsService should bind for.
6649 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6650 */
6651 @Override
6652 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006653 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6654 "clearCarrierImsServiceOverride");
6655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006656 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006657
6658 final long identity = Binder.clearCallingIdentity();
6659 try {
6660 if (mImsResolver == null) {
6661 // may happen if the device does not support IMS.
6662 return false;
6663 }
6664 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6665 } finally {
6666 Binder.restoreCallingIdentity(identity);
6667 }
6668 }
6669
6670 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006671 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006672 *
6673 * @param slotId The slot that the ImsService is associated with.
6674 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6675 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006676 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006677 * @return the package name of the ImsService configuration.
6678 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006679 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6680 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006681 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006682 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6683 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 final long identity = Binder.clearCallingIdentity();
6686 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006687 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006688 // may happen if the device does not support IMS.
6689 return "";
6690 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006691 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006692 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6693 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 } finally {
6695 Binder.restoreCallingIdentity(identity);
6696 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006697 }
6698
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006699 /**
6700 * Get the MmTelFeature state associated with the requested subscription id.
6701 * @param subId The subscription that the MmTelFeature is associated with.
6702 * @param callback A callback with an integer containing the
6703 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6704 */
6705 @Override
6706 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6707 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006708 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6709 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6710 "IMS not available on device.");
6711 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006712 final long token = Binder.clearCallingIdentity();
6713 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006714 int slotId = getSlotIndex(subId);
6715 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6716 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6717 + subId + "'");
6718 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6719 }
6720 verifyImsMmTelConfiguredOrThrow(slotId);
6721 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6722 try {
6723 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6724 } catch (RemoteException e) {
6725 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6726 + "Ignore");
6727 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006728 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006729 } catch (ImsException e) {
6730 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006731 } finally {
6732 Binder.restoreCallingIdentity(token);
6733 }
6734 }
6735
Daniel Brightbb5840b2021-01-12 15:48:18 -08006736 /**
6737 * Sets the ims registration state on all valid {@link Phone}s.
6738 */
6739 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006740 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741
6742 final long identity = Binder.clearCallingIdentity();
6743 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006744 // NOTE: Before S, this method only set the default phone.
6745 for (final Phone phone : PhoneFactory.getPhones()) {
6746 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6747 phone.setImsRegistrationState(registered);
6748 }
6749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
Wink Saville36469e72014-06-11 15:17:00 -07006753 }
6754
6755 /**
Stuart Scott54788802015-03-30 13:18:01 -07006756 * Set the network selection mode to automatic.
6757 *
6758 */
6759 @Override
6760 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6762 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763
joonhunshin4ac60942023-11-15 15:23:39 +00006764 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6765 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 final long identity = Binder.clearCallingIdentity();
6768 try {
shilufc958392020-01-20 11:36:01 -08006769 if (!isActiveSubscription(subId)) {
6770 return;
6771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006773 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6774 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 } finally {
6776 Binder.restoreCallingIdentity(identity);
6777 }
Stuart Scott54788802015-03-30 13:18:01 -07006778 }
6779
Jack Yud10cdd42020-09-28 20:28:01 -07006780 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006781 * Ask the radio to connect to the input network and change selection mode to manual.
6782 *
6783 * @param subId the id of the subscription.
6784 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6785 * the operator to attach to.
6786 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6787 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6788 * normal network selection next time.
6789 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006790 */
6791 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006792 public boolean setNetworkSelectionModeManual(
6793 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6795 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006796
joonhunshin4ac60942023-11-15 15:23:39 +00006797 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6798 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6799
Jack Yu285100e2022-12-02 22:48:35 -08006800 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006801 if (!isActiveSubscription(subId)) {
6802 return false;
6803 }
6804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006806 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006807 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006808 if (DBG) {
6809 log("setNetworkSelectionModeManual: subId: " + subId
6810 + " operator: " + operatorInfo);
6811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006812 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6813 } finally {
6814 Binder.restoreCallingIdentity(identity);
6815 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006816 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006817 /**
shilu84f6e8b2019-12-19 13:58:01 -08006818 * Get the manual network selection
6819 *
6820 * @param subId the id of the subscription.
6821 *
6822 * @return the previously saved user selected PLMN
6823 */
6824 @Override
6825 public String getManualNetworkSelectionPlmn(int subId) {
6826 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006827 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6828 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006829
joonhunshin4ac60942023-11-15 15:23:39 +00006830 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6831 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6832
shilu84f6e8b2019-12-19 13:58:01 -08006833 final long identity = Binder.clearCallingIdentity();
6834 try {
6835 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006836 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006837 }
6838
6839 final Phone phone = getPhone(subId);
6840 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006841 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006842 }
6843 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6844 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006845 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006846 } finally {
6847 Binder.restoreCallingIdentity(identity);
6848 }
6849 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006850
6851 /**
6852 * Scans for available networks.
6853 */
6854 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006855 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6856 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6858 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006859 LocationAccessPolicy.LocationPermissionResult locationResult =
6860 LocationAccessPolicy.checkLocationPermission(mApp,
6861 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6862 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006863 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006864 .setCallingPid(Binder.getCallingPid())
6865 .setCallingUid(Binder.getCallingUid())
6866 .setMethod("getCellNetworkScanResults")
6867 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006868 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6869 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006870 .build());
6871 switch (locationResult) {
6872 case DENIED_HARD:
6873 throw new SecurityException("Not allowed to access scan results -- location");
6874 case DENIED_SOFT:
6875 return null;
6876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006877
Pengquan Menga1bb6272018-09-06 09:59:22 -07006878 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879 try {
6880 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006881 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883 } finally {
6884 Binder.restoreCallingIdentity(identity);
6885 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006886 }
6887
6888 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006889 * Get the call forwarding info, given the call forwarding reason.
6890 */
6891 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006892 public void getCallForwarding(int subId, int callForwardingReason,
6893 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006894 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006895
6896 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6897 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6898
Shuo Qian4a594052020-01-23 11:59:30 -08006899 long identity = Binder.clearCallingIdentity();
6900 try {
6901 if (DBG) {
6902 log("getCallForwarding: subId " + subId
6903 + " callForwardingReason" + callForwardingReason);
6904 }
Hall Liu27d24262020-09-18 19:04:59 -07006905
6906 Phone phone = getPhone(subId);
6907 if (phone == null) {
6908 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006909 callback.onError(
6910 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006911 } catch (RemoteException e) {
6912 // ignore
6913 }
6914 return;
6915 }
6916
6917 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6918 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6919 @Override
6920 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6921 try {
6922 callback.onCallForwardingInfoAvailable(info);
6923 } catch (RemoteException e) {
6924 // ignore
6925 }
6926 }
6927
6928 @Override
6929 public void onError(int error) {
6930 try {
6931 callback.onError(error);
6932 } catch (RemoteException e) {
6933 // ignore
6934 }
6935 }
6936 });
6937 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006938 } finally {
6939 Binder.restoreCallingIdentity(identity);
6940 }
6941 }
6942
6943 /**
6944 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6945 * reason, the number to forward, and the timeout before the forwarding is attempted.
6946 */
6947 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006948 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6949 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006950 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006951
6952 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6953 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6954
Shuo Qian4a594052020-01-23 11:59:30 -08006955 long identity = Binder.clearCallingIdentity();
6956 try {
6957 if (DBG) {
6958 log("setCallForwarding: subId " + subId
6959 + " callForwardingInfo" + callForwardingInfo);
6960 }
Hall Liu27d24262020-09-18 19:04:59 -07006961
6962 Phone phone = getPhone(subId);
6963 if (phone == null) {
6964 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006965 callback.accept(
6966 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006967 } catch (RemoteException e) {
6968 // ignore
6969 }
6970 return;
6971 }
6972
6973 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6974 FunctionalUtils.ignoreRemoteException(callback::accept));
6975
6976 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006977 } finally {
6978 Binder.restoreCallingIdentity(identity);
6979 }
6980 }
6981
6982 /**
Hall Liu27d24262020-09-18 19:04:59 -07006983 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006984 */
6985 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006986 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006987 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006988
6989 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6990 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6991
Shuo Qian4a594052020-01-23 11:59:30 -08006992 long identity = Binder.clearCallingIdentity();
6993 try {
Hall Liu27d24262020-09-18 19:04:59 -07006994 Phone phone = getPhone(subId);
6995 if (phone == null) {
6996 try {
6997 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6998 } catch (RemoteException e) {
6999 // ignore
7000 }
7001 return;
7002 }
SongFerngWang0e767992021-03-31 22:08:45 +08007003 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7004 PersistableBundle c = configManager.getConfigForSubId(subId);
7005 boolean requireUssd = c.getBoolean(
7006 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007007
Shuo Qian4a594052020-01-23 11:59:30 -08007008 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007009 if (requireUssd) {
7010 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7011 getSubscriptionCarrierId(subId));
7012 String newUssdCommand = "";
7013 try {
7014 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007015 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007016 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7017 } catch (NullPointerException e) {
7018 loge("Failed to generate USSD number" + e);
7019 }
7020 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7021 mMainThreadHandler, callback, carrierXmlParser,
7022 CarrierXmlParser.SsEntry.SSAction.QUERY);
7023 final String ussdCommand = newUssdCommand;
7024 Executors.newSingleThreadExecutor().execute(() -> {
7025 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7026 });
7027 } else {
7028 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7029 callback::accept);
7030 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7031 }
Shuo Qian4a594052020-01-23 11:59:30 -08007032 } finally {
7033 Binder.restoreCallingIdentity(identity);
7034 }
7035 }
7036
7037 /**
Hall Liu27d24262020-09-18 19:04:59 -07007038 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007039 */
7040 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007041 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007042 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007043
7044 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7045 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7046
Shuo Qian4a594052020-01-23 11:59:30 -08007047 long identity = Binder.clearCallingIdentity();
7048 try {
Hall Liu27d24262020-09-18 19:04:59 -07007049 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7050
7051 Phone phone = getPhone(subId);
7052 if (phone == null) {
7053 try {
7054 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7055 } catch (RemoteException e) {
7056 // ignore
7057 }
7058 return;
7059 }
7060
SongFerngWang0e767992021-03-31 22:08:45 +08007061 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7062 PersistableBundle c = configManager.getConfigForSubId(subId);
7063 boolean requireUssd = c.getBoolean(
7064 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007065
SongFerngWang0e767992021-03-31 22:08:45 +08007066 if (DBG) log("getCallWaitingStatus: subId " + subId);
7067 if (requireUssd) {
7068 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7069 getSubscriptionCarrierId(subId));
7070 CarrierXmlParser.SsEntry.SSAction ssAction =
7071 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7072 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7073 String newUssdCommand = "";
7074 try {
7075 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007076 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007077 .makeCommand(ssAction, null);
7078 } catch (NullPointerException e) {
7079 loge("Failed to generate USSD number" + e);
7080 }
7081 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7082 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7083 final String ussdCommand = newUssdCommand;
7084 Executors.newSingleThreadExecutor().execute(() -> {
7085 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7086 });
7087 } else {
7088 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7089 FunctionalUtils.ignoreRemoteException(callback::accept));
7090
7091 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7092 }
Shuo Qian4a594052020-01-23 11:59:30 -08007093 } finally {
7094 Binder.restoreCallingIdentity(identity);
7095 }
7096 }
7097
7098 /**
yinxub1bed742017-04-17 11:45:04 -07007099 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007100 *
yinxub1bed742017-04-17 11:45:04 -07007101 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007102 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7103 * location related information which will be sent if the caller already possess
7104 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007105 * @param request contains the radio access networks with bands/channels to scan
7106 * @param messenger callback messenger for scan results or errors
7107 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007108 * @return the id of the requested scan which can be used to stop the scan.
7109 */
7110 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007111 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7112 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007113 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7115 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007116 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007117 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7118 if (!renounceFineLocationAccess) {
7119 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007120 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7121 .setCallingPackage(callingPackage)
7122 .setCallingFeatureId(callingFeatureId)
7123 .setCallingPid(Binder.getCallingPid())
7124 .setCallingUid(Binder.getCallingUid())
7125 .setMethod("requestNetworkScan")
7126 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7127 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7128 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7129 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007130 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007131 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007132 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7133 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007134 if (e != null) {
7135 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7136 throw e;
7137 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007138 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007139 return TelephonyScanManager.INVALID_SCAN_ID;
7140 }
7141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142 }
joonhunshin4ac60942023-11-15 15:23:39 +00007143
7144 enforceTelephonyFeatureWithException(callingPackage,
7145 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7146
Hall Liu912dfd32019-04-25 14:02:26 -07007147 int callingUid = Binder.getCallingUid();
7148 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007149 final long identity = Binder.clearCallingIdentity();
7150 try {
7151 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007152 renounceFineLocationAccess, request, messenger, binder,
7153 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007154 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007155 } finally {
7156 Binder.restoreCallingIdentity(identity);
7157 }
yinxu504e1392017-04-12 16:03:22 -07007158 }
7159
Hall Liub2ac8ef2019-02-28 15:56:23 -08007160 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007161 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007162 boolean hasCarrierPriv;
7163 final long identity = Binder.clearCallingIdentity();
7164 try {
7165 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7166 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7167 } finally {
7168 Binder.restoreCallingIdentity(identity);
7169 }
Hall Liu558027f2019-05-15 19:14:05 -07007170 boolean hasNetworkScanPermission =
7171 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007172 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007173
7174 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7175 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7176 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007177 }
7178
7179 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7180 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007181 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7182 return new SecurityException("Specific channels must not be"
7183 + " scanned without location access.");
7184 }
7185 }
7186 }
7187
Hall Liub2ac8ef2019-02-28 15:56:23 -08007188 return null;
7189 }
7190
yinxu504e1392017-04-12 16:03:22 -07007191 /**
7192 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007193 *
7194 * @param subId id of the subscription
7195 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007196 */
7197 @Override
7198 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7200 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201
Hall Liu912dfd32019-04-25 14:02:26 -07007202 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 final long identity = Binder.clearCallingIdentity();
7204 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007205 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
yinxu504e1392017-04-12 16:03:22 -07007209 }
7210
7211 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007212 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007213 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007214 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007215 */
7216 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007217 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007218 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007219 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007220 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007221
joonhunshin4ac60942023-11-15 15:23:39 +00007222 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7223 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225 final long identity = Binder.clearCallingIdentity();
7226 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007227 if (DBG) log("getAllowedNetworkTypesBitmask");
7228 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7229 int networkTypesBitmask = (result != null ? result[0] : -1);
7230 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7231 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232 } finally {
7233 Binder.restoreCallingIdentity(identity);
7234 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007235 }
7236
7237 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007238 * Get the allowed network types for certain reason.
7239 *
7240 * @param subId the id of the subscription.
7241 * @param reason the reason the allowed network type change is taking place
7242 * @return the allowed network types.
7243 */
7244 @Override
7245 public long getAllowedNetworkTypesForReason(int subId,
7246 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007247 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007248 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007249
7250 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7251 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7252
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007253 final long identity = Binder.clearCallingIdentity();
7254 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007255 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007256 } finally {
7257 Binder.restoreCallingIdentity(identity);
7258 }
7259 }
7260
7261 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007262 * Enable/Disable E-UTRA-NR Dual Connectivity
7263 * @param subId subscription id of the sim card
7264 * @param nrDualConnectivityState expected NR dual connectivity state
7265 * This can be passed following states
7266 * <ol>
7267 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7268 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7269 * <li>Disable NR dual connectivity and force secondary cell to be released
7270 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7271 * </ol>
7272 * @return operation result.
7273 */
7274 @Override
7275 public int setNrDualConnectivityState(int subId,
7276 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7278 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007279 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007280 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7281 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7282 }
7283
Sooraj Sasindran37444802020-08-11 10:40:43 -07007284 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7285 final long identity = Binder.clearCallingIdentity();
7286 try {
7287 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7288 nrDualConnectivityState, subId,
7289 workSource);
7290 if (DBG) log("enableNRDualConnectivity result: " + result);
7291 return result;
7292 } finally {
7293 Binder.restoreCallingIdentity(identity);
7294 }
7295 }
7296
7297 /**
7298 * Is E-UTRA-NR Dual Connectivity enabled
7299 * @return true if dual connectivity is enabled else false
7300 */
7301 @Override
7302 public boolean isNrDualConnectivityEnabled(int subId) {
7303 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007304 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007305 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007306 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007307 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7308 return false;
7309 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007310 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7311 final long identity = Binder.clearCallingIdentity();
7312 try {
7313 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7314 null, subId, workSource);
7315 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7316 return isEnabled;
7317 } finally {
7318 Binder.restoreCallingIdentity(identity);
7319 }
7320 }
7321
7322 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007323 * Set the allowed network types of the device and
7324 * provide the reason triggering the allowed network change.
7325 *
7326 * @param subId the id of the subscription.
7327 * @param reason the reason the allowed network type change is taking place
7328 * @param allowedNetworkTypes the allowed network types.
7329 * @return true on success; false on any failure.
7330 */
7331 @Override
7332 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007333 @TelephonyManager.AllowedNetworkTypesReason int reason,
7334 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7336 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007337 // If the caller only has carrier privileges, then they should not be able to override
7338 // any network types which were set for security reasons.
7339 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7340 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007341 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007342 throw new SecurityException(
7343 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007344 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007345 }
joonhunshin4ac60942023-11-15 15:23:39 +00007346
7347 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7348 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7349
SongFerngWang3ef3e072020-12-21 16:41:52 +08007350 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007351 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007352 return false;
7353 }
7354 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7355 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007356 return false;
7357 }
7358
Jack Yu5b494332023-01-23 18:18:04 +00007359 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7360 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007361
Jack Yue37dd262022-12-16 11:53:37 -08007362 Phone phone = getPhone(subId);
7363 if (phone == null) {
7364 return false;
7365 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007366
Jack Yue37dd262022-12-16 11:53:37 -08007367 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007368 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007369 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007370 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007371
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007372 final long identity = Binder.clearCallingIdentity();
7373 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007374 Boolean success = (Boolean) sendRequest(
7375 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7376 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7377
7378 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7379 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007380 } finally {
7381 Binder.restoreCallingIdentity(identity);
7382 }
7383 }
7384
7385 /**
Miaoa84611c2019-03-15 09:21:10 +08007386 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007387 *
Miaoa84611c2019-03-15 09:21:10 +08007388 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007389 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007390 * @hide
7391 */
7392 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007393 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007394 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007395
7396 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7397 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007399 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007400 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007401 try {
Miaoa84611c2019-03-15 09:21:10 +08007402 if (phone != null) {
7403 return phone.hasMatchedTetherApnSetting();
7404 } else {
7405 return false;
7406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 } finally {
7408 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007409 }
Junda Liu475951f2014-11-07 16:45:03 -08007410 }
7411
7412 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007413 * Get the user enabled state of Mobile Data.
7414 *
7415 * TODO: remove and use isUserDataEnabled.
7416 * This can't be removed now because some vendor codes
7417 * calls through ITelephony directly while they should
7418 * use TelephonyManager.
7419 *
7420 * @return true on enabled
7421 */
7422 @Override
7423 public boolean getDataEnabled(int subId) {
7424 return isUserDataEnabled(subId);
7425 }
7426
7427 /**
7428 * Get whether mobile data is enabled per user setting.
7429 *
7430 * There are other factors deciding whether mobile data is actually enabled, but they are
7431 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007432 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007433 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7434 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007435 *
7436 * @return {@code true} if data is enabled else {@code false}
7437 */
7438 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007439 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007440 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007441 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007442 try {
7443 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7444 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007445 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007446 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7447 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007448 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007450 mApp, subId, functionName);
7451
Robert Greenwalt646120a2014-05-23 11:54:03 -07007452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453
7454 final long identity = Binder.clearCallingIdentity();
7455 try {
Jack Yu285100e2022-12-02 22:48:35 -08007456 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7458 Phone phone = PhoneFactory.getPhone(phoneId);
7459 if (phone != null) {
7460 boolean retVal = phone.isUserDataEnabled();
7461 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7462 return retVal;
7463 } else {
7464 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7465 return false;
7466 }
7467 } finally {
7468 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007469 }
7470 }
7471
7472 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007473 * Checks if the device is capable of mobile data by considering whether whether the
7474 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7475 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007476 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007477 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007478 */
7479 @Override
7480 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007481 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007482 try {
7483 try {
7484 mApp.enforceCallingOrSelfPermission(
7485 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007486 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007487 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007488 try {
7489 mApp.enforceCallingOrSelfPermission(
7490 android.Manifest.permission.READ_PHONE_STATE,
7491 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007492 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007493 mApp.enforceCallingOrSelfPermission(
7494 permission.READ_BASIC_PHONE_STATE, functionName);
7495 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007496 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007497 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007498 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500
joonhunshin4ac60942023-11-15 15:23:39 +00007501 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7502 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 final long identity = Binder.clearCallingIdentity();
7505 try {
Jack Yu285100e2022-12-02 22:48:35 -08007506 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 Phone phone = PhoneFactory.getPhone(phoneId);
7508 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007509 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007510 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 return retVal;
7512 } else {
7513 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7514 return false;
7515 }
7516 } finally {
7517 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007518 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007519 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007520
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007521 /**
7522 * Check if data is enabled for a specific reason
7523 * @param subId Subscription index
7524 * @param reason the reason the data enable change is taking place
7525 * @return {@code true} if the overall data is enabled; {@code false} if not.
7526 */
7527 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007528 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007529 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007530 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007531 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007532 try {
7533 mApp.enforceCallingOrSelfPermission(
7534 android.Manifest.permission.ACCESS_NETWORK_STATE,
7535 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007536 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007537 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7538 functionName);
7539 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007540 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007541 try {
7542 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007543 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007544 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007546 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007547 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007548 }
7549
joonhunshin4ac60942023-11-15 15:23:39 +00007550 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7551 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007552
7553 final long identity = Binder.clearCallingIdentity();
7554 try {
Jack Yu285100e2022-12-02 22:48:35 -08007555 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007556 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007557 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007558 + " reason=" + reason);
7559 }
7560 Phone phone = PhoneFactory.getPhone(phoneId);
7561 if (phone != null) {
7562 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007563 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007564 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007565 return retVal;
7566 } else {
7567 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007568 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007569 + subId + " retVal=false");
7570 }
7571 return false;
7572 }
7573 } finally {
7574 Binder.restoreCallingIdentity(identity);
7575 }
7576 }
7577
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007578 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007579 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007580 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7581 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7582
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007583 // No permission needed; this only lets the caller inspect their own status.
7584 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007585 }
Junda Liu29340342014-07-10 15:23:27 -07007586
7587 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007588 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007589 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007590
7591 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7592 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7593
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007594 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7595 }
7596
7597 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7598 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007599 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007600 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007601 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7602 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007603 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7604 if (cpt == null) {
7605 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007606 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7607 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007608 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007609 }
7610
7611 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007612 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007613 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007614
7615 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7616 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7617
chen xuf7e9fe82019-05-09 19:31:02 -07007618 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007619 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007620 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007621 Phone phone = getPhone(subId);
7622 if (phone == null) {
7623 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7624 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7625 }
7626 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7627 if (cpt == null) {
7628 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007629 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7630 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007631 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007632 }
7633
7634 @Override
7635 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007636 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007637
7638 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7639 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7640 "checkCarrierPrivilegesForPackageAnyPhone");
7641
Rambo Wange7209ce2022-02-23 13:41:02 -08007642 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7643 }
7644
7645 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007646 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007647 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007648 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007649 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007650 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7651 Phone phone = PhoneFactory.getPhone(phoneId);
7652 if (phone == null) {
7653 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007654 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007655 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7656 if (cpt == null) {
7657 continue;
7658 }
7659 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007660 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7661 break;
7662 }
7663 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007664 return result;
Junda Liu29340342014-07-10 15:23:27 -07007665 }
Derek Tan89e89d42014-07-08 17:00:10 -07007666
7667 @Override
Junda Liue64de782015-04-16 17:19:16 -07007668 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007669 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007670
7671 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7672 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7673 "getCarrierPackageNamesForIntentAndPhone");
7674
Rambo Wang8a247eb2022-02-08 21:11:18 +00007675 Phone phone = PhoneFactory.getPhone(phoneId);
7676 if (phone == null) {
7677 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007678 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007679 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7680 if (cpt == null) {
7681 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007682 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007683 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007684 }
7685
Amith Yamasani6e118872016-02-19 12:53:51 -08007686 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007687 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007688 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007689 Phone phone = PhoneFactory.getPhone(phoneId);
7690 if (phone == null) {
7691 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007692 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007693 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7694 if (cpt == null) {
7695 return Collections.emptyList();
7696 }
7697 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007698 }
7699
chen xuf7e9fe82019-05-09 19:31:02 -07007700 @Override
7701 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007702 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007703
7704 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7705 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7706 "getPackagesWithCarrierPrivilegesForAllPhones");
7707
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007708 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007709 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007710 try {
7711 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7712 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7713 }
7714 } finally {
7715 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007716 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007717 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007718 }
7719
Rambo Wang6812ffb2022-03-15 16:54:17 -07007720 @Override
7721 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7722 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7723
joonhunshin4ac60942023-11-15 15:23:39 +00007724 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7725 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7726 "getCarrierServicePackageNameForLogicalSlot");
7727
Rambo Wang6812ffb2022-03-15 16:54:17 -07007728 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7729 if (phone == null) {
7730 return null;
7731 }
7732 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7733 if (cpt == null) {
7734 return null;
7735 }
7736 return cpt.getCarrierServicePackageName();
7737 }
7738
Wink Savilleb564aae2014-10-23 10:18:09 -07007739 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007740 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007741 UiccPort port = phone == null ? null : phone.getUiccPort();
7742 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007743 return null;
7744 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007745 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007746 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007747 return null;
7748 }
7749 return iccId;
7750 }
7751
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007752 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007753 public void setCallComposerStatus(int subId, int status) {
7754 enforceModifyPermission();
7755
joonhunshin4ac60942023-11-15 15:23:39 +00007756 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7757 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7758
Shuo Qiane4e11672020-12-15 22:15:33 -08007759 final long identity = Binder.clearCallingIdentity();
7760 try {
7761 Phone phone = getPhone(subId);
7762 if (phone != null) {
7763 Phone defaultPhone = phone.getImsPhone();
7764 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7765 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7766 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007767 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7768 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007769 }
7770 }
Shuo Qian284ae752020-12-22 19:10:14 -08007771 } catch (ImsException e) {
7772 throw new ServiceSpecificException(e.getCode());
7773 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007774 Binder.restoreCallingIdentity(identity);
7775 }
7776 }
7777
7778 @Override
7779 public int getCallComposerStatus(int subId) {
7780 enforceReadPrivilegedPermission("getCallComposerStatus");
7781
joonhunshin4ac60942023-11-15 15:23:39 +00007782 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7783 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7784
Shuo Qiane4e11672020-12-15 22:15:33 -08007785 final long identity = Binder.clearCallingIdentity();
7786 try {
7787 Phone phone = getPhone(subId);
7788 if (phone != null) {
7789 Phone defaultPhone = phone.getImsPhone();
7790 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7791 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7792 return imsPhone.getCallComposerStatus();
7793 }
7794 }
7795 } finally {
7796 Binder.restoreCallingIdentity(identity);
7797 }
7798 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7799 }
7800
7801 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007802 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7803 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007804 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007805 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007806
joonhunshin4ac60942023-11-15 15:23:39 +00007807 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7808 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7809 "setLine1NumberForDisplayForSubscriber");
7810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007811 final long identity = Binder.clearCallingIdentity();
7812 try {
7813 final String iccId = getIccId(subId);
7814 final Phone phone = getPhone(subId);
7815 if (phone == null) {
7816 return false;
7817 }
7818 final String subscriberId = phone.getSubscriberId();
7819
7820 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007821 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 + subscriberId + " to " + number);
7823 }
7824
7825 if (TextUtils.isEmpty(iccId)) {
7826 return false;
7827 }
7828
7829 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7830
7831 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7832 if (alphaTag == null) {
7833 editor.remove(alphaTagPrefKey);
7834 } else {
7835 editor.putString(alphaTagPrefKey, alphaTag);
7836 }
7837
7838 // Record both the line number and IMSI for this ICCID, since we need to
7839 // track all merged IMSIs based on line number
7840 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7841 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7842 if (number == null) {
7843 editor.remove(numberPrefKey);
7844 editor.remove(subscriberPrefKey);
7845 } else {
7846 editor.putString(numberPrefKey, number);
7847 editor.putString(subscriberPrefKey, subscriberId);
7848 }
7849
7850 editor.commit();
7851 return true;
7852 } finally {
7853 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007854 }
Derek Tan7226c842014-07-02 17:42:23 -07007855 }
7856
7857 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007858 public String getLine1NumberForDisplay(int subId, String callingPackage,
7859 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007860 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007862 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007863 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007864 return null;
7865 }
Derek Tan97ebb422014-09-05 16:55:38 -07007866
joonhunshin4ac60942023-11-15 15:23:39 +00007867 enforceTelephonyFeatureWithException(callingPackage,
7868 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007870 final long identity = Binder.clearCallingIdentity();
7871 try {
7872 String iccId = getIccId(subId);
7873 if (iccId != null) {
7874 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7875 if (DBG_MERGE) {
7876 log("getLine1NumberForDisplay returning "
7877 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7878 }
7879 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007881 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7882 return null;
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007885 }
Derek Tan7226c842014-07-02 17:42:23 -07007886 }
7887
7888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007889 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7890 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007892 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007893 return null;
7894 }
Derek Tan97ebb422014-09-05 16:55:38 -07007895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 final long identity = Binder.clearCallingIdentity();
7897 try {
7898 String iccId = getIccId(subId);
7899 if (iccId != null) {
7900 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7901 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7902 }
7903 return null;
7904 } finally {
7905 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007906 }
Derek Tan7226c842014-07-02 17:42:23 -07007907 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007908
7909 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007910 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7911 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007912 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7913 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007915 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007916 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007917 return null;
7918 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007919
Jordan Liub49b04b2019-05-06 14:45:15 -07007920 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7921 // the process, where TelephonyManager was instantiated.
7922 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007923 final long identity = Binder.clearCallingIdentity();
7924 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007925 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 final TelephonyManager tele = TelephonyManager.from(context);
7927 final SubscriptionManager sub = SubscriptionManager.from(context);
7928
7929 // Figure out what subscribers are currently active
7930 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931
Jordan Liub49b04b2019-05-06 14:45:15 -07007932 // Only consider subs which match the current subId
7933 // This logic can be simplified. See b/131189269 for progress.
7934 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007935 activeSubscriberIds.add(tele.getSubscriberId(subId));
7936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937
7938 // First pass, find a number override for an active subscriber
7939 String mergeNumber = null;
7940 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7941 for (String key : prefs.keySet()) {
7942 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7943 final String subscriberId = (String) prefs.get(key);
7944 if (activeSubscriberIds.contains(subscriberId)) {
7945 final String iccId = key.substring(
7946 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7947 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7948 mergeNumber = (String) prefs.get(numberKey);
7949 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007950 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951 + " for active subscriber " + subscriberId);
7952 }
7953 if (!TextUtils.isEmpty(mergeNumber)) {
7954 break;
7955 }
7956 }
7957 }
7958 }
7959
7960 // Shortcut when no active merged subscribers
7961 if (TextUtils.isEmpty(mergeNumber)) {
7962 return null;
7963 }
7964
7965 // Second pass, find all subscribers under that line override
7966 final ArraySet<String> result = new ArraySet<>();
7967 for (String key : prefs.keySet()) {
7968 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7969 final String number = (String) prefs.get(key);
7970 if (mergeNumber.equals(number)) {
7971 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7972 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7973 final String subscriberId = (String) prefs.get(subscriberKey);
7974 if (!TextUtils.isEmpty(subscriberId)) {
7975 result.add(subscriberId);
7976 }
7977 }
7978 }
7979 }
7980
7981 final String[] resultArray = result.toArray(new String[result.size()]);
7982 Arrays.sort(resultArray);
7983 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007984 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7986 }
7987 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007988 } finally {
7989 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007990 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007991 }
7992
7993 @Override
zoey chen38003472019-12-13 17:16:31 +08007994 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7995 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007996
joonhunshin4ac60942023-11-15 15:23:39 +00007997 enforceTelephonyFeatureWithException(callingPackage,
7998 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7999
Malcolm Chen6ca97372019-07-01 16:28:21 -07008000 final long identity = Binder.clearCallingIdentity();
8001 try {
8002 final TelephonyManager telephonyManager = mApp.getSystemService(
8003 TelephonyManager.class);
8004 String subscriberId = telephonyManager.getSubscriberId(subId);
8005 if (subscriberId == null) {
8006 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008007 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008008 + subId);
8009 }
8010 return null;
8011 }
8012
Jack Yu3beaf9d2023-04-14 09:17:27 -07008013 final SubscriptionInfo info = getSubscriptionManagerService()
8014 .getSubscriptionInfo(subId);
8015 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008016 // If it doesn't belong to any group, return just subscriberId of itself.
8017 if (groupUuid == null) {
8018 return new String[]{subscriberId};
8019 }
8020
8021 // Get all subscriberIds from the group.
8022 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008023 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8024 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8025 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008026 for (SubscriptionInfo subInfo : groupInfos) {
8027 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8028 if (subscriberId != null) {
8029 mergedSubscriberIds.add(subscriberId);
8030 }
8031 }
8032
8033 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8034 } finally {
8035 Binder.restoreCallingIdentity(identity);
8036
8037 }
8038 }
8039
8040 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008041 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008042 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008043 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008044
joonhunshin4ac60942023-11-15 15:23:39 +00008045 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8046 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008048 final long identity = Binder.clearCallingIdentity();
8049 try {
8050 final Phone phone = getPhone(subId);
8051 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8052 } finally {
8053 Binder.restoreCallingIdentity(identity);
8054 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008055 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008056
8057 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008058 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008059 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8060 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008061 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8062 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063
8064 final long identity = Binder.clearCallingIdentity();
8065 try {
8066 final Phone phone = getPhone(subId);
8067 if (phone == null) {
8068 return false;
8069 }
8070 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8071 cdmaNonRoamingList);
8072 } finally {
8073 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008074 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008075 }
8076
8077 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008078 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008079 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008080 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008081 if (phone == null) {
8082 return raf;
8083 }
8084
Shuo Qiandee53402020-05-29 14:08:15 -07008085 try {
8086 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008087 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008088 mApp, phone.getSubId(), "getRadioAccessFamily");
8089 } catch (SecurityException e) {
8090 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8091 throw e;
8092 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008093
joonhunshin4ac60942023-11-15 15:23:39 +00008094 enforceTelephonyFeatureWithException(callingPackage,
8095 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 final long identity = Binder.clearCallingIdentity();
8098 try {
chen xub97461a2018-10-26 14:17:57 -07008099 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008100 } finally {
8101 Binder.restoreCallingIdentity(identity);
8102 }
chen xub97461a2018-10-26 14:17:57 -07008103 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008104 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008105
8106 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008107 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008108 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008109 try {
8110 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8111 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008112 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008113 }
8114 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008115 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008116 }
joonhunshin4ac60942023-11-15 15:23:39 +00008117
8118 enforceTelephonyFeatureWithException(callingPackage,
8119 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8120
Hall Liu82694d52020-12-11 18:22:04 -08008121 RoleManager rm = mApp.getSystemService(RoleManager.class);
8122 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8123 if (!dialerRoleHolders.contains(callingPackage)) {
8124 throw new SecurityException("App must be the dialer role holder to"
8125 + " upload a call composer pic");
8126 }
8127
8128 Executors.newSingleThreadExecutor().execute(() -> {
8129 ByteArrayOutputStream output = new ByteArrayOutputStream(
8130 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8131 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8132 boolean readUntilEnd = false;
8133 int totalBytesRead = 0;
8134 byte[] buffer = new byte[16 * 1024];
8135 while (true) {
8136 int numRead;
8137 try {
8138 numRead = input.read(buffer);
8139 } catch (IOException e) {
8140 try {
8141 fd.checkError();
8142 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8143 null);
8144 } catch (IOException e1) {
8145 // This means that the other side closed explicitly with an error. If this
8146 // happens, log and ignore.
8147 loge("Remote end of call composer picture pipe closed: " + e1);
8148 }
8149 break;
8150 }
8151 if (numRead == -1) {
8152 readUntilEnd = true;
8153 break;
8154 }
8155 totalBytesRead += numRead;
8156 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8157 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8158 try {
8159 input.close();
8160 } catch (IOException e) {
8161 // ignore
8162 }
8163 break;
8164 }
8165 output.write(buffer, 0, numRead);
8166 }
8167 // Generally, the remote end will close the file descriptors. The only case where we
8168 // close is above, where the picture size is too big.
8169
8170 try {
8171 fd.checkError();
8172 } catch (IOException e) {
8173 loge("Remote end for call composer closed with an error: " + e);
8174 return;
8175 }
8176
Hall Liuaa4211e2021-01-20 15:43:39 -08008177 if (!readUntilEnd) {
8178 loge("Did not finish reading entire image; aborting");
8179 return;
8180 }
Hall Liu82694d52020-12-11 18:22:04 -08008181
Hall Liuaa4211e2021-01-20 15:43:39 -08008182 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8183 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8184 new CallComposerPictureTransfer.Factory() {},
8185 imageData,
8186 (result) -> {
8187 if (result.first != null) {
8188 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8189 Bundle outputResult = new Bundle();
8190 outputResult.putParcelable(
8191 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8192 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8193 outputResult);
8194 } else {
8195 callback.send(result.second, null);
8196 }
8197 }
8198 );
Hall Liu82694d52020-12-11 18:22:04 -08008199 });
8200 }
8201
8202 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008203 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008204 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008205 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008206
joonhunshin4ac60942023-11-15 15:23:39 +00008207 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8208 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210 final long identity = Binder.clearCallingIdentity();
8211 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008212 ImsManager.getInstance(defaultPhone.getContext(),
8213 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 } finally {
8215 Binder.restoreCallingIdentity(identity);
8216 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008217 }
8218
8219 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008220 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008221 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8223 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008224 return false;
8225 }
Svet Ganovb320e182015-04-16 12:30:10 -07008226
joonhunshin4ac60942023-11-15 15:23:39 +00008227 enforceTelephonyFeatureWithException(callingPackage,
8228 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008230 final long identity = Binder.clearCallingIdentity();
8231 try {
8232 // Check the user preference and the system-level IMS setting. Even if the user has
8233 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8234 // In the long run, we may instead need to check if there exists a connection service
8235 // which can support video calling.
8236 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008237 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 return imsManager.isVtEnabledByPlatform()
8239 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8240 && imsManager.isVtEnabledByUser();
8241 } finally {
8242 Binder.restoreCallingIdentity(identity);
8243 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008244 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008245
Andrew Leea1239f22015-03-02 17:44:07 -08008246 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008247 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8248 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008250 mApp, subId, callingPackage, callingFeatureId,
8251 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008252 return false;
8253 }
8254
joonhunshin4ac60942023-11-15 15:23:39 +00008255 enforceTelephonyFeatureWithException(callingPackage,
8256 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 final long identity = Binder.clearCallingIdentity();
8259 try {
8260 CarrierConfigManager configManager =
8261 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008262 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008263 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8264 } finally {
8265 Binder.restoreCallingIdentity(identity);
8266 }
Andrew Leea1239f22015-03-02 17:44:07 -08008267 }
8268
8269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008270 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008272 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273 return false;
8274 }
8275
joonhunshin4ac60942023-11-15 15:23:39 +00008276 enforceTelephonyFeatureWithException(callingPackage,
8277 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8278
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 final long identity = Binder.clearCallingIdentity();
8280 try {
8281 CarrierConfigManager configManager =
8282 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008283 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008284 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8285 } finally {
8286 Binder.restoreCallingIdentity(identity);
8287 }
Andrew Leea1239f22015-03-02 17:44:07 -08008288 }
8289
Andrew Lee9431b832015-03-09 18:46:45 -07008290 @Override
8291 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008292 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008293 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008294 }
8295
8296 @Override
8297 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008298 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8299 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008301 final long identity = Binder.clearCallingIdentity();
8302 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008303 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304 } finally {
8305 Binder.restoreCallingIdentity(identity);
8306 }
Andrew Lee9431b832015-03-09 18:46:45 -07008307 }
8308
Hall Liuf6668912018-10-31 17:05:23 -07008309 /**
8310 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8311 * support for the feature and device firmware support.
8312 *
8313 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8314 */
8315 @Override
8316 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008317 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8318 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8319
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008320 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008321 final Phone phone = getPhone(subscriptionId);
8322 if (phone == null) {
8323 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8324 return false;
8325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008326 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008327 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008329 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8330 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8331 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008332 return isCarrierSupported && isDeviceSupported;
8333 } finally {
8334 Binder.restoreCallingIdentity(identity);
8335 }
Hall Liu98187582018-01-22 19:15:32 -08008336 }
8337
Hall Liuf6668912018-10-31 17:05:23 -07008338 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008339 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8340 * RTT setting, will return true if the device and carrier both support RTT.
8341 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008342 */
8343 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344 final long identity = Binder.clearCallingIdentity();
8345 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008346 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8347 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8348 return false;
8349 }
8350 }
8351
Hall Liu5bab75c2019-12-11 23:58:20 +00008352 boolean isRttSupported = isRttSupported(subscriptionId);
8353 boolean isUserRttSettingOn = Settings.Secure.getInt(
8354 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8355 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8356 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8357 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008358 } finally {
8359 Binder.restoreCallingIdentity(identity);
8360 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008361 }
8362
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008363 @Deprecated
8364 @Override
8365 public String getDeviceId(String callingPackage) {
8366 return getDeviceIdWithFeature(callingPackage, null);
8367 }
8368
Sanket Padawe7310cc72015-01-14 09:53:20 -08008369 /**
8370 * Returns the unique device ID of phone, for example, the IMEI for
8371 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8372 *
8373 * <p>Requires Permission:
8374 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8375 */
8376 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008377 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008378 try {
8379 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8380 } catch (SecurityException se) {
8381 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8382 throw new SecurityException("Package " + callingPackage + " does not belong to "
8383 + Binder.getCallingUid());
8384 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008385 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008386 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008387 return null;
8388 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008389 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008390 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008391 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008392 return null;
8393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008394
8395 final long identity = Binder.clearCallingIdentity();
8396 try {
8397 return phone.getDeviceId();
8398 } finally {
8399 Binder.restoreCallingIdentity(identity);
8400 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008401 }
8402
Ping Sunc67b7c22016-03-02 19:16:45 +08008403 /**
8404 * {@hide}
8405 * Returns the IMS Registration Status on a particular subid
8406 *
8407 * @param subId
8408 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008409 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008410 Phone phone = getPhone(subId);
8411 if (phone != null) {
8412 return phone.isImsRegistered();
8413 } else {
8414 return false;
8415 }
8416 }
8417
Santos Cordon7a1885b2015-02-03 11:15:19 -08008418 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008419 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008420 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008422 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008423 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8424 }
8425 final long identity = Binder.clearCallingIdentity();
8426 try {
8427 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8428 } finally {
8429 Binder.restoreCallingIdentity(identity);
8430 }
8431 }
8432
8433 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008434 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008435 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008436 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008437 mApp,
8438 subscriptionId,
8439 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8440 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008441
8442 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8443 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8444
Tyler Gunnf70ed162019-04-03 15:28:53 -07008445 final long identity = Binder.clearCallingIdentity();
8446 try {
8447 Phone phone = getPhone(subscriptionId);
8448 if (phone == null) {
8449 return null;
8450 }
8451 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
8454 }
8455 }
8456
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008457 /**
8458 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008459 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008460 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461 final long identity = Binder.clearCallingIdentity();
8462 try {
8463 Phone phone = getPhone(subId);
8464 if (phone != null) {
8465 return phone.isWifiCallingEnabled();
8466 } else {
8467 return false;
8468 }
8469 } finally {
8470 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008471 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008472 }
8473
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008474 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008475 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008476 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008477 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008478 final long identity = Binder.clearCallingIdentity();
8479 try {
8480 Phone phone = getPhone(subId);
8481 if (phone != null) {
8482 return phone.isVideoEnabled();
8483 } else {
8484 return false;
8485 }
8486 } finally {
8487 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008488 }
8489 }
8490
8491 /**
8492 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8493 * defined in {@link ImsRegistrationImplBase}.
8494 */
8495 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008496 final long identity = Binder.clearCallingIdentity();
8497 try {
8498 Phone phone = getPhone(subId);
8499 if (phone != null) {
8500 return phone.getImsRegistrationTech();
8501 } else {
8502 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8503 }
8504 } finally {
8505 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008506 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008507 }
8508
Stuart Scott8eef64f2015-04-08 15:13:54 -07008509 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008510 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008511 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008512
8513 enforceTelephonyFeatureWithException(callingPackage,
8514 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8515
Stuart Scott981d8582015-04-21 14:09:50 -07008516 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8517 return;
8518 }
Kai Shif70f46f2021-03-03 13:59:46 -08008519 Phone defaultPhone = getDefaultPhone();
8520 if (defaultPhone != null) {
8521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8522 mApp, getDefaultPhone().getSubId(), "factoryReset");
8523 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008524 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008525
Svet Ganovcc087f82015-05-12 20:35:54 -07008526 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008527 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8528 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008529 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008530 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008531 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008532 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008533 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008534 setDataRoamingEnabled(subId, phone == null ? false
8535 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008536 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008537 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008538 // There has been issues when Sms raw table somehow stores orphan
8539 // fragments. They lead to garbled message when new fragments come
8540 // in and combined with those stale ones. In case this happens again,
8541 // user can reset all network settings which will clean up this table.
8542 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008543 // Clean up IMS settings as well here.
8544 int slotId = getSlotIndex(subId);
8545 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8546 ImsManager.getInstance(mApp, slotId).factoryReset();
8547 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008548
Kai Shif70f46f2021-03-03 13:59:46 -08008549 if (defaultPhone == null) {
8550 return;
8551 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008552 // Erase modem config if erase modem on network setting is enabled.
8553 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8554 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8555 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008556 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008557 }
Kai Shif70f46f2021-03-03 13:59:46 -08008558
8559 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008560 } finally {
8561 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008562 }
8563 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008564
SongFerngWangfd89b102021-05-27 22:44:54 +08008565 @VisibleForTesting
8566 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8567 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8568 return;
8569 }
8570 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8571 RILConstants.PREFERRED_NETWORK_MODE);
8572 SubscriptionManager.setSubscriptionProperty(subId,
8573 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8574 "user=" + defaultNetworkType);
8575 phone.loadAllowedNetworksFromSubscriptionDatabase();
8576 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8577 defaultNetworkType, null);
8578 }
8579
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008580 private void cleanUpSmsRawTable(Context context) {
8581 ContentResolver resolver = context.getContentResolver();
8582 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8583 resolver.delete(uri, null, null);
8584 }
8585
Narayan Kamath1c496c22015-04-16 14:40:19 +01008586 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008587 public String getSimLocaleForSubscriber(int subId) {
8588 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008589
8590 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8591 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8592
chen xu5d3637b2019-01-21 23:31:38 -08008593 final Phone phone = getPhone(subId);
8594 if (phone == null) {
8595 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008596 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598 final long identity = Binder.clearCallingIdentity();
8599 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008600 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8601 phone.getContext().getOpPackageName(),
8602 phone.getContext().getAttributionTag());
8603 if (info == null) {
8604 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8605 return null;
chen xu6291c472019-02-04 12:55:53 -08008606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008607 // Try and fetch the locale from the carrier properties or from the SIM language
8608 // preferences (EF-PL and EF-LI)...
8609 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008610 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008611 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8612 if (localeFromDefaultSim != null) {
8613 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8614 if (DBG) log("Using locale from subId: " + subId + " locale: "
8615 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008616 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008617 } else {
8618 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008619 }
8620 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008622 // The SIM language preferences only store a language (e.g. fr = French), not an
8623 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8624 // the SIM and carrier preferences does not include a country we add the country
8625 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008626 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008627 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008628 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008629 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008630 }
8631
8632 if (DBG) log("No locale found - returning null");
8633 return null;
8634 } finally {
8635 Binder.restoreCallingIdentity(identity);
8636 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008637 }
8638
tom hsu0b59d292022-09-29 23:49:21 +08008639 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008640 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008641 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008642 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008643 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008644 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8645 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008646 Locale.forLanguageTag(localeTag).getCountry())) {
8647 return localeTag;
8648 }
8649 }
8650 return inputLocale.toLanguageTag();
8651 }
8652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008653 /**
8654 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8655 */
8656 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008657 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008658 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008659 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008660
Gary Jian3aa9a762022-01-24 16:41:19 +08008661 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8662 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008663
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008664 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008665 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8666 * representing the state of the modem.
8667 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008668 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8669 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008670 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008671 */
8672 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008673 public void requestModemActivityInfo(ResultReceiver result) {
8674 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008675
8676 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8677 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8678
vagdeviaf9a5b92018-08-15 16:01:53 -07008679 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008680
8681 final long identity = Binder.clearCallingIdentity();
8682 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008683 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008684 } finally {
8685 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008686 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008687 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008688
Gary Jian76280a42022-12-07 16:18:33 +08008689 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008690 // less than total activity duration.
8691 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8692 if (info == null) {
8693 return false;
8694 }
8695 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008696 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008697 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8698
Hall Liu49656c02020-10-09 19:00:11 -07008699 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8700
Siddharth Rayb8114062018-06-17 15:02:38 -07008701 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008702 && (info.getSleepTimeMillis() <= activityDurationMs)
8703 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008704 }
8705
Gary Jian3aa9a762022-01-24 16:41:19 +08008706 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8707 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8708 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8709 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8710
8711 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8712 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8713 }
8714
8715 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8716 mLastModemActivityInfo.setReceiveTimeMillis(
8717 rat,
8718 freq,
8719 info.getReceiveTimeMillis(rat, freq)
8720 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8721 }
8722
8723 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8724 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8725 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8726 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8727
8728 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8729 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8730 }
8731 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8732 mLastModemActivityInfo.setReceiveTimeMillis(
8733 rat,
8734 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8735 }
8736
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008737 /**
8738 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8739 * @param info recent ModemActivityInfo
8740 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008741 private void mergeModemActivityInfo(ModemActivityInfo info) {
8742 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008743 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008744 boolean matched;
8745 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8746 matched = false;
8747 int rat = info.getSpecificInfoRat(i);
8748 int freq = info.getSpecificInfoFrequencyRange(i);
8749 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8750 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8751 //if it already exists
8752 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8753 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8754 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8755 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8756 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8757 updateLastModemActivityInfo(info, rat, freq);
8758 matched = true;
8759 }
8760 } else {
8761 updateLastModemActivityInfo(info, rat);
8762 matched = true;
8763 }
8764 }
8765 }
8766
8767 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008768 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008769 new ActivityStatsTechSpecificInfo(
8770 rat,
8771 freq,
8772 info.getTransmitTimeMillis(rat, freq),
8773 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008774 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008775 }
8776 }
8777 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8778 mLastModemActivitySpecificInfo =
8779 new ActivityStatsTechSpecificInfo[merged.size()];
8780 merged.toArray(mLastModemActivitySpecificInfo);
8781
8782 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8783 mLastModemActivityInfo.setSleepTimeMillis(
8784 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008785 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008786 mLastModemActivityInfo.setIdleTimeMillis(
8787 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008788 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008789
8790 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008791 new ModemActivityInfo(
8792 mLastModemActivityInfo.getTimestampMillis(),
8793 mLastModemActivityInfo.getSleepTimeMillis(),
8794 mLastModemActivityInfo.getIdleTimeMillis(),
8795 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008796 }
8797
8798 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8799 ActivityStatsTechSpecificInfo[] info) {
8800 int infoSize = info.length;
8801 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8802 for (int i = 0; i < infoSize; i++) {
8803 ret[i] = new ActivityStatsTechSpecificInfo(
8804 info[i].getRat(), info[i].getFrequencyRange(),
8805 info[i].getTransmitTimeMillis(),
8806 (int) info[i].getReceiveTimeMillis());
8807 }
8808 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008809 }
8810
Jack Yu85bd38a2015-11-09 11:34:32 -08008811 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008812 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008813 */
8814 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008815 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8816 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8817 Phone phone = PhoneFactory.getPhone(slotIndex);
8818 if (phone == null) {
8819 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8820 return null;
8821 }
8822
8823 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008825 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008826 return null;
8827 }
8828
joonhunshin4ac60942023-11-15 15:23:39 +00008829 enforceTelephonyFeatureWithException(callingPackage,
8830 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8831
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008832 boolean hasFinePermission = false;
8833 boolean hasCoarsePermission = false;
8834 if (!renounceFineLocationAccess) {
8835 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8836 LocationAccessPolicy.checkLocationPermission(mApp,
8837 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8838 .setCallingPackage(callingPackage)
8839 .setCallingFeatureId(callingFeatureId)
8840 .setCallingPid(Binder.getCallingPid())
8841 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008842 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008843 .setLogAsInfo(true)
8844 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8845 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8846 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8847 .build());
8848 hasFinePermission =
8849 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8850 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008851
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008852 if (!renounceCoarseLocationAccess) {
8853 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8854 LocationAccessPolicy.checkLocationPermission(mApp,
8855 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8856 .setCallingPackage(callingPackage)
8857 .setCallingFeatureId(callingFeatureId)
8858 .setCallingPid(Binder.getCallingPid())
8859 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008860 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008861 .setLogAsInfo(true)
8862 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8863 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8864 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8865 .build());
8866 hasCoarsePermission =
8867 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8868 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008869
Jordan Liu0f2bc442020-11-18 16:47:37 -08008870 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008871 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008872 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8873 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008874 if (subInfo != null && !subInfo.isActive()) {
8875 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008876 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008877 }
8878
Hall Liuf19c44f2018-11-27 14:38:17 -08008879 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008880 boolean isCallingPackageDataService = phone.getDataServicePackages()
8881 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008882
8883 // Scrub out the location info in ServiceState depending on what level of access
8884 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008885 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008886 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8887 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008891 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008892
8893 /**
8894 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8895 *
8896 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8897 * voicemail ringtone.
8898 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8899 * PhoneAccount.
8900 */
8901 @Override
8902 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008903 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8904 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008906 final long identity = Binder.clearCallingIdentity();
8907 try {
8908 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8909 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008910 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008911 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008913 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8914 } finally {
8915 Binder.restoreCallingIdentity(identity);
8916 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008917 }
8918
8919 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008920 * Sets the per-account voicemail ringtone.
8921 *
8922 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8923 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8924 *
8925 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8926 * voicemail ringtone.
8927 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8928 * PhoneAccount.
8929 */
8930 @Override
8931 public void setVoicemailRingtoneUri(String callingPackage,
8932 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008933 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008934 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008935 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8936 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8938 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8939 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008940 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008941
joonhunshin4ac60942023-11-15 15:23:39 +00008942 enforceTelephonyFeatureWithException(callingPackage,
8943 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945 final long identity = Binder.clearCallingIdentity();
8946 try {
8947 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8948 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008949 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950 }
8951 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8952 } finally {
8953 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008954 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008955 }
8956
8957 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008958 * Returns whether vibration is set for voicemail notification in Phone settings.
8959 *
8960 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8961 * voicemail vibration setting.
8962 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8963 */
8964 @Override
8965 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008966 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8967 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008969 final long identity = Binder.clearCallingIdentity();
8970 try {
8971 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8972 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008973 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008974 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008976 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8977 } finally {
8978 Binder.restoreCallingIdentity(identity);
8979 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008980 }
8981
Youhan Wange64578a2016-05-02 15:32:42 -07008982 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008983 * Sets the per-account voicemail vibration.
8984 *
8985 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8986 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8987 *
8988 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8989 * voicemail vibration setting.
8990 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8991 * specific PhoneAccount.
8992 */
8993 @Override
8994 public void setVoicemailVibrationEnabled(String callingPackage,
8995 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008996 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008997 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008998 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8999 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9001 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9002 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009003 }
9004
joonhunshin4ac60942023-11-15 15:23:39 +00009005 enforceTelephonyFeatureWithException(callingPackage,
9006 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009008 final long identity = Binder.clearCallingIdentity();
9009 try {
9010 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9011 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009012 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009013 }
9014 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9015 } finally {
9016 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009017 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009018 }
9019
9020 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009021 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9022 *
9023 * @throws SecurityException if the caller does not have the required permission
9024 */
arunvoddud7401012022-12-15 16:08:12 +00009025 @VisibleForTesting
9026 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009027 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009028 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009029 }
9030
9031 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009032 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9033 * permission.
9034 *
9035 * @throws SecurityException if the caller does not have the required permission
9036 */
9037 private void enforceSendSmsPermission() {
9038 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9039 }
9040
9041 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009042 * Make sure either called from same process as self (phone) or IPC caller has interact across
9043 * users permission.
9044 *
9045 * @throws SecurityException if the caller does not have the required permission
9046 */
9047 private void enforceInteractAcrossUsersPermission(String message) {
9048 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9049 }
9050
9051 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009052 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009053 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009054 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009055 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009056 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009057 final long identity = Binder.clearCallingIdentity();
9058 try {
9059 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009060 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009061 if (componentName == null) {
9062 throw new SecurityException(
9063 "Caller not current active visual voicemail package[null]");
9064 }
9065 String vvmPackage = componentName.getPackageName();
9066 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009067 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009068 }
9069 } finally {
9070 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009071 }
9072 }
9073
9074 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009075 * Return the application ID for the app type.
9076 *
9077 * @param subId the subscription ID that this request applies to.
9078 * @param appType the uicc app type.
9079 * @return Application ID for specificied app type, or null if no uicc.
9080 */
9081 @Override
9082 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009083 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009084
9085 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9086 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9087
Youhan Wange64578a2016-05-02 15:32:42 -07009088 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009089
9090 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009091 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009092 if (phone == null) {
9093 return null;
9094 }
9095 String aid = null;
9096 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009097 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009098 .getApplicationByType(appType).getAid();
9099 } catch (Exception e) {
9100 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9101 }
9102 return aid;
9103 } finally {
9104 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009105 }
Youhan Wange64578a2016-05-02 15:32:42 -07009106 }
9107
Youhan Wang4001d252016-05-11 10:29:41 -07009108 /**
9109 * Return the Electronic Serial Number.
9110 *
9111 * @param subId the subscription ID that this request applies to.
9112 * @return ESN or null if error.
9113 */
9114 @Override
9115 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009116 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009117 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009118
9119 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009120 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009121 if (phone == null) {
9122 return null;
9123 }
9124 String esn = null;
9125 try {
9126 esn = phone.getEsn();
9127 } catch (Exception e) {
9128 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9129 }
9130 return esn;
9131 } finally {
9132 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009133 }
Youhan Wang4001d252016-05-11 10:29:41 -07009134 }
9135
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009136 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009137 * Return the Preferred Roaming List Version.
9138 *
9139 * @param subId the subscription ID that this request applies to.
9140 * @return PRLVersion or null if error.
9141 */
9142 @Override
9143 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009144 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009145
9146 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9147 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9148
Youhan Wang66ad5d72016-07-18 17:56:58 -07009149 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009150
9151 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009152 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009153 if (phone == null) {
9154 return null;
9155 }
9156 String cdmaPrlVersion = null;
9157 try {
9158 cdmaPrlVersion = phone.getCdmaPrlVersion();
9159 } catch (Exception e) {
9160 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9161 }
9162 return cdmaPrlVersion;
9163 } finally {
9164 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009165 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009166 }
9167
9168 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009169 * Get snapshot of Telephony histograms
9170 * @return List of Telephony histograms
9171 * @hide
9172 */
9173 @Override
9174 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9176 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009177
9178 final long identity = Binder.clearCallingIdentity();
9179 try {
9180 return RIL.getTelephonyRILTimingHistograms();
9181 } finally {
9182 Binder.restoreCallingIdentity(identity);
9183 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009184 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009185
9186 /**
9187 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009188 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9189 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009190 * Require system privileges. In the future we may add this to carrier APIs.
9191 *
Michele Berionne482f8202018-11-27 18:57:59 -08009192 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009193 */
9194 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009195 @TelephonyManager.SetCarrierRestrictionResult
9196 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009197 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009198
9199 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9200 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9201
vagdeviaf9a5b92018-08-15 16:01:53 -07009202 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009203
Michele Berionne482f8202018-11-27 18:57:59 -08009204 if (carrierRestrictionRules == null) {
9205 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009206 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009208 final long identity = Binder.clearCallingIdentity();
9209 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009210 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009211 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009212 } finally {
9213 Binder.restoreCallingIdentity(identity);
9214 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009215 }
9216
9217 /**
9218 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009219 * Get the allowed carrier list and the excluded carrier list, including the priority between
9220 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009221 * Require system privileges. In the future we may add this to carrier APIs.
9222 *
Michele Berionne482f8202018-11-27 18:57:59 -08009223 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009224 */
9225 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009226 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009227 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009228
9229 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9230 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9231
vagdeviaf9a5b92018-08-15 16:01:53 -07009232 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009233
9234 final long identity = Binder.clearCallingIdentity();
9235 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009236 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9237 if (response instanceof CarrierRestrictionRules) {
9238 return (CarrierRestrictionRules) response;
9239 }
9240 // Response is an Exception of some kind,
9241 // which is signalled to the user as a NULL retval
9242 return null;
9243 } catch (Exception e) {
9244 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9245 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009246 } finally {
9247 Binder.restoreCallingIdentity(identity);
9248 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009249 }
9250
fionaxu59545b42016-05-25 15:53:37 -07009251 /**
arunvoddud7401012022-12-15 16:08:12 +00009252 * Fetches the carrier restriction status of the device and sends the status to the caller
9253 * through the callback.
9254 *
9255 * @param callback The callback that will be used to send the result.
9256 * @throws SecurityException if the caller does not have the required permission/privileges or
9257 * the caller is not allowlisted.
9258 */
9259 @Override
9260 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9261 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009262
9263 enforceTelephonyFeatureWithException(packageName,
9264 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9265
Steve Statia28b7cb32024-03-11 23:58:50 +00009266 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9267 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009268 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9269 throw new SecurityException("Not an authorized caller");
9270 }
9271 final long identity = Binder.clearCallingIdentity();
9272 try {
9273 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009274 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009275 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9276 } finally {
9277 Binder.restoreCallingIdentity(identity);
9278 }
9279 }
9280
arunvoddu567f2b42023-04-25 17:22:00 +00009281 @Override
9282 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9283 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9284 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9285 return allowListInfo.getShaIdList(pkgName, carrierId);
9286 }
9287
arunvoddud7401012022-12-15 16:08:12 +00009288 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009289 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009290 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009291 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009292 }
9293
9294 /**
fionaxu59545b42016-05-25 15:53:37 -07009295 * Action set from carrier signalling broadcast receivers to enable/disable radio
9296 * @param subId the subscription ID that this action applies to.
9297 * @param enabled control enable or disable radio.
9298 * {@hide}
9299 */
9300 @Override
9301 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9302 enforceModifyPermission();
9303 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009304
9305 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009306 if (phone == null) {
9307 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9308 return;
9309 }
9310 try {
9311 phone.carrierActionSetRadioEnabled(enabled);
9312 } catch (Exception e) {
9313 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009314 } finally {
9315 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009316 }
9317 }
9318
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009319 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009320 * Enable or disable Voice over NR (VoNR)
9321 * @param subId the subscription ID that this action applies to.
9322 * @param enabled enable or disable VoNR.
9323 * @return operation result.
9324 */
9325 @Override
9326 public int setVoNrEnabled(int subId, boolean enabled) {
9327 enforceModifyPermission();
9328 final Phone phone = getPhone(subId);
9329
9330 final long identity = Binder.clearCallingIdentity();
9331 if (phone == null) {
9332 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9333 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9334 }
9335
9336 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9337 try {
9338 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9339 workSource);
9340 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009341
9342 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9343 if (DBG) {
9344 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9345 }
9346 SubscriptionManager.setSubscriptionProperty(
9347 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9348 (enabled ? "1" : "0"));
9349 }
9350
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009351 return result;
9352 } finally {
9353 Binder.restoreCallingIdentity(identity);
9354 }
9355 }
9356
9357 /**
9358 * Is voice over NR enabled
9359 * @return true if VoNR is enabled else false
9360 */
9361 @Override
9362 public boolean isVoNrEnabled(int subId) {
9363 enforceReadPrivilegedPermission("isVoNrEnabled");
9364 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9365 final long identity = Binder.clearCallingIdentity();
9366 try {
9367 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9368 null, subId, workSource);
9369 if (DBG) log("isVoNrEnabled: " + isEnabled);
9370 return isEnabled;
9371 } finally {
9372 Binder.restoreCallingIdentity(identity);
9373 }
9374 }
9375
9376 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009377 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9378 * network status based on which carrier apps could apply actions accordingly,
9379 * enable/disable default url handler for example.
9380 *
9381 * @param subId the subscription ID that this action applies to.
9382 * @param report control start/stop reporting the default network status.
9383 * {@hide}
9384 */
9385 @Override
9386 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9387 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009388
9389 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9390 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9391 "carrierActionReportDefaultNetworkStatus");
9392
fionaxu8da9cb12017-05-23 15:02:46 -07009393 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009394
9395 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009396 if (phone == null) {
9397 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9398 return;
9399 }
9400 try {
9401 phone.carrierActionReportDefaultNetworkStatus(report);
9402 } catch (Exception e) {
9403 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009404 } finally {
9405 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009406 }
9407 }
9408
9409 /**
fionaxud9622282017-07-17 17:51:30 -07009410 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9411 * @param subId the subscription ID that this action applies to.
9412 * {@hide}
9413 */
9414 @Override
9415 public void carrierActionResetAll(int subId) {
9416 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009417
9418 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9419 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9420
fionaxud9622282017-07-17 17:51:30 -07009421 final Phone phone = getPhone(subId);
9422 if (phone == null) {
9423 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9424 return;
9425 }
9426 try {
9427 phone.carrierActionResetAll();
9428 } catch (Exception e) {
9429 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9430 }
9431 }
9432
9433 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009434 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9435 * bug report is being generated.
9436 */
9437 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009438 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009439 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9440 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009441 writer.println("Permission Denial: can't dump Phone from pid="
9442 + Binder.getCallingPid()
9443 + ", uid=" + Binder.getCallingUid()
9444 + "without permission "
9445 + android.Manifest.permission.DUMP);
9446 return;
9447 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009448 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009449 }
Jack Yueb89b242016-06-22 13:27:47 -07009450
Brad Ebingerdac2f002018-04-03 15:17:52 -07009451 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009452 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9453 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9454 @NonNull String[] args) {
9455 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9456 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009457 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009458 }
9459
Jack Yueb89b242016-06-22 13:27:47 -07009460 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009461 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009462 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009463 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009464 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009465 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009466 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009467 */
9468 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009469 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009470 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009471 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9472 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9473 try {
9474 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009475 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009476 } catch (SecurityException se) {
9477 enforceModifyPermission();
9478 }
9479 } else {
9480 enforceModifyPermission();
9481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009482
joonhunshin4ac60942023-11-15 15:23:39 +00009483 enforceTelephonyFeatureWithException(callingPackage,
9484 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9485
Nate Myren116695d2024-02-09 09:36:01 -08009486 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009487 final long identity = Binder.clearCallingIdentity();
9488 try {
Nate Myren116695d2024-02-09 09:36:01 -08009489 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9490 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009491 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009492 callingUid, callingPackage, null, null);
9493 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009494 Phone phone = getPhone(subId);
9495 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009496 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9497 phone.carrierActionSetMeteredApnsEnabled(enabled);
9498 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009499 phone.getDataSettingsManager().setDataEnabled(
9500 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009501 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009502 }
9503 } finally {
9504 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009505 }
9506 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009507
9508 /**
9509 * Get Client request stats
9510 * @return List of Client Request Stats
9511 * @hide
9512 */
9513 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009514 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9515 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009516 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009517 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009518 return null;
9519 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009520 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009522 final long identity = Binder.clearCallingIdentity();
9523 try {
9524 if (phone != null) {
9525 return phone.getClientRequestStats();
9526 }
9527
9528 return null;
9529 } finally {
9530 Binder.restoreCallingIdentity(identity);
9531 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009532 }
9533
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009534 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009535 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009536 if (uid == Process.ROOT_UID && packageName == null) {
9537 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9538 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9539 // exception. ROOT_UID seems not to have a valid package name returned by
9540 // PackageManager, so just fake it here to avoid issues when running telephony shell
9541 // commands that plumb through the RIL as root, like so:
9542 // $ adb root
9543 // $ adb shell cmd phone ...
9544 packageName = "root";
9545 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009546 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009547 }
Jack Yueb4124c2017-02-16 15:32:43 -08009548
9549 /**
Grace Chen70990072017-03-24 17:21:30 -07009550 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009551 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009552 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009553 * @param state State of SIM (power down, power up, pass through)
9554 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9555 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9556 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009557 *
9558 **/
9559 @Override
Grace Chen70990072017-03-24 17:21:30 -07009560 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009561 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009562
9563 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9564 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9565
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009566 Phone phone = PhoneFactory.getPhone(slotIndex);
9567
vagdeviaf9a5b92018-08-15 16:01:53 -07009568 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009570 final long identity = Binder.clearCallingIdentity();
9571 try {
9572 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009573 phone.setSimPowerState(state, null, workSource);
9574 }
9575 } finally {
9576 Binder.restoreCallingIdentity(identity);
9577 }
9578 }
9579
9580 /**
9581 * Set SIM card power state.
9582 *
9583 * @param slotIndex SIM slot id.
9584 * @param state State of SIM (power down, power up, pass through)
9585 * @param callback callback to trigger after success or failure
9586 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9587 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9588 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9589 *
9590 **/
9591 @Override
9592 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9593 IIntegerConsumer callback) {
9594 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009595
9596 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9597 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9598 "setSimPowerStateForSlotWithCallback");
9599
Jordan Liu109698e2020-11-24 14:50:34 -08009600 Phone phone = PhoneFactory.getPhone(slotIndex);
9601
9602 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9603
9604 final long identity = Binder.clearCallingIdentity();
9605 try {
9606 if (phone != null) {
9607 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9608 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009609 }
9610 } finally {
9611 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009612 }
9613 }
Shuo Qiandd210312017-04-12 22:11:33 +00009614
Tyler Gunn65d45c22017-06-05 11:22:26 -07009615 private boolean isUssdApiAllowed(int subId) {
9616 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009617 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009618 if (configManager == null) {
9619 return false;
9620 }
9621 PersistableBundle pb = configManager.getConfigForSubId(subId);
9622 if (pb == null) {
9623 return false;
9624 }
9625 return pb.getBoolean(
9626 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9627 }
9628
Shuo Qiandd210312017-04-12 22:11:33 +00009629 /**
Ling Mac28f0212023-03-24 16:07:15 -07009630 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009631 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009632 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009633 */
goneil9c5f4872017-12-05 14:07:56 -08009634 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009635 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009636 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009637
9638 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9639 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009641 final long identity = Binder.clearCallingIdentity();
9642 try {
Ling Mac28f0212023-03-24 16:07:15 -07009643 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009644 } finally {
9645 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009646 }
9647 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009648
9649 /**
9650 * Get the current signal strength information for the given subscription.
9651 * Because this information is not updated when the device is in a low power state
9652 * it should not be relied-upon to be current.
9653 * @param subId Subscription index
9654 * @return the most recent cached signal strength info from the modem
9655 */
9656 @Override
9657 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009658 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9659 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009661 final long identity = Binder.clearCallingIdentity();
9662 try {
9663 Phone p = getPhone(subId);
9664 if (p == null) {
9665 return null;
9666 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009668 return p.getSignalStrength();
9669 } finally {
9670 Binder.restoreCallingIdentity(identity);
9671 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009672 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009673
Pengquan Meng77b7f132018-08-22 14:49:57 -07009674 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009675 * Get the current modem radio state for the given slot.
9676 * @param slotIndex slot index.
9677 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009678 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009679 * @return the current radio power state from the modem
9680 */
9681 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009682 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009683 Phone phone = PhoneFactory.getPhone(slotIndex);
9684 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9686 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009687 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9688 }
9689
joonhunshin4ac60942023-11-15 15:23:39 +00009690 enforceTelephonyFeatureWithException(callingPackage,
9691 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9692
Chen Xuf792fd62018-10-17 17:54:36 +00009693 final long identity = Binder.clearCallingIdentity();
9694 try {
9695 return phone.getRadioPowerState();
9696 } finally {
9697 Binder.restoreCallingIdentity(identity);
9698 }
9699 }
9700 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9701 }
9702
9703 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009704 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9705 *
9706 * <p>Requires one of the following permissions:
9707 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009708 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009709 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9710 * privileges.
9711 *
9712 * @param subId subscription id
9713 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9714 * {@code false}.
9715 */
9716 @Override
9717 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009718 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009719 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009720 try {
9721 mApp.enforceCallingOrSelfPermission(
9722 android.Manifest.permission.ACCESS_NETWORK_STATE,
9723 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009724 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009725 mApp.enforceCallingOrSelfPermission(
9726 permission.READ_BASIC_PHONE_STATE, functionName);
9727 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009728 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009729 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009730 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009731 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009732
joonhunshin4ac60942023-11-15 15:23:39 +00009733 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9734 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9735
Pengquan Menga1bb6272018-09-06 09:59:22 -07009736 boolean isEnabled = false;
9737 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009738 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009739 Phone phone = getPhone(subId);
9740 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009741 } finally {
9742 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009743 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009744 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009745 }
9746
9747
9748 /**
9749 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9750 *
9751 * <p> Requires permission:
9752 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9753 * privileges.
9754 *
9755 * @param subId subscription id
9756 * @param isEnabled {@code true} means enable, {@code false} means disable.
9757 */
9758 @Override
9759 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9761 mApp, subId, "setDataRoamingEnabled");
9762
joonhunshin4ac60942023-11-15 15:23:39 +00009763 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9764 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9765
Pengquan Menga1bb6272018-09-06 09:59:22 -07009766 final long identity = Binder.clearCallingIdentity();
9767 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009768 Phone phone = getPhone(subId);
9769 if (phone != null) {
9770 phone.setDataRoamingEnabled(isEnabled);
9771 }
9772 } finally {
9773 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009774 }
9775 }
9776
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009777 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009778 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009779 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009780 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009781 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009782
joonhunshin4ac60942023-11-15 15:23:39 +00009783 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9784 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9785
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009786 boolean isAllowed = true;
9787 final long identity = Binder.clearCallingIdentity();
9788 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009789 Phone phone = getPhone(subId);
9790 if (phone != null) {
9791 isAllowed = phone.isCspPlmnEnabled();
9792 }
9793 } finally {
9794 Binder.restoreCallingIdentity(identity);
9795 }
9796 return isAllowed;
9797 }
9798
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009799 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9800 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009801 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009802 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009803 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009804 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9805 if (phone == null) {
9806 return false;
9807 }
9808 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9809 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9810 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009811 }
9812
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009813 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009814 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009815 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009816 mApp.getSystemService(AppOpsManager.class)
9817 .checkPackage(Binder.getCallingUid(), callingPackage);
9818
Jordan Liu1e142fc2019-04-22 15:10:43 -07009819 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009820 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009821 try {
9822 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009823 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009824 } catch (SecurityException e) {
9825 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9826 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009827 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009828 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009829 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009830 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009831 }
joonhunshin4ac60942023-11-15 15:23:39 +00009832
9833 enforceTelephonyFeatureWithException(callingPackage,
9834 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9835
sandeepjsb6c87872021-09-27 15:34:44 +00009836 // checking compatibility, if calling app's target SDK is T and beyond.
9837 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9838 Binder.getCallingUid())) {
9839 isIccIdAccessRestricted = true;
9840 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009841 final long identity = Binder.clearCallingIdentity();
9842 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009843 UiccController uiccController = UiccController.getInstance();
9844 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009845 if (hasReadPermission) {
9846 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009847 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009848
9849 // Remove private info if the caller doesn't have access
9850 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9851 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009852 //setting the value after compatibility check
9853 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009854 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9855 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009856 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009857 if (card == null) {
9858 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009859 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009860 continue;
9861 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009862 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9863 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009864 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009865 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009866 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009867 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9868 for (UiccPortInfo portInfo : portInfos) {
9869 UiccPort port = uiccController.getUiccPortForSlot(
9870 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9871 if (port == null) {
9872 // assume no access if port is null
9873 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9874 continue;
9875 }
9876 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9877 uiccPortInfos.add(portInfo);
9878 } else {
9879 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9880 }
9881 }
9882 filteredInfos.add(new UiccCardInfo(
9883 cardInfo.isEuicc(),
9884 cardInfo.getCardId(),
9885 null,
9886 cardInfo.getPhysicalSlotIndex(),
9887 cardInfo.isRemovable(),
9888 cardInfo.isMultipleEnabledProfilesSupported(),
9889 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009890 }
9891 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009892 } finally {
9893 Binder.restoreCallingIdentity(identity);
9894 }
9895 }
9896
sandeepjsb6c87872021-09-27 15:34:44 +00009897 /**
9898 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9899 * generally private and require carrier privileges to view.
9900 *
9901 * @hide
9902 */
9903 @NonNull
9904 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9905 List<UiccPortInfo> portinfo = new ArrayList<>();
9906 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9907 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9908 }
9909 return new UiccCardInfo(
9910 cardInfo.isEuicc(),
9911 cardInfo.getCardId(),
9912 null,
9913 cardInfo.getPhysicalSlotIndex(),
9914 cardInfo.isRemovable(),
9915 cardInfo.isMultipleEnabledProfilesSupported(),
9916 portinfo
9917 );
9918 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009919
sandeepjsb6c87872021-09-27 15:34:44 +00009920 /**
9921 * @hide
9922 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9923 * These values are generally private and require carrier privileges to view.
9924 */
9925 @NonNull
9926 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9927 return new UiccPortInfo(
9928 UiccPortInfo.ICCID_REDACTED,
9929 portInfo.getPortIndex(),
9930 portInfo.getLogicalSlotIndex(),
9931 portInfo.isActive()
9932 );
9933 }
9934 @Override
9935 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009936 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009937 mApp.getSystemService(AppOpsManager.class)
9938 .checkPackage(Binder.getCallingUid(), callingPackage);
9939
sandeepjsb6c87872021-09-27 15:34:44 +00009940 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009941
Aman Guptaf3c90b32022-03-17 04:54:16 +00009942 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9943 // we are reading iccId which is PII data.
9944 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009945
joonhunshin4ac60942023-11-15 15:23:39 +00009946 enforceTelephonyFeatureWithException(callingPackage,
9947 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9948
sandeepjsb6c87872021-09-27 15:34:44 +00009949 // checking compatibility, if calling app's target SDK is T and beyond.
9950 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9951 Binder.getCallingUid())) {
9952 isLogicalSlotAccessRestricted = true;
9953 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009954 final long identity = Binder.clearCallingIdentity();
9955 try {
9956 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009957 if (slots == null || slots.length == 0) {
9958 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009959 return null;
9960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009961 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9962 for (int i = 0; i < slots.length; i++) {
9963 UiccSlot slot = slots[i];
9964 if (slot == null) {
9965 continue;
9966 }
9967
Jordan Liu7be7e652019-05-06 18:55:02 +00009968 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009969 UiccCard card = slot.getUiccCard();
9970 if (card != null) {
9971 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009972 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009973 cardId = slot.getEid();
9974 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009975 // If cardId is null, use iccId of default port as cardId.
9976 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009978 }
9979
Jordan Liu857451f2019-05-09 16:35:35 -07009980 if (cardId != null) {
9981 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9982 // if cardId is an EID, it's all digits so this is fine
9983 cardId = IccUtils.stripTrailingFs(cardId);
9984 }
9985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009986 int cardState = 0;
9987 switch (slot.getCardState()) {
9988 case CARDSTATE_ABSENT:
9989 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9990 break;
9991 case CARDSTATE_PRESENT:
9992 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9993 break;
9994 case CARDSTATE_ERROR:
9995 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9996 break;
9997 case CARDSTATE_RESTRICTED:
9998 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9999 break;
10000 default:
10001 break;
10002
10003 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010004 List<UiccPortInfo> portInfos = new ArrayList<>();
10005 int[] portIndexes = slot.getPortList();
10006 for (int portIdx : portIndexes) {
10007 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010008 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010009 portInfos.add(new UiccPortInfo(iccId, portIdx,
10010 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010012 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010013 slot.isEuicc(),
10014 cardId,
10015 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010016 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010017 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010018 //setting the value after compatibility check
10019 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010020 }
10021 return infos;
10022 } finally {
10023 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010024 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010025 }
10026
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010027 /* Returns null if doesn't have read permission or carrier privilege access. */
10028 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10029 boolean hasReadPermission) {
10030 String iccId = slot.getIccId(portIndex);
10031 if (hasReadPermission) { // if has read permission
10032 return iccId;
10033 } else {
10034 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10035 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10036 // if no read permission, checking carrier privilege access
10037 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10038 return iccId;
10039 }
10040 }
10041 }
10042 // No read permission or carrier privilege access.
10043 return UiccPortInfo.ICCID_REDACTED;
10044 }
10045
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010046 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010047 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010048 public boolean switchSlots(int[] physicalSlots) {
10049 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010050
joonhunshin4ac60942023-11-15 15:23:39 +000010051 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10052 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10053
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010054 final long identity = Binder.clearCallingIdentity();
10055 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010056 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10057 for (int i = 0; i < physicalSlots.length; i++) {
10058 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10059 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10060 physicalSlots[i], i));
10061 }
10062 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010063 } finally {
10064 Binder.restoreCallingIdentity(identity);
10065 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010066 }
Jack Yu4c988042018-02-27 15:30:01 -080010067
10068 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010069 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10070 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10071 enforceModifyPermission();
10072
joonhunshin4ac60942023-11-15 15:23:39 +000010073 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10074 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10075
sandeepjsb6c87872021-09-27 15:34:44 +000010076 final long identity = Binder.clearCallingIdentity();
10077 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010078 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010079 } finally {
10080 Binder.restoreCallingIdentity(identity);
10081 }
10082 }
10083
10084 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010085 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010086 enforceTelephonyFeatureWithException(callingPackage,
10087 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10088
Jordan Liu7de49fa2018-12-06 14:48:49 -080010089 final long identity = Binder.clearCallingIdentity();
10090 try {
10091 return UiccController.getInstance().getCardIdForDefaultEuicc();
10092 } finally {
10093 Binder.restoreCallingIdentity(identity);
10094 }
10095 }
10096
Pengquan Meng85728fb2018-03-12 16:31:21 -070010097 /**
goneil47ffb6e2018-04-06 15:40:58 -070010098 * A test API to reload the UICC profile.
10099 *
10100 * <p>Requires that the calling app has permission
10101 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10102 * @hide
10103 */
10104 @Override
10105 public void refreshUiccProfile(int subId) {
10106 enforceModifyPermission();
10107
10108 final long identity = Binder.clearCallingIdentity();
10109 try {
10110 Phone phone = getPhone(subId);
10111 if (phone == null) {
10112 return;
10113 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010114 UiccPort uiccPort = phone.getUiccPort();
10115 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010116 return;
10117 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010118 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010119 if (uiccProfile == null) {
10120 return;
10121 }
10122 uiccProfile.refresh();
10123 } finally {
10124 Binder.restoreCallingIdentity(identity);
10125 }
10126 }
10127
10128 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010129 * Returns false if the mobile data is disabled by default, otherwise return true.
10130 */
10131 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010132 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010133 }
10134
10135 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010136 * Returns the default network type for the given {@code subId}, if the default network type is
10137 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10138 */
10139 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010140 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010141 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010142 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10143 return list.get(phoneId);
10144 }
10145 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010146 }
fionaxua13278b2018-03-21 00:08:13 -070010147
10148 @Override
10149 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010150 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010151 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010152
10153 final long identity = Binder.clearCallingIdentity();
10154 try {
10155 final Phone phone = getPhone(subId);
10156 if (phone == null) {
10157 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10158 return;
10159 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010160 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10161 if (cpt != null) {
10162 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10163 }
10164 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010165 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10166 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010167 if (carrierPrivilegeRules == null) {
10168 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10169 } else {
10170 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010172 } finally {
10173 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010174 }
fionaxua13278b2018-03-21 00:08:13 -070010175 }
10176
10177 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010178 public void setCarrierServicePackageOverride(
10179 int subId, String carrierServicePackage, String callingPackage) {
10180 TelephonyPermissions.enforceShellOnly(
10181 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10182
Benedict Wong66477622023-02-03 23:30:57 +000010183 final long identity = Binder.clearCallingIdentity();
10184 try {
10185 final Phone phone = getPhone(subId);
10186 if (phone == null || phone.getSubId() != subId) {
10187 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10188 throw new IllegalArgumentException("No phone for subid");
10189 }
10190 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10191 if (cpt == null) {
10192 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10193 throw new IllegalStateException("No CPT for phone");
10194 }
10195 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10196 } finally {
10197 Binder.restoreCallingIdentity(identity);
10198 }
10199 }
10200
10201 @Override
fionaxua13278b2018-03-21 00:08:13 -070010202 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010203 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010204
10205 final long identity = Binder.clearCallingIdentity();
10206 try {
10207 final Phone phone = getPhone(subId);
10208 if (phone == null) {
10209 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10210 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10211 }
10212 return phone.getCarrierIdListVersion();
10213 } finally {
10214 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010215 }
fionaxua13278b2018-03-21 00:08:13 -070010216 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010217
10218 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010219 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10220 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010222 mApp, subId, callingPackage, callingFeatureId,
10223 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010224 return -1;
10225 }
10226
10227 final long identity = Binder.clearCallingIdentity();
10228 try {
10229 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10230 } finally {
10231 Binder.restoreCallingIdentity(identity);
10232 }
10233 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010234
10235 @Override
10236 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010237 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010238 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010239 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010240
joonhunshin4ac60942023-11-15 15:23:39 +000010241 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10242 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10243
Pengquan Menga1bb6272018-09-06 09:59:22 -070010244 final long identity = Binder.clearCallingIdentity();
10245 try {
10246 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10247 } finally {
10248 Binder.restoreCallingIdentity(identity);
10249 }
10250 }
10251
10252 @Override
10253 public boolean setCdmaRoamingMode(int subId, int mode) {
10254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10255 mApp, subId, "setCdmaRoamingMode");
10256
joonhunshin4ac60942023-11-15 15:23:39 +000010257 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10258 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10259
Pengquan Menga1bb6272018-09-06 09:59:22 -070010260 final long identity = Binder.clearCallingIdentity();
10261 try {
10262 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10263 } finally {
10264 Binder.restoreCallingIdentity(identity);
10265 }
10266 }
10267
10268 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010269 public int getCdmaSubscriptionMode(int subId) {
10270 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010271 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010272 mApp, subId, "getCdmaSubscriptionMode");
10273
joonhunshin4ac60942023-11-15 15:23:39 +000010274 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10275 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10276
Sarah Chinbaab1432020-10-28 13:46:24 -070010277 final long identity = Binder.clearCallingIdentity();
10278 try {
10279 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10280 } finally {
10281 Binder.restoreCallingIdentity(identity);
10282 }
10283 }
10284
10285 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010286 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10287 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10288 mApp, subId, "setCdmaSubscriptionMode");
10289
joonhunshin4ac60942023-11-15 15:23:39 +000010290 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10291 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10292
Pengquan Menga1bb6272018-09-06 09:59:22 -070010293 final long identity = Binder.clearCallingIdentity();
10294 try {
10295 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10296 } finally {
10297 Binder.restoreCallingIdentity(identity);
10298 }
10299 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010300
sqianc5eccab2018-10-19 18:46:41 -070010301 @Override
sqian8c685422019-02-22 15:55:18 -080010302 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010303 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010304 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010305 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10306 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010307 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10308 }
joonhunshin4ac60942023-11-15 15:23:39 +000010309
10310 enforceTelephonyFeatureWithException(callingPackage,
10311 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10312
sqian11b7a0e2018-12-05 18:48:28 -080010313 final long identity = Binder.clearCallingIdentity();
10314 try {
sqian854d44b2018-12-12 16:48:18 -080010315 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10316 for (Phone phone: PhoneFactory.getPhones()) {
10317 if (phone.getEmergencyNumberTracker() != null
10318 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10319 emergencyNumberListInternal.put(
10320 phone.getSubId(),
10321 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10322 }
sqian11b7a0e2018-12-05 18:48:28 -080010323 }
sqian854d44b2018-12-12 16:48:18 -080010324 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010325 } finally {
10326 Binder.restoreCallingIdentity(identity);
10327 }
sqianc5eccab2018-10-19 18:46:41 -070010328 }
10329
10330 @Override
sqian8c685422019-02-22 15:55:18 -080010331 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010332 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010333 if (!exactMatch) {
10334 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010335 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010336 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010337 }
joonhunshin4ac60942023-11-15 15:23:39 +000010338
10339 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10340 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10341
sqian11b7a0e2018-12-05 18:48:28 -080010342 final long identity = Binder.clearCallingIdentity();
10343 try {
sqian854d44b2018-12-12 16:48:18 -080010344 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010345 //Note: we ignore passed in param exactMatch. We can remove it once
10346 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010347 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010348 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010349 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010350 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010351 }
sqian11b7a0e2018-12-05 18:48:28 -080010352 }
10353 return false;
10354 } finally {
10355 Binder.restoreCallingIdentity(identity);
10356 }
10357 }
10358
sqianf4ca7ed2019-01-15 18:32:07 -080010359 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010360 * Start emergency callback mode for GsmCdmaPhone for testing.
10361 */
10362 @Override
10363 public void startEmergencyCallbackMode() {
10364 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10365 "startEmergencyCallbackMode");
10366 enforceModifyPermission();
10367 final long identity = Binder.clearCallingIdentity();
10368 try {
10369 for (Phone phone : PhoneFactory.getPhones()) {
10370 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10371 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10372 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10373 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10374 gsmCdmaPhone.obtainMessage(
10375 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10376 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10377 }
10378 }
10379 } finally {
10380 Binder.restoreCallingIdentity(identity);
10381 }
10382 }
10383
10384 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010385 * Update emergency number list for test mode.
10386 */
10387 @Override
10388 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10389 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10390 "updateEmergencyNumberListTestMode");
10391
10392 final long identity = Binder.clearCallingIdentity();
10393 try {
10394 for (Phone phone: PhoneFactory.getPhones()) {
10395 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10396 if (tracker != null) {
10397 tracker.executeEmergencyNumberTestModeCommand(action, num);
10398 }
10399 }
10400 } finally {
10401 Binder.restoreCallingIdentity(identity);
10402 }
10403 }
10404
10405 /**
10406 * Get the full emergency number list for test mode.
10407 */
10408 @Override
10409 public List<String> getEmergencyNumberListTestMode() {
10410 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10411 "getEmergencyNumberListTestMode");
10412
10413 final long identity = Binder.clearCallingIdentity();
10414 try {
10415 Set<String> emergencyNumbers = new HashSet<>();
10416 for (Phone phone: PhoneFactory.getPhones()) {
10417 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10418 if (tracker != null) {
10419 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10420 emergencyNumbers.add(num.getNumber());
10421 }
10422 }
10423 }
10424 return new ArrayList<>(emergencyNumbers);
10425 } finally {
10426 Binder.restoreCallingIdentity(identity);
10427 }
10428 }
10429
chen xud6b45bd2018-10-30 22:27:10 -070010430 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010431 public int getEmergencyNumberDbVersion(int subId) {
10432 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10433
joonhunshin4ac60942023-11-15 15:23:39 +000010434 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10435 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10436
Shuo Qian3b6ee772019-11-13 17:43:31 -080010437 final long identity = Binder.clearCallingIdentity();
10438 try {
10439 final Phone phone = getPhone(subId);
10440 if (phone == null) {
10441 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10442 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10443 }
10444 return phone.getEmergencyNumberDbVersion();
10445 } finally {
10446 Binder.restoreCallingIdentity(identity);
10447 }
10448 }
10449
10450 @Override
10451 public void notifyOtaEmergencyNumberDbInstalled() {
10452 enforceModifyPermission();
10453
joonhunshin4ac60942023-11-15 15:23:39 +000010454 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10455 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10456
Shuo Qian3b6ee772019-11-13 17:43:31 -080010457 final long identity = Binder.clearCallingIdentity();
10458 try {
10459 for (Phone phone: PhoneFactory.getPhones()) {
10460 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10461 if (tracker != null) {
10462 tracker.updateOtaEmergencyNumberDatabase();
10463 }
10464 }
10465 } finally {
10466 Binder.restoreCallingIdentity(identity);
10467 }
10468 }
10469
10470 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010471 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010472 enforceActiveEmergencySessionPermission();
10473
joonhunshin4ac60942023-11-15 15:23:39 +000010474 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10475 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10476
Shuo Qian3b6ee772019-11-13 17:43:31 -080010477 final long identity = Binder.clearCallingIdentity();
10478 try {
10479 for (Phone phone: PhoneFactory.getPhones()) {
10480 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10481 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010482 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10483 }
10484 }
10485 } finally {
10486 Binder.restoreCallingIdentity(identity);
10487 }
10488 }
10489
10490 @Override
10491 public void resetOtaEmergencyNumberDbFilePath() {
10492 enforceActiveEmergencySessionPermission();
10493
joonhunshin4ac60942023-11-15 15:23:39 +000010494 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10495 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10496
Shuo Qianc373f112020-03-05 17:55:34 -080010497 final long identity = Binder.clearCallingIdentity();
10498 try {
10499 for (Phone phone: PhoneFactory.getPhones()) {
10500 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10501 if (tracker != null) {
10502 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010503 }
10504 }
10505 } finally {
10506 Binder.restoreCallingIdentity(identity);
10507 }
10508 }
10509
10510 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010511 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10512 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10513 Phone phone = getPhone(subId);
10514 if (phone == null) {
10515 return null;
10516 }
10517 final long identity = Binder.clearCallingIdentity();
10518 try {
10519 UiccProfile profile = UiccController.getInstance()
10520 .getUiccProfileForPhone(phone.getPhoneId());
10521 if (profile != null) {
10522 return profile.getCertsFromCarrierPrivilegeAccessRules();
10523 }
10524 } finally {
10525 Binder.restoreCallingIdentity(identity);
10526 }
10527 return null;
10528 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010529
10530 /**
10531 * Enable or disable a modem stack.
10532 */
10533 @Override
10534 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10535 enforceModifyPermission();
10536
joonhunshin4ac60942023-11-15 15:23:39 +000010537 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10538 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10539
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010540 final long identity = Binder.clearCallingIdentity();
10541 try {
10542 Phone phone = PhoneFactory.getPhone(slotIndex);
10543 if (phone == null) {
10544 return false;
10545 } else {
10546 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10547 }
10548 } finally {
10549 Binder.restoreCallingIdentity(identity);
10550 }
10551 }
Michelecea4cf22018-12-21 15:00:11 -080010552
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010553 /**
10554 * Whether a modem stack is enabled or not.
10555 */
10556 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010557 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10558 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010559 Phone phone = PhoneFactory.getPhone(slotIndex);
10560 if (phone == null) return false;
10561
10562 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010563 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10564 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010565 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10566 }
10567
joonhunshin4ac60942023-11-15 15:23:39 +000010568 enforceTelephonyFeatureWithException(callingPackage,
10569 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10570
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010571 final long identity = Binder.clearCallingIdentity();
10572 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010573 try {
10574 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10575 } catch (NoSuchElementException ex) {
10576 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10577 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010578 } finally {
10579 Binder.restoreCallingIdentity(identity);
10580 }
10581 }
10582
Michelecea4cf22018-12-21 15:00:11 -080010583 @Override
Michele0ea7d782019-03-19 14:58:42 -070010584 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010585 enforceModifyPermission();
10586
joonhunshin4ac60942023-11-15 15:23:39 +000010587 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10588 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10589
Michelecea4cf22018-12-21 15:00:11 -080010590 final long identity = Binder.clearCallingIdentity();
10591 try {
10592 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010593 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010594 .commit();
10595 } finally {
10596 Binder.restoreCallingIdentity(identity);
10597 }
10598 }
10599
10600 @Override
Michele0ea7d782019-03-19 14:58:42 -070010601 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010602 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010604 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10605 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010606 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010607 }
Michelecea4cf22018-12-21 15:00:11 -080010608
joonhunshin4ac60942023-11-15 15:23:39 +000010609 enforceTelephonyFeatureWithException(callingPackage,
10610 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10611
Michelecea4cf22018-12-21 15:00:11 -080010612 final long identity = Binder.clearCallingIdentity();
10613 try {
Michele0ea7d782019-03-19 14:58:42 -070010614 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010615 } finally {
10616 Binder.restoreCallingIdentity(identity);
10617 }
10618 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010619
Michele0ea7d782019-03-19 14:58:42 -070010620 @TelephonyManager.IsMultiSimSupportedResult
10621 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010622 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10623 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10624 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010625 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10626 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010627 }
10628 // Check if the hardware supports multisim functionality. If usage of multisim is not
10629 // supported by the modem, indicate that it is restricted.
10630 PhoneCapability staticCapability =
10631 mPhoneConfigurationManager.getStaticPhoneCapability();
10632 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010633 loge("isMultiSimSupportedInternal: no static configuration available");
10634 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010635 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010636 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010637 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10638 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010639 }
10640 // Check if support of multiple SIMs is restricted by carrier
10641 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010642 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010643 }
10644
Michele0ea7d782019-03-19 14:58:42 -070010645 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010646 }
10647
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010648 /**
10649 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010650 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10651 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10652 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010653 * @param numOfSims number of active sims we want to switch to
10654 */
10655 @Override
10656 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010657 if (numOfSims == 1) {
10658 enforceModifyPermission();
10659 } else {
10660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10661 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10662 }
joonhunshin4ac60942023-11-15 15:23:39 +000010663
10664 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10665 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10666
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010667 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010668
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010669 try {
Michele30b57b22019-03-01 12:01:14 -080010670 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010671 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010672 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10673 return;
10674 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010675 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10676 } finally {
10677 Binder.restoreCallingIdentity(identity);
10678 }
10679 }
10680
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010681 @Override
10682 public boolean isApplicationOnUicc(int subId, int appType) {
10683 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010684
10685 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10686 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10687
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010688 Phone phone = getPhone(subId);
10689 if (phone == null) {
10690 return false;
10691 }
10692 final long identity = Binder.clearCallingIdentity();
10693 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010694 UiccPort uiccPort = phone.getUiccPort();
10695 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010696 return false;
10697 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010698 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010699 if (uiccProfile == null) {
10700 return false;
10701 }
10702 if (TelephonyManager.APPTYPE_SIM <= appType
10703 && appType <= TelephonyManager.APPTYPE_ISIM) {
10704 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10705 }
10706 return false;
10707 } finally {
10708 Binder.restoreCallingIdentity(identity);
10709 }
10710 }
10711
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010712 /**
chen xub4baa772019-04-03 10:23:41 -070010713 * Get whether making changes to modem configurations will trigger reboot.
10714 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010715 */
10716 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010717 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10718 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010720 mApp, subId, callingPackage, callingFeatureId,
10721 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010722 return false;
10723 }
joonhunshin4ac60942023-11-15 15:23:39 +000010724
10725 enforceTelephonyFeatureWithException(callingPackage,
10726 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10727 "doesSwitchMultiSimConfigTriggerReboot");
10728
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010729 final long identity = Binder.clearCallingIdentity();
10730 try {
10731 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10732 } finally {
10733 Binder.restoreCallingIdentity(identity);
10734 }
10735 }
10736
Nathan Harold29f5f052019-02-15 13:41:57 -080010737 private void updateModemStateMetrics() {
10738 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10739 // TODO: check the state for each modem if the api is ready.
10740 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10741 }
10742
Pengquan Meng3889a572019-01-23 11:16:29 -080010743 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010744 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010745 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010746 // Verify that the callingPackage belongs to the calling UID
10747 mApp.getSystemService(AppOpsManager.class)
10748 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010749
10750 enforceTelephonyFeatureWithException(callingPackage,
10751 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10752
Pengquan Meng3889a572019-01-23 11:16:29 -080010753 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010754 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010755 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010756 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10757 if (slotInfos != null) {
10758 for (int i = 0; i < slotInfos.length; i++) {
10759 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10760 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10761 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10762 portInfo.getLogicalSlotIndex()));
10763 }
10764 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010765 }
10766 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010767 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010768 } finally {
10769 Binder.restoreCallingIdentity(identity);
10770 }
10771 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010772
10773 /**
10774 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010775 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010776 */
jimsunf9ec1622022-09-13 21:18:43 +080010777 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010778 @Override
10779 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010780 return getHalVersion(HAL_SERVICE_RADIO);
10781 }
10782
10783 /**
10784 * Get the HAL Version of a specific service
10785 */
10786 @Override
10787 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010788 Phone phone = getDefaultPhone();
10789 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010790 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010791 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10792 return hv.major * 100 + hv.minor;
10793 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010794
10795 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010796 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010797 *
10798 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010799 */
10800 @Override
sangyun097dcf72024-01-04 10:35:49 +090010801 public @Nullable String getCurrentPackageName() {
10802 PackageManager pm = mApp.getPackageManager();
10803 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10804 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010805 }
10806
10807 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010808 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10809 * corresponding network requests on a subId.
10810 *
10811 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010812 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010813 * 2) APN is un-metered for this subscription, or
10814 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010815 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010816 *
10817 * @return whether data is allowed for a apn type.
10818 *
10819 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010820 */
10821 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010822 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010823 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10824 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010825
joonhunshin4ac60942023-11-15 15:23:39 +000010826 enforceTelephonyFeatureWithException(callingPackage,
10827 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10828
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010829 // Now that all security checks passes, perform the operation as ourselves.
10830 final long identity = Binder.clearCallingIdentity();
10831 try {
10832 Phone phone = getPhone(subId);
10833 if (phone == null) return false;
10834
Jack Yu27422a52022-03-21 10:38:05 -070010835 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010836 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010837 isMetered = phone.getDataNetworkController().getDataConfigManager()
10838 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10839 phone.getServiceState().getDataRoaming());
10840 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010841 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
10846
10847 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010848 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010849 enforceReadPrivilegedPermission("isApnMetered");
10850
joonhunshin4ac60942023-11-15 15:23:39 +000010851 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10852 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10853
Malcolm Chene5ad5792019-04-18 13:51:02 -070010854 // Now that all security checks passes, perform the operation as ourselves.
10855 final long identity = Binder.clearCallingIdentity();
10856 try {
10857 Phone phone = getPhone(subId);
10858 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010859 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10860 DataUtils.apnTypeToNetworkCapability(apnType),
10861 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010862 } finally {
10863 Binder.restoreCallingIdentity(identity);
10864 }
10865 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010866
10867 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010868 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10869 int subscriptionId, IBooleanConsumer resultCallback) {
10870 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010871
10872 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10873 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10874
Hall Liu73f5d362020-01-20 13:42:00 -080010875 long token = Binder.clearCallingIdentity();
10876 try {
10877 Phone phone = getPhone(subscriptionId);
10878 if (phone == null) {
10879 try {
10880 if (resultCallback != null) {
10881 resultCallback.accept(false);
10882 }
10883 } catch (RemoteException e) {
10884 // ignore
10885 }
10886 return;
10887 }
10888 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10889 Pair.create(specifiers, (x) -> {
10890 try {
10891 if (resultCallback != null) {
10892 resultCallback.accept(x);
10893 }
10894 } catch (RemoteException e) {
10895 // ignore
10896 }
10897 });
10898 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10899 } finally {
10900 Binder.restoreCallingIdentity(token);
10901 }
10902 }
10903
10904 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010905 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10906 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010907 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010908 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010909
10910 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10911 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10912
Sarah Chin679c08a2020-11-18 13:39:35 -080010913 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10914 final long identity = Binder.clearCallingIdentity();
10915 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010916 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10917 if (result instanceof IllegalStateException) {
10918 throw (IllegalStateException) result;
10919 }
10920 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010921 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10922 return specifiers;
10923 } finally {
10924 Binder.restoreCallingIdentity(identity);
10925 }
10926 }
10927
10928 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010929 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010930 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010931
10932 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10933 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10934
Jack Yu8b766fc2022-03-21 09:42:33 -070010935 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010936 }
10937
10938 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010939 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10940 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010941 if (callingPackage == null) {
10942 callingPackage = getCurrentPackageName();
10943 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010944 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10945 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010946 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10947 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010948 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10949 }
10950 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10951 Intent intent = new Intent();
10952 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10953 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10954 // Bring up choose default SMS subscription dialog right now
10955 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10956 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10957 mApp.startActivity(intent);
10958 }
chen xud5ca2d52019-05-28 15:20:57 -070010959
10960 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010961 public void showSwitchToManagedProfileDialog() {
10962 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010963 try {
10964 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10965 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10966 // for work telephony.
10967 Intent intent = new Intent(Intent.ACTION_SENDTO);
10968 intent.setData(Uri.parse("smsto:"));
10969 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10970 mApp.startActivity(intent);
10971 } catch (ActivityNotFoundException e) {
10972 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10973 Intent intent = new Intent();
10974 intent.setClass(mApp, ErrorDialogActivity.class);
10975 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10976 mApp.startActivity(intent);
10977 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010978 }
10979
10980 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010981 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010982 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10983 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10984
chen xud5ca2d52019-05-28 15:20:57 -070010985 //TODO investigate if this API should require proper permission check in R b/133791609
10986 final long identity = Binder.clearCallingIdentity();
10987 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010988 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10989 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10990 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10991 return carrierUAProfUrl;
10992 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010993 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10994 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010995 } finally {
10996 Binder.restoreCallingIdentity(identity);
10997 }
10998 }
10999
11000 @Override
11001 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011002 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11003 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11004
chen xud5ca2d52019-05-28 15:20:57 -070011005 //TODO investigate if this API should require proper permission check in R b/133791609
11006 final long identity = Binder.clearCallingIdentity();
11007 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011008 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11009 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11010 if (!TextUtils.isEmpty(carrierUserAgent)) {
11011 return carrierUserAgent;
11012 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011013 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11014 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011015 } finally {
11016 Binder.restoreCallingIdentity(identity);
11017 }
11018 }
Jack Yub07d4972019-05-28 16:12:25 -070011019
11020 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011021 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11022 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011023
joonhunshin4ac60942023-11-15 15:23:39 +000011024 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11025 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11026
Jack Yub07d4972019-05-28 16:12:25 -070011027 final long identity = Binder.clearCallingIdentity();
11028 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011029 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011030 if (phone == null) return false;
11031
Ling Maf188d502022-09-16 15:22:36 -070011032 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011033 } finally {
11034 Binder.restoreCallingIdentity(identity);
11035 }
11036 }
11037
11038 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011039 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011040 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011041 enforceModifyPermission();
11042
joonhunshin4ac60942023-11-15 15:23:39 +000011043 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11044 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11045
changbettyd5c246e2019-12-24 15:40:37 +080011046 final long identity = Binder.clearCallingIdentity();
11047 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011048 Phone phone = getPhone(subscriptionId);
11049 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011050
Ling Maf188d502022-09-16 15:22:36 -070011051 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011052 } finally {
11053 Binder.restoreCallingIdentity(identity);
11054 }
11055 }
11056
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011057 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011058 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011059 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11060 * otherwise.
11061 */
11062 @Override
11063 public void setCepEnabled(boolean isCepEnabled) {
11064 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11065
11066 final long identity = Binder.clearCallingIdentity();
11067 try {
11068 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11069 for (Phone phone : PhoneFactory.getPhones()) {
11070 Phone defaultPhone = phone.getImsPhone();
11071 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11072 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11073 ImsPhoneCallTracker imsPhoneCallTracker =
11074 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11075 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11076 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11077 + imsPhone.getMsisdn());
11078 }
11079 }
11080 } finally {
11081 Binder.restoreCallingIdentity(identity);
11082 }
11083 }
allenwtsu46dcc572020-01-08 18:24:03 +080011084
11085 /**
11086 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11087 *
11088 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11089 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11090 * before being read.
11091 */
11092 @Override
11093 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11094 isCompressed) {
11095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11096 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011097 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11098 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11099 }
joonhunshin4ac60942023-11-15 15:23:39 +000011100
11101 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11102 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11103 Binder.getCallingUserHandle())) {
11104 if (!isImsAvailableOnDevice()) {
11105 // ProvisioningManager can not handle ServiceSpecificException.
11106 // Throw the IllegalStateException and annotate ProvisioningManager.
11107 throw new IllegalStateException("IMS not available on device.");
11108 }
11109 } else {
11110 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11111 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11112 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011113 }
11114
11115 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011116 try {
Hui Wang761a6682020-10-31 05:12:53 +000011117 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11118 } finally {
11119 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011120 }
11121 }
zoey chene02881a2019-12-30 16:11:23 +080011122
11123 @Override
11124 public boolean isIccLockEnabled(int subId) {
11125 enforceReadPrivilegedPermission("isIccLockEnabled");
11126
joonhunshin4ac60942023-11-15 15:23:39 +000011127 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11128 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11129
zoey chene02881a2019-12-30 16:11:23 +080011130 // Now that all security checks passes, perform the operation as ourselves.
11131 final long identity = Binder.clearCallingIdentity();
11132 try {
11133 Phone phone = getPhone(subId);
11134 if (phone != null && phone.getIccCard() != null) {
11135 return phone.getIccCard().getIccLockEnabled();
11136 } else {
11137 return false;
11138 }
11139 } finally {
11140 Binder.restoreCallingIdentity(identity);
11141 }
11142 }
11143
11144 /**
11145 * Set the ICC pin lock enabled or disabled.
11146 *
11147 * @return an integer representing the status of IccLock enabled or disabled in the following
11148 * three cases:
11149 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11150 * successfully.
11151 * - Positive number and zero for remaining password attempts.
11152 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11153 *
11154 */
11155 @Override
11156 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11157 enforceModifyPermission();
11158
joonhunshin4ac60942023-11-15 15:23:39 +000011159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11160 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11161
zoey chene02881a2019-12-30 16:11:23 +080011162 Phone phone = getPhone(subId);
11163 if (phone == null) {
11164 return 0;
11165 }
11166 // Now that all security checks passes, perform the operation as ourselves.
11167 final long identity = Binder.clearCallingIdentity();
11168 try {
11169 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11170 new Pair<Boolean, String>(enabled, password), phone, null);
11171 return attemptsRemaining;
11172
11173 } catch (Exception e) {
11174 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11175 } finally {
11176 Binder.restoreCallingIdentity(identity);
11177 }
11178 return 0;
11179 }
11180
11181 /**
11182 * Change the ICC password used in ICC pin lock.
11183 *
11184 * @return an integer representing the status of IccLock changed in the following three cases:
11185 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11186 * - Positive number and zero for remaining password attempts.
11187 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11188 *
11189 */
11190 @Override
11191 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11192 enforceModifyPermission();
11193
joonhunshin4ac60942023-11-15 15:23:39 +000011194 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11195 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11196
zoey chene02881a2019-12-30 16:11:23 +080011197 Phone phone = getPhone(subId);
11198 if (phone == null) {
11199 return 0;
11200 }
11201 // Now that all security checks passes, perform the operation as ourselves.
11202 final long identity = Binder.clearCallingIdentity();
11203 try {
11204 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11205 new Pair<String, String>(oldPassword, newPassword), phone, null);
11206 return attemptsRemaining;
11207
11208 } catch (Exception e) {
11209 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11210 } finally {
11211 Binder.restoreCallingIdentity(identity);
11212 }
11213 return 0;
11214 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011215
11216 /**
11217 * Request for receiving user activity notification
11218 */
11219 @Override
11220 public void requestUserActivityNotification() {
11221 if (!mNotifyUserActivity.get()
11222 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11223 mNotifyUserActivity.set(true);
11224 }
11225 }
11226
11227 /**
11228 * Called when userActivity is signalled in the power manager.
11229 * This is safe to call from any thread, with any window manager locks held or not.
11230 */
11231 @Override
11232 public void userActivity() {
11233 // ***************************************
11234 // * Inherited from PhoneWindowManager *
11235 // ***************************************
11236 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11237 // WITH ITS LOCKS HELD.
11238 //
11239 // This code must be VERY careful about the locks
11240 // it acquires.
11241 // In fact, the current code acquires way too many,
11242 // and probably has lurking deadlocks.
11243
11244 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11245 throw new SecurityException("Only the OS may call notifyUserActivity()");
11246 }
11247
11248 if (mNotifyUserActivity.getAndSet(false)) {
11249 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11250 USER_ACTIVITY_NOTIFICATION_DELAY);
11251 }
11252 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011253
11254 @Override
11255 public boolean canConnectTo5GInDsdsMode() {
11256 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11257 }
Jack Yud10cdd42020-09-28 20:28:01 -070011258
11259 @Override
11260 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11261 String callingFeatureId) {
11262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11263 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11264 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11265 }
11266
joonhunshin4ac60942023-11-15 15:23:39 +000011267 enforceTelephonyFeatureWithException(callingPackage,
11268 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11269
Jack Yud10cdd42020-09-28 20:28:01 -070011270 Phone phone = getPhone(subId);
11271 if (phone == null) {
11272 throw new RuntimeException("phone is not available");
11273 }
11274 // Now that all security checks passes, perform the operation as ourselves.
11275 final long identity = Binder.clearCallingIdentity();
11276 try {
11277 return phone.getEquivalentHomePlmns();
11278 } finally {
11279 Binder.restoreCallingIdentity(identity);
11280 }
11281 }
Daniel Bright59e67312020-11-13 11:49:37 -080011282
11283 @Override
11284 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011285 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011286 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11287 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11288 "isRadioInterfaceCapabilitySupported");
11289
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011290 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011291 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011292 if (radioInterfaceCapabilities == null) {
11293 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011294 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011295 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011296 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011297
Hui Wang641e81c2020-10-12 12:14:23 -070011298 @Override
11299 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11300 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011301 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11302 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11303 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11304 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11305 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011306
11307 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11308 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11309
Hui Wang641e81c2020-10-12 12:14:23 -070011310 if (DBG) {
11311 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11312 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11313 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11314 }
11315
11316 if (!SubscriptionManager.isValidSubscriptionId(subId)
11317 || appType < TelephonyManager.APPTYPE_UNKNOWN
11318 || appType > TelephonyManager.APPTYPE_ISIM
11319 || nafUrl == null || securityProtocol == null || callback == null) {
11320 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11321 if (callback != null) {
11322 try {
11323 callback.onAuthenticationFailure(
11324 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11325 } catch (RemoteException exception) {
11326 log("Fail to notify onAuthenticationFailure due to " + exception);
11327 }
11328 return;
11329 }
11330 }
11331
11332 final long token = Binder.clearCallingIdentity();
11333 try {
11334 getGbaManager(subId).bootstrapAuthenticationRequest(
11335 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011336 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011337 } finally {
11338 Binder.restoreCallingIdentity(token);
11339 }
11340 }
11341
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011342 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011343 * Attempts to set the radio power state for all phones for thermal reason.
11344 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011345 * requested radio power state will actually be set. See {@link
11346 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11347 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011348 * @param enable {@code true} if trying to turn radio on.
11349 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11350 * false}.
11351 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011352 private boolean setRadioPowerForThermal(boolean enable) {
11353 boolean isPhoneAvailable = false;
11354 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11355 Phone phone = PhoneFactory.getPhone(i);
11356 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011357 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011358 isPhoneAvailable = true;
11359 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011360 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011361
11362 // return true if successfully informed the phone object about the thermal radio power
11363 // request.
11364 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011365 }
11366
11367 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011368 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011369 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11370 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11371 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11372 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11373 throw new IllegalArgumentException("modem does not support data throttling");
11374 }
11375
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011376 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11377 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011378 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011379 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11380 }
11381
Sarah Chinecc78c42022-03-31 21:16:48 -070011382 setDataEnabledForReason(
11383 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011384
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011385 if (isDataThrottlingSupported) {
11386 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011387 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011388 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11389 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11390 } else if (thermalMitigationResult
11391 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011392 log("Modem likely does not support data throttling on secondary carrier. Data " +
11393 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11394 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011395 }
11396 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011397 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011398
11399 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011400 }
11401
Jack Nudelman644b91a2021-03-12 14:09:48 -080011402 private static List<String> getThermalMitigationAllowlist(Context context) {
11403 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11404 for (String pckg : context.getResources()
11405 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11406 sThermalMitigationAllowlistedPackages.add(pckg);
11407 }
11408 }
11409
11410 return sThermalMitigationAllowlistedPackages;
11411 }
11412
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011413 private boolean isAnyPhoneInEmergencyState() {
11414 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11415 if (tm.isInEmergencyCall()) {
11416 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11417 return true;
11418 }
11419 for (Phone phone : PhoneFactory.getPhones()) {
11420 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11421 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011422 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11423 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011424 return true;
11425 }
11426 }
11427
11428 return false;
11429 }
11430
Jack Nudelman644b91a2021-03-12 14:09:48 -080011431 /**
11432 * Used by shell commands to add an authorized package name for thermal mitigation.
11433 * @param packageName name of package to be allowlisted
11434 * @param context
11435 */
11436 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11437 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11438 sThermalMitigationAllowlistedPackages.add(packageName);
11439 }
11440
11441 /**
11442 * Used by shell commands to remove an authorized package name for thermal mitigation.
11443 * @param packageName name of package to remove from allowlist
11444 * @param context
11445 */
11446 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11447 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11448 sThermalMitigationAllowlistedPackages.remove(packageName);
11449 }
11450
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011451 /**
11452 * Thermal mitigation request to control functionalities at modem.
11453 *
11454 * @param subId the id of the subscription.
11455 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011456 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011457 *
11458 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11459 */
11460 @Override
11461 @ThermalMitigationResult
11462 public int sendThermalMitigationRequest(
11463 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011464 ThermalMitigationRequest thermalMitigationRequest,
11465 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011466 enforceModifyPermission();
11467
Jack Nudelman644b91a2021-03-12 14:09:48 -080011468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011469
11470 enforceTelephonyFeatureWithException(callingPackage,
11471 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11472
Jack Nudelman644b91a2021-03-12 14:09:48 -080011473 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11474 .contains(callingPackage)) {
11475 throw new SecurityException("Calling package must be configured in the device config. "
11476 + "calling package: " + callingPackage);
11477 }
11478
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011479 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11480 final long identity = Binder.clearCallingIdentity();
11481
11482 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11483 try {
11484 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11485 switch (thermalMitigationAction) {
11486 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11487 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011488 handleDataThrottlingRequest(subId,
11489 thermalMitigationRequest.getDataThrottlingRequest(),
11490 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011491 break;
11492 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11493 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11494 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11495 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11496 }
11497
11498 // Ensure that radio is on. If not able to power on due to phone being
11499 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011500 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011501 thermalMitigationResult =
11502 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11503 break;
11504 }
11505
11506 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011507 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011508 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11509 break;
11510 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11511 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11512 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11513 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11514 }
11515
11516 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11517 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011518 Phone phone = getPhone(subId);
11519 if (phone == null) {
11520 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011521 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011522 break;
11523 }
11524
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011525 TelephonyConnectionService service =
11526 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011527 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011528 Log.e(LOG_TAG, "An emergency call is pending");
11529 thermalMitigationResult =
11530 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11531 break;
11532 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011533 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011534 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011535 break;
11536 }
11537 } else {
11538 thermalMitigationResult =
11539 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11540 break;
11541 }
11542
11543 // Turn radio off. If not able to power off due to phone being unavailable,
11544 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011545 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011546 thermalMitigationResult =
11547 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11548 break;
11549 }
11550 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011551 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011552 break;
11553 default:
11554 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11555 + "not exist. Requested action: " + thermalMitigationAction);
11556 }
11557 } catch (IllegalArgumentException e) {
11558 throw e;
11559 } catch (Exception e) {
11560 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11561 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11562 } finally {
11563 Binder.restoreCallingIdentity(identity);
11564 }
11565
11566 if (DBG) {
11567 log("thermalMitigationRequest returning with thermalMitigationResult: "
11568 + thermalMitigationResult);
11569 }
11570
11571 return thermalMitigationResult;
11572 }
Hui Wang641e81c2020-10-12 12:14:23 -070011573
11574 /**
11575 * Set the GbaService Package Name that Telephony will bind to.
11576 *
11577 * @param subId The sim that the GbaService is associated with.
11578 * @param packageName The name of the package to be replaced with.
11579 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11580 */
11581 @Override
11582 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11583 enforceModifyPermission();
11584
11585 final long identity = Binder.clearCallingIdentity();
11586 try {
11587 return getGbaManager(subId).overrideServicePackage(packageName);
11588 } finally {
11589 Binder.restoreCallingIdentity(identity);
11590 }
11591 }
11592
11593 /**
11594 * Return the package name of the currently bound GbaService.
11595 *
11596 * @param subId The sim that the GbaService is associated with.
11597 * @return the package name of the GbaService configuration, null if GBA is not supported.
11598 */
11599 @Override
11600 public String getBoundGbaService(int subId) {
11601 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11602
11603 final long identity = Binder.clearCallingIdentity();
11604 try {
11605 return getGbaManager(subId).getServicePackage();
11606 } finally {
11607 Binder.restoreCallingIdentity(identity);
11608 }
11609 }
11610
11611 /**
11612 * Set the release time for telephony to unbind GbaService.
11613 *
11614 * @param subId The sim that the GbaService is associated with.
11615 * @param interval The release time to unbind GbaService by millisecond.
11616 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11617 */
11618 @Override
11619 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11620 enforceModifyPermission();
11621
11622 final long identity = Binder.clearCallingIdentity();
11623 try {
11624 return getGbaManager(subId).overrideReleaseTime(interval);
11625 } finally {
11626 Binder.restoreCallingIdentity(identity);
11627 }
11628 }
11629
11630 /**
11631 * Return the release time for telephony to unbind GbaService.
11632 *
11633 * @param subId The sim that the GbaService is associated with.
11634 * @return The release time to unbind GbaService by millisecond.
11635 */
11636 @Override
11637 public int getGbaReleaseTime(int subId) {
11638 enforceReadPrivilegedPermission("getGbaReleaseTime");
11639
11640 final long identity = Binder.clearCallingIdentity();
11641 try {
11642 return getGbaManager(subId).getReleaseTime();
11643 } finally {
11644 Binder.restoreCallingIdentity(identity);
11645 }
11646 }
11647
11648 private GbaManager getGbaManager(int subId) {
11649 GbaManager instance = GbaManager.getInstance(subId);
11650 if (instance == null) {
11651 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11652 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11653 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11654 }
11655 return instance;
11656 }
Hui Wang761a6682020-10-31 05:12:53 +000011657
11658 /**
11659 * indicate whether the device and the carrier can support
11660 * RCS VoLTE single registration.
11661 */
11662 @Override
11663 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011664 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11665 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11666 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11667 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011668
11669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11670 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11671 }
11672
11673 final long identity = Binder.clearCallingIdentity();
11674 try {
11675 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11676 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011677 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11678 if (isCapable != null) {
11679 return isCapable;
11680 }
Hui Wang761a6682020-10-31 05:12:53 +000011681 }
Hui Wang67af90e2021-06-04 16:57:15 -070011682 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11683 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011684 } finally {
11685 Binder.restoreCallingIdentity(identity);
11686 }
11687 }
11688
11689 /**
11690 * Register RCS provisioning callback.
11691 */
11692 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011693 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011694 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011695 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011696 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011697 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11698 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011699
11700 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11701 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11702 }
joonhunshin4ac60942023-11-15 15:23:39 +000011703 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11704 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11705 Binder.getCallingUserHandle())) {
11706 if (!isImsAvailableOnDevice()) {
11707 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11708 "IMS not available on device.");
11709 }
11710 } else {
11711 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11712 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011713 }
11714
11715 final long identity = Binder.clearCallingIdentity();
11716 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011717 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011718 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011719 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11720 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011721 }
Hui Wang761a6682020-10-31 05:12:53 +000011722 } finally {
11723 Binder.restoreCallingIdentity(identity);
11724 }
11725 }
11726
11727 /**
11728 * Unregister RCS provisioning callback.
11729 */
11730 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011731 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011732 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011733 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011734 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011735 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11736 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011737
11738 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11739 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11740 }
joonhunshin4ac60942023-11-15 15:23:39 +000011741
11742 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11743 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11744 Binder.getCallingUserHandle())) {
11745 if (!isImsAvailableOnDevice()) {
11746 // operation failed silently
11747 Rlog.w(LOG_TAG, "IMS not available on device.");
11748 return;
11749 }
11750 } else {
11751 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11752 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11753 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011754 }
11755
11756 final long identity = Binder.clearCallingIdentity();
11757 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011758 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011759 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011760 } finally {
11761 Binder.restoreCallingIdentity(identity);
11762 }
11763 }
11764
11765 /**
11766 * trigger RCS reconfiguration.
11767 */
11768 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011769 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11770 "triggerRcsReconfiguration",
11771 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011772
11773 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11774 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11775 }
joonhunshin4ac60942023-11-15 15:23:39 +000011776 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11777 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11778 Binder.getCallingUserHandle())) {
11779 if (!isImsAvailableOnDevice()) {
11780 // ProvisioningManager can not handle ServiceSpecificException.
11781 // Throw the IllegalStateException and annotate ProvisioningManager.
11782 throw new IllegalStateException("IMS not available on device.");
11783 }
11784 } else {
11785 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11786 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011787 }
11788
11789 final long identity = Binder.clearCallingIdentity();
11790 try {
11791 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11792 } finally {
11793 Binder.restoreCallingIdentity(identity);
11794 }
11795 }
11796
11797 /**
11798 * Provide the client configuration parameters of the RCS application.
11799 */
11800 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011801 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11802 "setRcsClientConfiguration",
11803 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011804
11805 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11806 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11807 }
joonhunshin4ac60942023-11-15 15:23:39 +000011808 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11809 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11810 Binder.getCallingUserHandle())) {
11811 if (!isImsAvailableOnDevice()) {
11812 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11813 "IMS not available on device.");
11814 }
11815 } else {
11816 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11817 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011818 }
11819
11820 final long identity = Binder.clearCallingIdentity();
11821
11822 try {
11823 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11824 if (configBinder == null) {
11825 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011826 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11827 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011828 } else {
11829 configBinder.setRcsClientConfiguration(rcc);
11830 }
joonhunshin3e154242021-09-17 06:33:39 +000011831
11832 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11833 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011834 } catch (RemoteException e) {
11835 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011836 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11837 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011838 } finally {
11839 Binder.restoreCallingIdentity(identity);
11840 }
11841 }
11842
11843 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011844 * Enables or disables the test mode for RCS VoLTE single registration.
11845 */
11846 @Override
11847 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11848 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11849 "setRcsSingleRegistrationTestModeEnabled");
11850
11851 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11852 }
11853
11854 /**
11855 * Gets the test mode for RCS VoLTE single registration.
11856 */
11857 @Override
11858 public boolean getRcsSingleRegistrationTestModeEnabled() {
11859 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11860 "getRcsSingleRegistrationTestModeEnabled");
11861
11862 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11863 }
11864
11865 /**
Hui Wang761a6682020-10-31 05:12:53 +000011866 * Overrides the config of RCS VoLTE single registration enabled for the device.
11867 */
11868 @Override
11869 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11870 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11871 "setDeviceSingleRegistrationEnabledOverride");
11872 enforceModifyPermission();
11873
11874 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11875 : Boolean.parseBoolean(enabledStr);
11876 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011877 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011878 }
11879
11880 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011881 * Sends a device to device communication message. Only usable via shell.
11882 * @param message message to send.
11883 * @param value message value.
11884 */
11885 @Override
11886 public void sendDeviceToDeviceMessage(int message, int value) {
11887 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011888 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011889 enforceModifyPermission();
11890
11891 final long identity = Binder.clearCallingIdentity();
11892 try {
11893 TelephonyConnectionService service =
11894 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11895 if (service == null) {
11896 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11897 return;
11898 }
11899 service.sendTestDeviceToDeviceMessage(message, value);
11900 } finally {
11901 Binder.restoreCallingIdentity(identity);
11902 }
11903 }
11904
Tyler Gunnbabbda02021-02-10 11:05:02 -080011905 /**
11906 * Sets the specified device to device transport active.
11907 * @param transport The transport to set active.
11908 */
11909 @Override
11910 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11912 "setActiveDeviceToDeviceTransport");
11913 enforceModifyPermission();
11914
11915 final long identity = Binder.clearCallingIdentity();
11916 try {
11917 TelephonyConnectionService service =
11918 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11919 if (service == null) {
11920 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11921 return;
11922 }
11923 service.setActiveDeviceToDeviceTransport(transport);
11924 } finally {
11925 Binder.restoreCallingIdentity(identity);
11926 }
11927 }
Tyler Gunn92479152021-01-20 16:30:10 -080011928
Tyler Gunnd4339262021-05-03 14:46:49 -070011929 @Override
11930 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11931 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11932 "setDeviceToDeviceForceEnabled");
11933
11934 final long identity = Binder.clearCallingIdentity();
11935 try {
11936 Arrays.stream(PhoneFactory.getPhones()).forEach(
11937 p -> {
11938 Phone thePhone = p.getImsPhone();
11939 if (thePhone != null && thePhone instanceof ImsPhone) {
11940 ImsPhone imsPhone = (ImsPhone) thePhone;
11941 CallTracker tracker = imsPhone.getCallTracker();
11942 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11943 ImsPhoneCallTracker imsPhoneCallTracker =
11944 (ImsPhoneCallTracker) tracker;
11945 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11946 }
11947 }
11948 }
11949 );
11950 } finally {
11951 Binder.restoreCallingIdentity(identity);
11952 }
11953 }
11954
Tyler Gunn92479152021-01-20 16:30:10 -080011955 /**
Hui Wang761a6682020-10-31 05:12:53 +000011956 * Gets the config of RCS VoLTE single registration enabled for the device.
11957 */
11958 @Override
11959 public boolean getDeviceSingleRegistrationEnabled() {
11960 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11961 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11962 }
11963
11964 /**
11965 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11966 */
11967 @Override
11968 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11969 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11970 "setCarrierSingleRegistrationEnabledOverride");
11971 enforceModifyPermission();
11972
11973 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11974 : Boolean.parseBoolean(enabledStr);
11975 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11976 subId, enabled);
11977 }
11978
11979 /**
11980 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11981 */
11982 @Override
11983 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11984 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11985 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11986 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011987
11988 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011989 * Overrides the ims feature validation result
11990 */
11991 @Override
11992 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11994 "setImsFeatureValidationOverride");
11995
11996 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11997 : Boolean.parseBoolean(enabledStr);
11998 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11999 subId, enabled);
12000 }
12001
12002 /**
12003 * Gets the ims feature validation override value
12004 */
12005 @Override
12006 public boolean getImsFeatureValidationOverride(int subId) {
12007 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12008 "getImsFeatureValidationOverride");
12009 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12010 }
12011
12012 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012013 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12014 * their mobile plan.
12015 */
12016 @Override
12017 public String getMobileProvisioningUrl() {
12018 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12019 final long identity = Binder.clearCallingIdentity();
12020 try {
12021 return getDefaultPhone().getMobileProvisioningUrl();
12022 } finally {
12023 Binder.restoreCallingIdentity(identity);
12024 }
12025 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012026
James.cf Linbcdf8b32021-01-14 16:44:13 +080012027 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012028 * Get the EAB contact from the EAB database.
12029 */
12030 @Override
12031 public String getContactFromEab(String contact) {
12032 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12033 enforceModifyPermission();
12034 final long identity = Binder.clearCallingIdentity();
12035 try {
12036 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12037 } finally {
12038 Binder.restoreCallingIdentity(identity);
12039 }
12040 }
12041
12042 /**
Calvin Pana1434322021-07-01 19:27:01 +080012043 * Get the EAB capability from the EAB database.
12044 */
12045 @Override
12046 public String getCapabilityFromEab(String contact) {
12047 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12048 enforceModifyPermission();
12049 final long identity = Binder.clearCallingIdentity();
12050 try {
12051 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12052 } finally {
12053 Binder.restoreCallingIdentity(identity);
12054 }
12055 }
12056
12057 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012058 * Remove the EAB contacts from the EAB database.
12059 */
12060 @Override
12061 public int removeContactFromEab(int subId, String contacts) {
12062 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12063 enforceModifyPermission();
12064 final long identity = Binder.clearCallingIdentity();
12065 try {
12066 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12067 } finally {
12068 Binder.restoreCallingIdentity(identity);
12069 }
12070 }
12071
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012072 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012073 public boolean getDeviceUceEnabled() {
12074 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12075 final long identity = Binder.clearCallingIdentity();
12076 try {
12077 return mApp.getDeviceUceEnabled();
12078 } finally {
12079 Binder.restoreCallingIdentity(identity);
12080 }
12081 }
12082
12083 @Override
12084 public void setDeviceUceEnabled(boolean isEnabled) {
12085 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12086 final long identity = Binder.clearCallingIdentity();
12087 try {
12088 mApp.setDeviceUceEnabled(isEnabled);
12089 } finally {
12090 Binder.restoreCallingIdentity(identity);
12091 }
12092 }
12093
Brad Ebinger14d467f2021-02-12 06:18:28 +000012094 /**
12095 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12096 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12097 */
12098 // Used for SHELL command only right now.
12099 @Override
12100 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12101 List<String> featureTags) {
12102 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12103 "addUceRegistrationOverrideShell");
12104 final long identity = Binder.clearCallingIdentity();
12105 try {
12106 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12107 new ArraySet<>(featureTags));
12108 } catch (ImsException e) {
12109 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12110 } finally {
12111 Binder.restoreCallingIdentity(identity);
12112 }
12113 }
12114
12115 /**
12116 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12117 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12118 */
12119 // Used for SHELL command only right now.
12120 @Override
12121 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12122 List<String> featureTags) {
12123 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12124 "removeUceRegistrationOverrideShell");
12125 final long identity = Binder.clearCallingIdentity();
12126 try {
12127 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12128 new ArraySet<>(featureTags));
12129 } catch (ImsException e) {
12130 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12131 } finally {
12132 Binder.restoreCallingIdentity(identity);
12133 }
12134 }
12135
12136 /**
12137 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12138 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12139 */
12140 // Used for SHELL command only right now.
12141 @Override
12142 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12143 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12144 "clearUceRegistrationOverrideShell");
12145 final long identity = Binder.clearCallingIdentity();
12146 try {
12147 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12148 } catch (ImsException e) {
12149 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12150 } finally {
12151 Binder.restoreCallingIdentity(identity);
12152 }
12153 }
12154
12155 /**
12156 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12157 */
12158 // Used for SHELL command only right now.
12159 @Override
12160 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12161 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12162 "getLatestRcsContactUceCapabilityShell");
12163 final long identity = Binder.clearCallingIdentity();
12164 try {
12165 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12166 } catch (ImsException e) {
12167 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12168 } finally {
12169 Binder.restoreCallingIdentity(identity);
12170 }
12171 }
12172
12173 /**
12174 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12175 * device does not have an active PUBLISH.
12176 */
12177 // Used for SHELL command only right now.
12178 @Override
12179 public String getLastUcePidfXmlShell(int subId) {
12180 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12181 final long identity = Binder.clearCallingIdentity();
12182 try {
12183 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12184 } catch (ImsException e) {
12185 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12186 } finally {
12187 Binder.restoreCallingIdentity(identity);
12188 }
12189 }
12190
James.cf Line8713a42021-04-29 16:04:26 +080012191 /**
12192 * Remove UCE requests cannot be sent to the network status.
12193 */
12194 // Used for SHELL command only right now.
12195 @Override
12196 public boolean removeUceRequestDisallowedStatus(int subId) {
12197 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12198 final long identity = Binder.clearCallingIdentity();
12199 try {
12200 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12201 } catch (ImsException e) {
12202 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12203 } finally {
12204 Binder.restoreCallingIdentity(identity);
12205 }
12206 }
12207
James.cf Lin18bb9002021-05-25 01:37:38 +080012208 /**
12209 * Remove UCE requests cannot be sent to the network status.
12210 */
12211 // Used for SHELL command only.
12212 @Override
12213 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12214 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12215 final long identity = Binder.clearCallingIdentity();
12216 try {
12217 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12218 } catch (ImsException e) {
12219 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12220 } finally {
12221 Binder.restoreCallingIdentity(identity);
12222 }
12223 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012224
James.cf Lin4b784aa2021-01-31 03:25:15 +080012225 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012226 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12227 String callingPackage) {
12228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12229 mApp, subId, "setSignalStrengthUpdateRequest");
12230
joonhunshin4ac60942023-11-15 15:23:39 +000012231 enforceTelephonyFeatureWithException(callingPackage,
12232 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12233
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012234 final int callingUid = Binder.getCallingUid();
12235 // Verify that tha callingPackage belongs to the calling UID
12236 mApp.getSystemService(AppOpsManager.class)
12237 .checkPackage(callingUid, callingPackage);
12238
Rambo Wang3607f502021-02-01 21:51:40 -080012239 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012240
12241 final long identity = Binder.clearCallingIdentity();
12242 try {
12243 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12244 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12245
12246 if (result instanceof IllegalStateException) {
12247 throw (IllegalStateException) result;
12248 }
12249 } finally {
12250 Binder.restoreCallingIdentity(identity);
12251 }
12252 }
12253
12254 @Override
12255 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12256 String callingPackage) {
12257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12258 mApp, subId, "clearSignalStrengthUpdateRequest");
12259
joonhunshin4ac60942023-11-15 15:23:39 +000012260 enforceTelephonyFeatureWithException(callingPackage,
12261 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12262
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012263 final int callingUid = Binder.getCallingUid();
12264 // Verify that tha callingPackage belongs to the calling UID
12265 mApp.getSystemService(AppOpsManager.class)
12266 .checkPackage(callingUid, callingPackage);
12267
12268 final long identity = Binder.clearCallingIdentity();
12269 try {
12270 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12271 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12272
12273 if (result instanceof IllegalStateException) {
12274 throw (IllegalStateException) result;
12275 }
12276 } finally {
12277 Binder.restoreCallingIdentity(identity);
12278 }
12279 }
12280
Rambo Wang3607f502021-02-01 21:51:40 -080012281 private static void validateSignalStrengthUpdateRequest(Context context,
12282 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012283 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12284 // phone/system process do not have further restriction on request
12285 return;
12286 }
12287
12288 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012289 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012290 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012291 context.enforceCallingOrSelfPermission(
12292 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12293 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012294 }
12295
12296 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012297 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012298 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012299 || info.isEnabled()) {
12300 throw new IllegalArgumentException(
12301 "Only system can set hide fields in SignalThresholdInfo");
12302 }
12303
12304 // Thresholds length for each RAN need in range. This has been validated in
12305 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12306 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12307 final int[] thresholds = info.getThresholds();
12308 Objects.requireNonNull(thresholds);
12309 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12310 || thresholds.length
12311 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12312 throw new IllegalArgumentException(
12313 "thresholds length is out of range: " + thresholds.length);
12314 }
12315 }
12316 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012317
12318 /**
12319 * Gets the current phone capability.
12320 *
12321 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12322 * @return the PhoneCapability which describes the data connection capability of modem.
12323 * It's used to evaluate possible phone config change, for example from single
12324 * SIM device to multi-SIM device.
12325 */
12326 @Override
12327 public PhoneCapability getPhoneCapability() {
12328 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012329
12330 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12331 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12332
SongFerngWang8236caa2021-01-17 21:51:44 +080012333 final long identity = Binder.clearCallingIdentity();
12334 try {
12335 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12336 } finally {
12337 Binder.restoreCallingIdentity(identity);
12338 }
12339 }
Michele Berionne5e411512020-11-13 02:36:59 +000012340
12341 /**
12342 * Prepare TelephonyManager for an unattended reboot. The reboot is
12343 * required to be done shortly after the API is invoked.
12344 */
12345 @Override
12346 @TelephonyManager.PrepareUnattendedRebootResult
12347 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012348 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012349 enforceRebootPermission();
12350
joonhunshin4ac60942023-11-15 15:23:39 +000012351 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12352 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12353
Michele Berionne5e411512020-11-13 02:36:59 +000012354 final long identity = Binder.clearCallingIdentity();
12355 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012356 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012357 } finally {
12358 Binder.restoreCallingIdentity(identity);
12359 }
12360 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012361
12362 /**
12363 * Request to get the current slicing configuration including URSP rules and
12364 * NSSAIs (configured, allowed and rejected).
12365 *
12366 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12367 */
12368 @Override
12369 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012370 TelephonyPermissions
12371 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12372 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012373
joonhunshin4ac60942023-11-15 15:23:39 +000012374 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12375 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12376 "getSlicingConfig");
12377
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012378 final long identity = Binder.clearCallingIdentity();
12379 try {
12380 Phone phone = getDefaultPhone();
12381 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12382 } finally {
12383 Binder.restoreCallingIdentity(identity);
12384 }
12385 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012386
12387 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012388 * Check whether the given premium capability is available for purchase from the carrier.
12389 *
12390 * @param capability The premium capability to check.
12391 * @param subId The subId to check the premium capability for.
12392 *
12393 * @return Whether the given premium capability is available to purchase.
12394 */
12395 @Override
12396 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12397 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12398 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12399 log("Premium capability "
12400 + TelephonyManager.convertPremiumCapabilityToString(capability)
12401 + " is not available for purchase due to missing permissions.");
12402 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12403 + "permission READ_BASIC_PHONE_STATE.");
12404 }
12405
joonhunshin4ac60942023-11-15 15:23:39 +000012406 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12407 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12408
Sarah Chin2ec39f62022-08-31 17:03:26 -070012409 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012410 if (phone == null) {
12411 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12412 return false;
12413 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012414 final long identity = Binder.clearCallingIdentity();
12415 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012416 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012417 .isPremiumCapabilityAvailableForPurchase(capability);
12418 } finally {
12419 Binder.restoreCallingIdentity(identity);
12420 }
12421 }
12422
12423 /**
12424 * Purchase the given premium capability from the carrier.
12425 *
12426 * @param capability The premium capability to purchase.
12427 * @param callback The result of the purchase request.
12428 * @param subId The subId to purchase the premium capability for.
12429 */
12430 @Override
12431 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12432 log("purchasePremiumCapability: capability="
12433 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12434 + getCurrentPackageName());
12435
12436 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12437 mApp, "purchasePremiumCapability")) {
12438 log("purchasePremiumCapability "
12439 + TelephonyManager.convertPremiumCapabilityToString(capability)
12440 + " failed due to missing permissions.");
12441 throw new SecurityException("purchasePremiumCapability requires permission "
12442 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012443 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12444 mApp, "purchasePremiumCapability")) {
12445 log("purchasePremiumCapability "
12446 + TelephonyManager.convertPremiumCapabilityToString(capability)
12447 + " failed due to missing permissions.");
12448 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012449 }
12450
joonhunshin4ac60942023-11-15 15:23:39 +000012451 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12452 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12453
Sarah Chin2ec39f62022-08-31 17:03:26 -070012454 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012455 if (phone == null) {
12456 try {
12457 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12458 callback.accept(result);
12459 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12460 } catch (RemoteException e) {
12461 String logStr = "Purchase premium capability "
12462 + TelephonyManager.convertPremiumCapabilityToString(capability)
12463 + " failed due to RemoteException handling null phone: " + e;
12464 if (DBG) log(logStr);
12465 AnomalyReporter.reportAnomaly(
12466 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12467 }
12468 return;
12469 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012470
12471 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012472 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012473 callingProcess = mApp.getPackageManager().getApplicationInfo(
12474 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012475 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012476 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012477 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012478
12479 boolean isVisible = false;
12480 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12481 if (am != null) {
12482 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12483 if (processes != null) {
12484 for (ActivityManager.RunningAppProcessInfo process : processes) {
12485 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012486 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012487 if (process.processName.equals(callingProcess) && process.importance
12488 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12489 isVisible = true;
12490 break;
12491 }
12492 }
12493 }
12494 }
12495
12496 if (!isVisible) {
12497 try {
12498 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12499 callback.accept(result);
12500 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12501 } catch (RemoteException e) {
12502 String logStr = "Purchase premium capability "
12503 + TelephonyManager.convertPremiumCapabilityToString(capability)
12504 + " failed due to RemoteException handling background application: " + e;
12505 if (DBG) log(logStr);
12506 AnomalyReporter.reportAnomaly(
12507 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12508 }
12509 return;
12510 }
12511
Sarah Chin71b3a852022-09-28 15:54:19 -070012512 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012513 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012514 }
12515
12516 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012517 * Register an IMS connection state callback
12518 */
12519 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012520 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12521 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012522 if (feature == ImsFeature.FEATURE_MMTEL) {
12523 // ImsMmTelManager
12524 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12525 TelephonyPermissions
12526 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12527 mApp, subId, "registerImsStateCallback");
12528 } else if (feature == ImsFeature.FEATURE_RCS) {
12529 // ImsRcsManager or SipDelegateManager
12530 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12531 Binder.getCallingUid(), "registerImsStateCallback",
12532 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12533 Manifest.permission.READ_PRECISE_PHONE_STATE,
12534 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12535 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12536 }
12537
12538 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12539 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12540 "IMS not available on device.");
12541 }
12542
12543 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12544 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12545 }
12546
12547 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12548 if (controller == null) {
12549 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12550 "IMS not available on device.");
12551 }
12552
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012553 if (callingPackage == null) {
12554 callingPackage = getCurrentPackageName();
12555 }
12556
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012557 final long token = Binder.clearCallingIdentity();
12558 try {
12559 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012560 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012561 } catch (ImsException e) {
12562 throw new ServiceSpecificException(e.getCode());
12563 } finally {
12564 Binder.restoreCallingIdentity(token);
12565 }
12566 }
12567
12568 /**
12569 * Unregister an IMS connection state callback
12570 */
12571 @Override
12572 public void unregisterImsStateCallback(IImsStateCallback cb) {
12573 final long token = Binder.clearCallingIdentity();
12574 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12575 if (controller == null) {
12576 return;
12577 }
12578 try {
12579 controller.unregisterImsStateCallback(cb);
12580 } finally {
12581 Binder.restoreCallingIdentity(token);
12582 }
12583 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012584
12585 /**
12586 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12587 *
12588 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012589 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012590 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012591 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012592 * If there is current registered network this value will be same as the registered cell
12593 * identity. If the device goes out of service the previous cell identity is cached and
12594 * will be returned. If the cache age of the Cell identity is more than 24 hours
12595 * it will be cleared and null will be returned.
12596 *
12597 */
12598 @Override
12599 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12600 String callingFeatureId) {
12601 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12602 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12603 LocationAccessPolicy.checkLocationPermission(mApp,
12604 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12605 .setCallingPackage(callingPackage)
12606 .setCallingFeatureId(callingFeatureId)
12607 .setCallingPid(Binder.getCallingPid())
12608 .setCallingUid(Binder.getCallingUid())
12609 .setMethod("getLastKnownCellIdentity")
12610 .setLogAsInfo(true)
12611 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12612 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12613 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12614 .build());
12615
12616 boolean hasFinePermission =
12617 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12618 if (!hasFinePermission
12619 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12620 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012621 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012622 }
12623
12624 final long identity = Binder.clearCallingIdentity();
12625 try {
Ling Mac28f0212023-03-24 16:07:15 -070012626 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012627 if (sst == null) return null;
12628 return sst.getLastKnownCellIdentity();
12629 } finally {
12630 Binder.restoreCallingIdentity(identity);
12631 }
12632 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012633
jimsun3b9ccac2021-10-26 15:01:23 +080012634 /**
12635 * Sets the modem service class Name that Telephony will bind to.
12636 *
12637 * @param serviceName The class name of the modem service.
12638 * @return true if the operation is succeed, otherwise false.
12639 */
12640 public boolean setModemService(String serviceName) {
12641 Log.d(LOG_TAG, "setModemService - " + serviceName);
12642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012644 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12645 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012646 return mPhoneConfigurationManager.setModemService(serviceName);
12647 }
12648
12649 /**
12650 * Return the class name of the currently bounded modem service.
12651 *
12652 * @return the class name of the modem service.
12653 */
12654 public String getModemService() {
12655 String result;
12656 Log.d(LOG_TAG, "getModemService");
12657 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12658 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012659 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012660 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12661 "getModemService");
12662 result = mPhoneConfigurationManager.getModemService();
12663 Log.d(LOG_TAG, "result = " + result);
12664 return result;
12665 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012666
Hakjun Choi3ee81112023-12-19 15:40:58 +000012667 /**
12668 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12669 * including carrier config, entitlement server, and config update.
12670 *
12671 * @param subId subId The subscription ID of the carrier.
12672 *
12673 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12674 * be returned.
12675 *
12676 * @throws SecurityException if the caller doesn't have the required permission.
12677 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012678 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12679 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012680 final long identity = Binder.clearCallingIdentity();
12681 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012682 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012683 } finally {
12684 Binder.restoreCallingIdentity(identity);
12685 }
12686 }
12687
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012688 @Override
12689 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12690 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12691 mApp.enforceCallingOrSelfPermission(
12692 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12694
12695 final long identity = Binder.clearCallingIdentity();
12696 try {
12697 Phone phone = getPhone(subId);
12698 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012699 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12700 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012701 phone.setVoiceServiceStateOverride(hasService);
12702 } finally {
12703 Binder.restoreCallingIdentity(identity);
12704 }
12705 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012706
12707 /**
12708 * set removable eSIM as default eUICC.
12709 *
12710 * @hide
12711 */
12712 @Override
12713 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12714 enforceModifyPermission();
12715 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12716
12717 final long identity = Binder.clearCallingIdentity();
12718 try {
12719 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12720 } finally {
12721 Binder.restoreCallingIdentity(identity);
12722 }
12723 }
12724
12725 /**
12726 * Returns whether the removable eSIM is default eUICC or not.
12727 *
12728 * @hide
12729 */
12730 @Override
12731 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12732 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12734
12735 final long identity = Binder.clearCallingIdentity();
12736 try {
12737 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12738 } finally {
12739 Binder.restoreCallingIdentity(identity);
12740 }
12741 }
12742
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012743 /**
12744 * Get the component name of the default app to direct respond-via-message intent for the
12745 * user associated with this subscription, update the cache if there is no respond-via-message
12746 * application currently configured for this user.
12747 * @return component name of the app and class to direct Respond Via Message intent to, or
12748 * {@code null} if the functionality is not supported.
12749 * @hide
12750 */
12751 @Override
12752 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12753 boolean updateIfNeeded) {
12754 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012755
joonhunshin4ac60942023-11-15 15:23:39 +000012756 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12757 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12758 "getDefaultRespondViaMessageApplication");
12759
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012760 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12761
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012762 UserHandle userHandle = null;
12763 final long identity = Binder.clearCallingIdentity();
12764 try {
12765 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12766 } finally {
12767 Binder.restoreCallingIdentity(identity);
12768 }
12769 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12770 updateIfNeeded, userHandle);
12771 }
Jack Yuf5badd92022-12-08 00:50:53 -080012772
12773 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012774 * Set whether the device is able to connect with null ciphering or integrity
12775 * algorithms. This is a global setting and will apply to all active subscriptions
12776 * and all new subscriptions after this.
12777 *
12778 * @param enabled when true, null cipher and integrity algorithms are allowed.
12779 * @hide
12780 */
12781 @Override
12782 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12783 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12784 enforceModifyPermission();
12785 checkForNullCipherAndIntegritySupport();
12786
12787 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12788 // for listening to these preference changes and applying them immediately.
12789 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12790 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12791 editor.apply();
12792
12793 for (Phone phone: PhoneFactory.getPhones()) {
12794 phone.handleNullCipherEnabledChange();
12795 }
12796 }
12797
12798
12799 /**
12800 * Get whether the device is able to connect with null ciphering or integrity
12801 * algorithms. Note that this retrieves the phone-global preference and not
12802 * the state of the radio.
12803 *
12804 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12805 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12806 * version for this feature.
12807 * @hide
12808 */
12809 @Override
12810 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12811 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12812 enforceReadPermission();
12813 checkForNullCipherAndIntegritySupport();
12814 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12815 }
12816
12817 private void checkForNullCipherAndIntegritySupport() {
12818 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12819 throw new UnsupportedOperationException(
12820 "Null cipher and integrity operations require HAL 2.1 or above");
12821 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012822 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12823 throw new UnsupportedOperationException(
12824 "Null cipher and integrity operations unsupported by modem");
12825 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012826 }
12827
Gil Cukierman06403e12023-11-29 16:33:03 +000012828 private void checkForIdentifierDisclosureNotificationSupport() {
12829 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12830 throw new UnsupportedOperationException(
12831 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12832 + "above");
12833 }
12834 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12835 throw new UnsupportedOperationException(
12836 "Cellular identifier disclosure transparency operations unsupported by modem");
12837 }
12838 }
12839
Michael Groover826b71d2023-12-21 22:08:06 -060012840 private void checkForNullCipherNotificationSupport() {
12841 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12842 throw new UnsupportedOperationException(
12843 "Null cipher notification operations require HAL 2.2 or above");
12844 }
12845 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12846 throw new UnsupportedOperationException(
12847 "Null cipher notification operations unsupported by modem");
12848 }
12849 }
12850
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012851 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012852 * Get the SIM state for the slot index.
12853 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12854 *
12855 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12856 */
12857 @Override
12858 @SimState
12859 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012860 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12861 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12862
Jack Yuf5badd92022-12-08 00:50:53 -080012863 IccCardConstants.State simState;
12864 if (slotIndex < 0) {
12865 simState = IccCardConstants.State.UNKNOWN;
12866 } else {
12867 Phone phone = null;
12868 try {
12869 phone = PhoneFactory.getPhone(slotIndex);
12870 } catch (IllegalStateException e) {
12871 // ignore
12872 }
12873 if (phone == null) {
12874 simState = IccCardConstants.State.UNKNOWN;
12875 } else {
12876 IccCard icc = phone.getIccCard();
12877 if (icc == null) {
12878 simState = IccCardConstants.State.UNKNOWN;
12879 } else {
12880 simState = icc.getState();
12881 }
12882 }
12883 }
12884 return simState.ordinal();
12885 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012886
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012887 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12888 boolean enableLogcat,
12889 long logcatStartTimestampMillis, boolean enableTelecomDump,
12890 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012891 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012892 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12893 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12894 ecdDataBuilder
12895 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12896 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012897 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012898 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012899 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012900 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12901 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012902 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12903 Executors.newCachedThreadPool(), db,
12904 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012905 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012906 }
12907
12908 /**
12909 * Request telephony to persist state for debugging emergency call failures.
12910 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012911 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012912 * @param enableLogcat whether to collect logcat output
12913 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12914 * @param enableTelecomDump whether to collect telecom dumpsys
12915 * @param enableTelephonyDump whether to collect telephony dumpsys
12916 */
12917 @Override
12918 @RequiresPermission(android.Manifest.permission.DUMP)
12919 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12920 long logcatStartTimestampMillis, boolean enableTelecomDump,
12921 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012922 // Verify that the caller has READ_DROPBOX_DATA permission.
12923 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12924 && Flags.enableReadDropboxPermission()) {
12925 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12926 "persistEmergencyCallDiagnosticData");
12927 } else {
12928 // Otherwise, enforce legacy permission.
12929 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12930 "persistEmergencyCallDiagnosticData");
12931 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012932 final long identity = Binder.clearCallingIdentity();
12933 try {
12934 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12935 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12936
12937 } finally {
12938 Binder.restoreCallingIdentity(identity);
12939 }
12940 }
12941
Hui Wang9b5793a2022-12-05 14:38:06 -060012942 /**
12943 * Get current cell broadcast ranges.
12944 */
12945 @Override
12946 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12947 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12948 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12949 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012950
12951 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12952 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12953
Hui Wang9b5793a2022-12-05 14:38:06 -060012954 final long identity = Binder.clearCallingIdentity();
12955 try {
12956 return getPhone(subId).getCellBroadcastIdRanges();
12957 } finally {
12958 Binder.restoreCallingIdentity(identity);
12959 }
12960 }
12961
12962 /**
12963 * Set reception of cell broadcast messages with the list of the given ranges
12964 *
12965 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12966 */
12967 @Override
12968 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12969 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12970 @Nullable IIntegerConsumer callback) {
12971 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12972 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012973
12974 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12975 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12976
Hui Wang9b5793a2022-12-05 14:38:06 -060012977 final long identity = Binder.clearCallingIdentity();
12978 try {
12979 Phone phone = getPhoneFromSubId(subId);
12980 if (DBG) {
12981 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12982 }
12983 phone.setCellBroadcastIdRanges(ranges, result -> {
12984 if (callback != null) {
12985 try {
12986 callback.accept(result);
12987 } catch (RemoteException e) {
12988 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12989 }
12990 }
12991 });
12992 } finally {
12993 Binder.restoreCallingIdentity(identity);
12994 }
12995 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012996
12997 /**
12998 * Returns whether the device supports the domain selection service.
12999 *
13000 * @return {@code true} if the device supports the domain selection service.
13001 */
13002 @Override
13003 public boolean isDomainSelectionSupported() {
13004 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13005 "isDomainSelectionSupported");
13006
13007 final long identity = Binder.clearCallingIdentity();
13008 try {
13009 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13010 } finally {
13011 Binder.restoreCallingIdentity(identity);
13012 }
13013 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013014
13015 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013016 * Returns whether the AOSP domain selection service is supported.
13017 *
13018 * @return {@code true} if the AOSP domain selection service is supported,
13019 * {@code false} otherwise.
13020 */
13021 @Override
13022 public boolean isAospDomainSelectionService() {
13023 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13024 "isAospDomainSelectionService");
13025
13026 final long identity = Binder.clearCallingIdentity();
13027 try {
13028 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13029 String dssComponentName = mApp.getResources().getString(
13030 R.string.config_domain_selection_service_component_name);
13031 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13032 TelephonyDomainSelectionService.class.getName());
13033 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13034 + ", aosp=" + componentName.flattenToString());
13035 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13036 }
13037 } finally {
13038 Binder.restoreCallingIdentity(identity);
13039 }
13040 return false;
13041 }
13042
13043 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013044 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13045 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13046 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013047 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013048 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013049 * @param enableSatellite {@code true} to enable the satellite modem and
13050 * {@code false} to disable.
13051 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013052 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013053 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013054 *
13055 * @throws SecurityException if the caller doesn't have the required permission.
13056 */
13057 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013058 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013059 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013060 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013061 if (enableSatellite) {
13062 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13063 @Override
13064 protected void onReceiveResult(int resultCode, Bundle resultData) {
13065 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13066 + ", resultData=" + resultData);
13067 boolean isAllowed = false;
13068 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13069 callback::accept);
13070 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13071 if (resultData != null
13072 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13073 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13074 } else {
13075 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13076 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013077 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013078 result.accept(resultCode);
13079 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013080 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013081 if (isAllowed) {
13082 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013083 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013084 } else {
13085 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13086 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013087 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013088 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013089 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013090 subId, resultReceiver);
13091 } else {
13092 // No need to check if satellite is allowed at current location when disabling satellite
13093 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013094 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013095 }
Sarah Chin503828c2023-02-01 23:54:20 -080013096 }
13097
13098 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013099 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013100 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013101 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013102 * @param result The result receiver that returns whether the satellite modem is enabled
13103 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013104 *
13105 * @throws SecurityException if the caller doesn't have the required permission.
13106 */
13107 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013108 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13109 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013110 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013111 }
13112
13113 /**
Sarah Chin43457982023-02-15 17:50:38 -080013114 * Request to get whether the satellite service demo mode is enabled.
13115 *
13116 * @param subId The subId of the subscription to check whether the satellite demo mode
13117 * is enabled for.
13118 * @param result The result receiver that returns whether the satellite demo mode is enabled
13119 * if the request is successful or an error code if the request failed.
13120 *
13121 * @throws SecurityException if the caller doesn't have the required permission.
13122 */
13123 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013124 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13125 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13126 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013127 }
13128
13129 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013130 * Request to get whether the satellite service is enabled with emergency mode.
13131 *
13132 * @param subId The subId of the subscription to check whether the satellite demo mode
13133 * is enabled for.
13134 * @param result The result receiver that returns whether the satellite emergency mode is
13135 * enabled if the request is successful or an error code if the request failed.
13136 *
13137 * @throws SecurityException if the caller doesn't have the required permission.
13138 */
13139 @Override
13140 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13141 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13142 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13143 }
13144
13145 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013146 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013147 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013148 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013149 * @param result The result receiver that returns whether the satellite service is supported on
13150 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013151 */
13152 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013153 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013154 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013155 }
13156
13157 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013158 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013159 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013160 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013161 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13162 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013163 *
13164 * @throws SecurityException if the caller doesn't have required permission.
13165 */
13166 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013167 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13168 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013169 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013170 }
13171
13172 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013173 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013174 * This can be called by the pointing UI when the user starts pointing to the satellite.
13175 * Modem should continue to report the pointing input as the device or satellite moves.
13176 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013177 * @param subId The subId of the subscription to start satellite transmission updates for.
13178 * @param resultCallback The callback to get the result of the request.
13179 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013180 *
13181 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013182 */
13183 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013184 public void startSatelliteTransmissionUpdates(int subId,
13185 @NonNull IIntegerConsumer resultCallback,
13186 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13187 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13188 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013189 }
13190
13191 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013192 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013193 * This can be called by the pointing UI when the user stops pointing to the satellite.
13194 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013195 * @param subId The subId of the subscription to stop satellite transmission updates for.
13196 * @param resultCallback The callback to get the result of the request.
13197 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13198 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013199 *
13200 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013201 */
13202 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013203 public void stopSatelliteTransmissionUpdates(int subId,
13204 @NonNull IIntegerConsumer resultCallback,
13205 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13206 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13207 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013208 }
13209
13210 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013211 * Register the subscription with a satellite provider.
13212 * This is needed to register the subscription if the provider allows dynamic registration.
13213 *
13214 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013215 * @param token The token to be used as a unique identifier for provisioning with satellite
13216 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013217 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013218 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013219 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013220 * @return The signal transport used by the caller to cancel the provision request,
13221 * or {@code null} if the request failed.
13222 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013223 * @throws SecurityException if the caller doesn't have the required permission.
13224 */
13225 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013226 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013227 @NonNull String token, @NonNull byte[] provisionData,
13228 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013229 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013230 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13231 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013232 }
13233
13234 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013235 * Unregister the device/subscription with the satellite provider.
13236 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013237 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013238 * should report as deprovisioned.
13239 *
13240 * @param subId The subId of the subscription to be deprovisioned.
13241 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013242 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013243 *
13244 * @throws SecurityException if the caller doesn't have the required permission.
13245 */
13246 @Override
13247 public void deprovisionSatelliteService(int subId,
13248 @NonNull String token, @NonNull IIntegerConsumer callback) {
13249 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013250 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013251 }
13252
13253 /**
Sarah Chin43457982023-02-15 17:50:38 -080013254 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013255 *
Sarah Chin43457982023-02-15 17:50:38 -080013256 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013257 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013258 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013259 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013260 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013261 * @throws SecurityException if the caller doesn't have the required permission.
13262 */
13263 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013264 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13265 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013266 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013267 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013268 }
13269
13270 /**
Sarah Chin43457982023-02-15 17:50:38 -080013271 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013272 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013273 *
Sarah Chin43457982023-02-15 17:50:38 -080013274 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013275 * @param callback The callback that was passed to
13276 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013277 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013278 * @throws SecurityException if the caller doesn't have the required permission.
13279 */
13280 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013281 public void unregisterForSatelliteProvisionStateChanged(
13282 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013283 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013284 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013285 }
13286
13287 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013288 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013289 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013290 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013291 * @param result The result receiver that returns whether the device is provisioned with a
13292 * satellite provider if the request is successful or an error code if the
13293 * request failed.
13294 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013295 * @throws SecurityException if the caller doesn't have the required permission.
13296 */
13297 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013298 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13299 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013300 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013301 }
13302
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013303 /**
Sarah Chin43457982023-02-15 17:50:38 -080013304 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013305 *
Sarah Chin43457982023-02-15 17:50:38 -080013306 * @param subId The subId of the subscription to register for satellite modem state changed.
13307 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013308 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013309 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013310 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013311 * @throws SecurityException if the caller doesn't have the required permission.
13312 */
13313 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013314 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013315 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013316 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013317 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013318 }
13319
13320 /**
Sarah Chin43457982023-02-15 17:50:38 -080013321 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013322 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013323 *
Sarah Chin43457982023-02-15 17:50:38 -080013324 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013325 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013326 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013327 *
13328 * @throws SecurityException if the caller doesn't have the required permission.
13329 */
13330 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013331 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013332 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013333 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13334 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013335 }
13336
13337 /**
13338 * Register to receive incoming datagrams over satellite.
13339 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013340 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013341 * @param callback The callback to handle incoming datagrams over satellite.
13342 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013343 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013344 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013345 * @throws SecurityException if the caller doesn't have the required permission.
13346 */
13347 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013348 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013349 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013350 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13351 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013352 }
13353
13354 /**
13355 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013356 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013357 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013358 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13359 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013360 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013361 *
13362 * @throws SecurityException if the caller doesn't have the required permission.
13363 */
13364 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013365 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013366 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013367 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13368 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013369 }
13370
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013371 /**
13372 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013373 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013374 * This method requests modem to check if there are any pending datagrams to be received over
13375 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013376 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013377 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013378 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013379 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013380 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013381 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013382 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013383 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13384 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13385 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013386 }
13387
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013388 /**
13389 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013390 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013391 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13392 * input to this method. Datagram received here will be passed down to modem without any
13393 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013394 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013395 * @param subId The subId of the subscription to send satellite datagrams for.
13396 * @param datagramType datagram type indicating whether the datagram is of type
13397 * SOS_SMS or LOCATION_SHARING.
13398 * @param datagram encoded gateway datagram which is encrypted by the caller.
13399 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013400 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13401 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013402 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013403 *
13404 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013405 */
13406 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013407 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013408 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13409 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013410 enforceSatelliteCommunicationPermission("sendDatagram");
13411 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13412 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013413 }
13414
Sarah Chindf715ec2023-02-13 13:46:24 -080013415 /**
13416 * Request to get whether satellite communication is allowed for the current location.
13417 *
13418 * @param subId The subId of the subscription to check whether satellite communication is
13419 * allowed for the current location for.
13420 * @param result The result receiver that returns whether satellite communication is allowed
13421 * for the current location if the request is successful or an error code
13422 * if the request failed.
13423 *
13424 * @throws SecurityException if the caller doesn't have the required permission.
13425 */
13426 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013427 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013428 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013429 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13430 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13431 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013432 }
13433
13434 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013435 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013436 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013437 * @param subId The subId to get the time after which the satellite will be visible for.
13438 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013439 * be visible if the request is successful or an error code if the request failed.
13440 *
13441 * @throws SecurityException if the caller doesn't have the required permission.
13442 */
13443 @Override
13444 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13445 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013446 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013447 }
13448
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013449 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013450 * Inform that Device is aligned to satellite for demo mode.
13451 *
13452 * @param subId The subId to get the time after which the satellite will be visible for.
13453 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13454 * {@code false} Device fails to align with the satellite for demo mode.
13455 *
13456 * @throws SecurityException if the caller doesn't have required permission.
13457 */
13458 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13459
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013460 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013461 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013462 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013463 }
13464
13465 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013466 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13467 * by modem.
13468 *
13469 * @param subId The subId of the subscription to request for.
13470 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013471 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013472 * operation.
13473 *
13474 * @throws SecurityException if the caller doesn't have required permission.
13475 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013476 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013477 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13478 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013479 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013480 final long identity = Binder.clearCallingIdentity();
13481 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013482 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013483 } finally {
13484 Binder.restoreCallingIdentity(identity);
13485 }
13486 }
13487
13488 /**
13489 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13490 * by modem.
13491 *
13492 * @param subId The subId of the subscription to request for.
13493 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013494 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013495 * operation.
13496 *
13497 * @throws SecurityException if the caller doesn't have required permission.
13498 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013499 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013500 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13501 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013502 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013503 final long identity = Binder.clearCallingIdentity();
13504 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013505 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013506 } finally {
13507 Binder.restoreCallingIdentity(identity);
13508 }
13509 }
13510
13511 /**
13512 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013513 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013514 *
13515 * @param subId The subId of the subscription to request for.
13516 *
13517 * @return Integer array of reasons for disallowing satellite communication.
13518 *
13519 * @throws SecurityException if the caller doesn't have the required permission.
13520 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013521 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013522 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013523 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013524 final long identity = Binder.clearCallingIdentity();
13525 try {
13526 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013527 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013528 return reasonSet.stream().mapToInt(i->i).toArray();
13529 } finally {
13530 Binder.restoreCallingIdentity(identity);
13531 }
13532 }
13533
13534 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013535 * Request to get the signal strength of the satellite connection.
13536 *
13537 * @param subId The subId of the subscription to request for.
13538 * @param result Result receiver to get the error code of the request and the current signal
13539 * strength of the satellite connection.
13540 *
13541 * @throws SecurityException if the caller doesn't have required permission.
13542 */
13543 @Override
13544 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13545 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13546 final long identity = Binder.clearCallingIdentity();
13547 try {
13548 mSatelliteController.requestNtnSignalStrength(subId, result);
13549 } finally {
13550 Binder.restoreCallingIdentity(identity);
13551 }
13552 }
13553
13554 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013555 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13556 * is not successful, a {@link ServiceSpecificException} that contains
13557 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013558 *
13559 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013560 * @param callback The callback to handle the NTN signal strength changed event. If the
13561 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13562 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13563 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13564 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013565 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013566 * @throws SecurityException If the caller doesn't have the required permission.
13567 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013568 */
13569 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013570 public void registerForNtnSignalStrengthChanged(int subId,
13571 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013572 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13573 final long identity = Binder.clearCallingIdentity();
13574 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013575 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013576 } finally {
13577 Binder.restoreCallingIdentity(identity);
13578 }
13579 }
13580
13581 /**
13582 * Unregisters for NTN signal strength changed from satellite modem.
13583 * If callback was not registered before, the request will be ignored.
13584 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013585 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13586 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013587 * @param callback The callback that was passed to
13588 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13589 *
13590 * @throws SecurityException if the caller doesn't have the required permission.
13591 */
13592 @Override
13593 public void unregisterForNtnSignalStrengthChanged(
13594 int subId, @NonNull INtnSignalStrengthCallback callback) {
13595 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13596 final long identity = Binder.clearCallingIdentity();
13597 try {
13598 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13599 } finally {
13600 Binder.restoreCallingIdentity(identity);
13601 }
13602 }
13603
13604 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013605 * Registers for satellite capabilities change event from the satellite service.
13606 *
13607 * @param subId The subId of the subscription to request for.
13608 * @param callback The callback to handle the satellite capabilities changed event.
13609 *
13610 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13611 *
13612 * @throws SecurityException if the caller doesn't have required permission.
13613 */
13614 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013615 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013616 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013617 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013618 final long identity = Binder.clearCallingIdentity();
13619 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013620 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013621 } finally {
13622 Binder.restoreCallingIdentity(identity);
13623 }
13624 }
13625
13626 /**
13627 * Unregisters for satellite capabilities change event from the satellite service.
13628 * If callback was not registered before, the request will be ignored.
13629 *
13630 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13631 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013632 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013633 *
13634 * @throws SecurityException if the caller doesn't have required permission.
13635 */
13636 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013637 public void unregisterForCapabilitiesChanged(int subId,
13638 @NonNull ISatelliteCapabilitiesCallback callback) {
13639 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013640 final long identity = Binder.clearCallingIdentity();
13641 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013642 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013643 } finally {
13644 Binder.restoreCallingIdentity(identity);
13645 }
13646 }
13647
13648 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013649 * Registers for the satellite supported state changed.
13650 *
13651 * @param subId The subId of the subscription to register for supported state changed.
13652 * @param callback The callback to handle the satellite supported state changed event.
13653 *
13654 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13655 *
13656 * @throws SecurityException if the caller doesn't have the required permission.
13657 */
13658 @Override
13659 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13660 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13661 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13662 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13663 }
13664
13665 /**
13666 * Unregisters for the satellite supported state changed.
13667 * If callback was not registered before, the request will be ignored.
13668 *
13669 * @param subId The subId of the subscription to unregister for supported state changed.
13670 * @param callback The callback that was passed to
13671 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13672 *
13673 * @throws SecurityException if the caller doesn't have the required permission.
13674 */
13675 @Override
13676 public void unregisterForSatelliteSupportedStateChanged(
13677 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13678 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13679 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13680 }
13681
13682 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013683 * This API can be used by only CTS to update satellite vendor service package name.
13684 *
13685 * @param servicePackageName The package name of the satellite vendor service.
13686 * @return {@code true} if the satellite vendor service is set successfully,
13687 * {@code false} otherwise.
13688 */
13689 public boolean setSatelliteServicePackageName(String servicePackageName) {
13690 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13691 TelephonyPermissions.enforceShellOnly(
13692 Binder.getCallingUid(), "setSatelliteServicePackageName");
13693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13694 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13695 "setSatelliteServicePackageName");
13696 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13697 }
13698
13699 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013700 * This API can be used by only CTS to update satellite gateway service package name.
13701 *
13702 * @param servicePackageName The package name of the satellite gateway service.
13703 * @return {@code true} if the satellite gateway service is set successfully,
13704 * {@code false} otherwise.
13705 */
13706 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13707 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13708 TelephonyPermissions.enforceShellOnly(
13709 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13711 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13712 "setSatelliteGatewayServicePackageName");
13713 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13714 }
13715
13716 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013717 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13718 *
13719 * @param packageName The package name of the satellite pointing UI app.
13720 * @param className The class name of the satellite pointing UI app.
13721 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13722 * {@code false} otherwise.
13723 */
13724 public boolean setSatellitePointingUiClassName(
13725 @Nullable String packageName, @Nullable String className) {
13726 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13727 + ", className=" + className);
13728 TelephonyPermissions.enforceShellOnly(
13729 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13731 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13732 "setSatelliteGatewayServicePackageName");
13733 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13734 }
13735
13736 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013737 * This API can be used by only CTS to update the timeout duration in milliseconds that
13738 * satellite should stay at listening mode to wait for the next incoming page before disabling
13739 * listening mode.
13740 *
13741 * @param timeoutMillis The timeout duration in millisecond.
13742 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13743 */
13744 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13745 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13746 TelephonyPermissions.enforceShellOnly(
13747 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13749 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13750 "setSatelliteListeningTimeoutDuration");
13751 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13752 }
13753
13754 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013755 * This API can be used by only CTS to override the timeout durations used by the
13756 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013757 *
13758 * @param timeoutMillis The timeout duration in millisecond.
13759 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13760 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013761 public boolean setDatagramControllerTimeoutDuration(
13762 boolean reset, int timeoutType, long timeoutMillis) {
13763 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13764 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013765 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013766 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13768 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013769 "setDatagramControllerTimeoutDuration");
13770 return mSatelliteController.setDatagramControllerTimeoutDuration(
13771 reset, timeoutType, timeoutMillis);
13772 }
13773
13774 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013775 * This API can be used by only CTS to override the boolean configs used by the
13776 * DatagramController module.
13777 *
13778 * @param enable Whether to enable or disable boolean config.
13779 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13780 */
13781 public boolean setDatagramControllerBooleanConfig(
13782 boolean reset, int booleanType, boolean enable) {
13783 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13784 + ", reset=" + reset + ", enable=" + enable);
13785 TelephonyPermissions.enforceShellOnly(
13786 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13788 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13789 "ssetDatagramControllerBooleanConfig");
13790 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13791 }
13792
13793
13794 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013795 * This API can be used by only CTS to override the timeout durations used by the
13796 * SatelliteController module.
13797 *
13798 * @param timeoutMillis The timeout duration in millisecond.
13799 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13800 */
13801 public boolean setSatelliteControllerTimeoutDuration(
13802 boolean reset, int timeoutType, long timeoutMillis) {
13803 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13804 + reset + ", timeoutMillis=" + timeoutMillis);
13805 TelephonyPermissions.enforceShellOnly(
13806 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13808 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13809 "setSatelliteControllerTimeoutDuration");
13810 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13811 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013812 }
13813
13814 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013815 * This API can be used in only testing to override connectivity status in monitoring emergency
13816 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13817 *
13818 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13819 * of the following values to enable the override:
13820 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13821 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13822 * To disable the override, use -1 for handoverType.
13823 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13824 * delaySeconds after the emergency call starts.
13825 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13826 */
13827 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13828 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13829 TelephonyPermissions.enforceShellOnly(
13830 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13832 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13833 "setEmergencyCallToSatelliteHandoverType");
13834 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13835 handoverType, delaySeconds);
13836 }
13837
13838 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013839 * This API can be used in only testing to override oem-enabled satellite provision status.
13840 *
13841 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13842 * otherwise.
13843 * @param isProvisioned The overriding provision status.
13844 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13845 */
13846 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13847 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13848 + ", isProvisioned=" + isProvisioned);
13849 TelephonyPermissions.enforceShellOnly(
13850 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13852 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13853 "setOemEnabledSatelliteProvisionStatus");
13854 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13855 }
13856
13857 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013858 * This API should be used by only CTS tests to forcefully set telephony country codes.
13859 *
13860 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13861 */
13862 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13863 Map cachedNetworkCountryCodes, String locationCountryCode,
13864 long locationCountryCodeTimestampNanos) {
13865 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13866 + String.join(", ", currentNetworkCountryCodes)
13867 + ", locationCountryCode=" + locationCountryCode
13868 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13869 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13870 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13871 TelephonyPermissions.enforceShellOnly(
13872 Binder.getCallingUid(), "setCachedLocationCountryCode");
13873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13874 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13875 "setCachedLocationCountryCode");
13876 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13877 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13878 locationCountryCodeTimestampNanos);
13879 }
13880
13881 /**
13882 * This API should be used by only CTS tests to override the overlay configs of satellite
13883 * access controller.
13884 *
13885 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13886 * otherwise.
13887 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13888 */
13889 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13890 String s2CellFile, long locationFreshDurationNanos,
13891 List<String> satelliteCountryCodes) {
13892 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13893 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13894 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13895 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13896 ? String.join(", ", satelliteCountryCodes) : null));
13897 TelephonyPermissions.enforceShellOnly(
13898 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13900 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13901 "setSatelliteAccessControlOverlayConfigs");
13902 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13903 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13904 }
13905
13906 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013907 * This API can be used by only CTS to override the cached value for the device overlay config
13908 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13909 * outgoing satellite datagrams should be sent to modem in demo mode.
13910 *
13911 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13912 * satellite modem or not.
13913 *
13914 * @return {@code true} if the operation is successful, {@code false} otherwise.
13915 */
13916 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13917 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13918 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13919 + "disabled");
13920 return false;
13921 }
13922 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13923 TelephonyPermissions.enforceShellOnly(
13924 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13926 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13927 "setShouldSendDatagramToModemInDemoMode");
13928 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13929 shouldSendToModemInDemoMode);
13930 }
13931
13932 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013933 * Sets the service defined in ComponentName to be bound.
13934 *
13935 * This should only be used for testing.
13936 * @return {@code true} if the DomainSelectionService to bind to was set,
13937 * {@code false} otherwise.
13938 */
13939 @Override
13940 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13941 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13942
13943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13944 "setDomainSelectionServiceOverride");
13945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13946 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13947
13948 final long identity = Binder.clearCallingIdentity();
13949 try {
13950 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13951 return DomainSelectionResolver.getInstance()
13952 .setDomainSelectionServiceOverride(componentName);
13953 }
13954 } finally {
13955 Binder.restoreCallingIdentity(identity);
13956 }
13957 return false;
13958 }
13959
13960 /**
13961 * Clears the DomainSelectionService override.
13962 *
13963 * This should only be used for testing.
13964 * @return {@code true} if the DomainSelectionService override was cleared,
13965 * {@code false} otherwise.
13966 */
13967 @Override
13968 public boolean clearDomainSelectionServiceOverride() {
13969 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13970
13971 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13972 "clearDomainSelectionServiceOverride");
13973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13974 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13975
13976 final long identity = Binder.clearCallingIdentity();
13977 try {
13978 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13979 return DomainSelectionResolver.getInstance()
13980 .clearDomainSelectionServiceOverride();
13981 }
13982 } finally {
13983 Binder.restoreCallingIdentity(identity);
13984 }
13985 return false;
13986 }
13987
13988 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013989 * Enable or disable notifications sent for cellular identifier disclosure events.
13990 *
13991 * Disclosure events are defined as instances where a device has sent a cellular identifier
13992 * on the Non-access stratum (NAS) before a security context is established. As a result the
13993 * identifier is sent in the clear, which has privacy implications for the user.
13994 *
13995 * @param enable if notifications about disclosure events should be enabled
13996 * @throws SecurityException if the caller does not have the required privileges
13997 * @throws UnsupportedOperationException if the modem does not support this feature.
13998 */
13999 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014000 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014001 enforceModifyPermission();
14002 checkForIdentifierDisclosureNotificationSupport();
14003
14004 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14005 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14006 editor.apply();
14007
14008 // Each phone instance is responsible for updating its respective modem immediately
14009 // after we've made a preference change.
14010 for (Phone phone : PhoneFactory.getPhones()) {
14011 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14012 }
14013 }
14014
14015 /**
14016 * Get whether or not cellular identifier disclosure notifications are enabled.
14017 *
14018 * @throws SecurityException if the caller does not have the required privileges
14019 * @throws UnsupportedOperationException if the modem does not support this feature.
14020 */
14021 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014022 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014023 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14024 checkForIdentifierDisclosureNotificationSupport();
14025 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14026 }
14027
14028 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014029 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14030 * are in use by the cellular modem.
14031 *
14032 * @throws IllegalStateException if the Telephony process is not currently available
14033 * @throws SecurityException if the caller does not have the required privileges
14034 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14035 * and integrity algorithms in use
14036 * @hide
14037 */
14038 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014039 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014040 enforceModifyPermission();
14041 checkForNullCipherNotificationSupport();
14042
14043 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14044 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14045 editor.apply();
14046
14047 // Each phone instance is responsible for updating its respective modem immediately
14048 // after a preference change.
14049 for (Phone phone : PhoneFactory.getPhones()) {
14050 phone.handleNullCipherNotificationPreferenceChanged();
14051 }
14052 }
14053
14054 /**
14055 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14056 * cellular modem.
14057 *
14058 * @throws IllegalStateException if the Telephony process is not currently available
14059 * @throws SecurityException if the caller does not have the required privileges
14060 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14061 * and integrity algorithms in use
14062 * @hide
14063 */
14064 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14065 public boolean isNullCipherNotificationsEnabled() {
14066 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14067 checkForNullCipherNotificationSupport();
14068 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14069 }
14070
14071 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014072 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14073 *
14074 * <p>This method behaves in one of the following ways:
14075 * <ul>
14076 * <li>return true : if the calling package has the appop permission {@link
14077 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14078 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14079 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14080 * Owner device identifier access check, or the calling package has carrier privileges</>
14081 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14082 * </ul>
14083 */
14084 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14085 String callingPackage, @Nullable String callingFeatureId, String message) {
14086 for (Phone phone : PhoneFactory.getPhones()) {
14087 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14088 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14089 return true;
14090 }
14091 }
14092 return false;
14093 }
arunvoddud7401012022-12-15 16:08:12 +000014094
14095 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014096 * @return The subscription manager service instance.
14097 */
14098 public SubscriptionManagerService getSubscriptionManagerService() {
14099 return SubscriptionManagerService.getInstance();
14100 }
14101
14102 /**
arunvoddud7401012022-12-15 16:08:12 +000014103 * Class binds the consumer[callback] and carrierId.
14104 */
14105 private static class CallerCallbackInfo {
14106 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014107 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014108
Steve Statia28b7cb32024-03-11 23:58:50 +000014109 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014110 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014111 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014112 }
14113
14114 public Consumer<Integer> getConsumer() {
14115 return mConsumer;
14116 }
14117
Steve Statia28b7cb32024-03-11 23:58:50 +000014118 public Set<Integer> getCarrierIds() {
14119 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014120 }
14121 }
joonhunshin4ac60942023-11-15 15:23:39 +000014122
14123 /*
14124 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14125 * But the context that is passed in is unused if the phone app is already alive.
14126 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14127 */
14128 @VisibleForTesting
14129 public void setPackageManager(PackageManager packageManager) {
14130 mPackageManager = packageManager;
14131 }
14132
14133 /*
Nate Myren453c3472024-03-13 11:28:11 -070014134 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14135 * But the context that is passed in is unused if the phone app is already alive.
14136 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14137 */
14138 @VisibleForTesting
14139 public void setAppOpsManager(AppOpsManager appOps) {
14140 mAppOps = appOps;
14141 }
14142
14143 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014144 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14145 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14146 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14147 */
14148 @VisibleForTesting
14149 public void setFeatureFlags(FeatureFlags featureFlags) {
14150 mFeatureFlags = featureFlags;
14151 }
14152
14153 /**
14154 * Make sure the device has required telephony feature
14155 *
14156 * @throws UnsupportedOperationException if the device does not have required telephony feature
14157 */
14158 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14159 @NonNull String telephonyFeature, @NonNull String methodName) {
14160 if (callingPackage == null || mPackageManager == null) {
14161 return;
14162 }
14163
14164 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14165 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014166 Binder.getCallingUserHandle())
14167 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14168 // Skip to check associated telephony feature,
14169 // if compatibility change is not enabled for the current process or
14170 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014171 return;
14172 }
14173
14174 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14175 throw new UnsupportedOperationException(
14176 methodName + " is unsupported without " + telephonyFeature);
14177 }
14178 }
youngtaecha5d483d52024-04-29 17:05:45 +000014179
14180 /**
14181 * Registers for the satellite communication allowed state changed.
14182 *
14183 * @param subId The subId of the subscription to register for the satellite communication
14184 * allowed state changed.
14185 * @param callback The callback to handle the satellite communication allowed
14186 * state changed event.
14187 *
14188 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14189 *
14190 * @throws SecurityException if the caller doesn't have the required permission.
14191 */
14192 @Override
14193 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14194 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14195 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14196 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14197 subId, callback);
14198 }
14199
14200 /**
14201 * Unregisters for the satellite communication allowed state changed.
14202 * If callback was not registered before, the request will be ignored.
14203 *
14204 * @param subId The subId of the subscription to unregister for the satellite communication
14205 * allowed state changed.
14206 * @param callback The callback that was passed to
14207 * {@link #registerForCommunicationAllowedStateChanged(int,
14208 * ISatelliteCommunicationAllowedStateCallback)}. *
14209 * @throws SecurityException if the caller doesn't have the required permission.
14210 */
14211 @Override
14212 public void unregisterForCommunicationAllowedStateChanged(
14213 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14214 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14215 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14216 }
Jack Yufa8ed012023-02-11 15:42:28 -080014217}