blob: 457fdd62f62dd951769d49b91aed99cec01769e5 [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);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003201 if (phone != null && phone.getDataSettingsManager() != 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);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003225 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003226 phone.getDataSettingsManager().setDataEnabled(
3227 TelephonyManager.DATA_ENABLED_REASON_USER, 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
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003965 /**
3966 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3967 * @param message - log message to print.
3968 * @throws SecurityException if the caller does not have the required permission
3969 */
3970 private void enforcePackageUsageStatsPermission(String message) {
3971 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3972 }
3973
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003974 private String createTelUrl(String number) {
3975 if (TextUtils.isEmpty(number)) {
3976 return null;
3977 }
3978
Jake Hambye994d462014-02-03 13:10:13 -08003979 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003980 }
3981
Ihab Awadf9e92732013-12-05 18:02:52 -08003982 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003983 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003984 }
3985
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003986 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003987 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003988 }
3989
Ihab Awadf9e92732013-12-05 18:02:52 -08003990 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003991 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003992 }
3993
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003994 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003995 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003996 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003997 }
3998
Sanket Padawe356d7632015-06-22 14:03:32 -07003999 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004000 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00004001 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4002 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 final Phone phone = PhoneFactory.getPhone(slotIndex);
4007 if (phone == null) {
4008 return PhoneConstants.PHONE_TYPE_NONE;
4009 } else {
4010 return phone.getPhoneType();
4011 }
4012 } finally {
4013 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004015 }
4016
4017 /**
4018 * Returns the CDMA ERI icon index to display
4019 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004020 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004021 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4022 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4023 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004024 }
4025
Sanket Padawe356d7632015-06-22 14:03:32 -07004026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004027 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4028 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004029 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004030 mApp, subId, callingPackage, callingFeatureId,
4031 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004032 return -1;
4033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004034
joonhunshin4ac60942023-11-15 15:23:39 +00004035 enforceTelephonyFeatureWithException(callingPackage,
4036 PackageManager.FEATURE_TELEPHONY_CDMA,
4037 "getCdmaEriIconIndexForSubscriber");
4038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 final Phone phone = getPhone(subId);
4042 if (phone != null) {
4043 return phone.getCdmaEriIconIndex();
4044 } else {
4045 return -1;
4046 }
4047 } finally {
4048 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004049 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004050 }
4051
4052 /**
4053 * Returns the CDMA ERI icon mode,
4054 * 0 - ON
4055 * 1 - FLASHING
4056 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004057 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004058 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4059 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4060 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004061 }
4062
Sanket Padawe356d7632015-06-22 14:03:32 -07004063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004064 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4065 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004067 mApp, subId, callingPackage, callingFeatureId,
4068 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004069 return -1;
4070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004071
4072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 final Phone phone = getPhone(subId);
4075 if (phone != null) {
4076 return phone.getCdmaEriIconMode();
4077 } else {
4078 return -1;
4079 }
4080 } finally {
4081 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004082 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004083 }
4084
4085 /**
4086 * Returns the CDMA ERI text,
4087 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004088 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004089 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4090 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4091 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004092 }
4093
Sanket Padawe356d7632015-06-22 14:03:32 -07004094 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004095 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4096 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004097 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004098 mApp, subId, callingPackage, callingFeatureId,
4099 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004100 return null;
4101 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004102
4103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 final Phone phone = getPhone(subId);
4106 if (phone != null) {
4107 return phone.getCdmaEriText();
4108 } else {
4109 return null;
4110 }
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004114 }
4115
4116 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004117 * Returns the CDMA MDN.
4118 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004119 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004120 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4122 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123
joonhunshin4ac60942023-11-15 15:23:39 +00004124 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4125 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 final long identity = Binder.clearCallingIdentity();
4128 try {
4129 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004130 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004131 return phone.getLine1Number();
4132 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004133 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134 return null;
4135 }
4136 } finally {
4137 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004138 }
4139 }
4140
4141 /**
4142 * Returns the CDMA MIN.
4143 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004144 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004145 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4147 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148
joonhunshin4ac60942023-11-15 15:23:39 +00004149 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4150 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4151
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 final Phone phone = getPhone(subId);
4155 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4156 return phone.getCdmaMin();
4157 } else {
4158 return null;
4159 }
4160 } finally {
4161 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004162 }
4163 }
4164
Hall Liud892bec2018-11-30 14:51:45 -08004165 @Override
4166 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4167 INumberVerificationCallback callback, String callingPackage) {
4168 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4169 != PERMISSION_GRANTED) {
4170 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4171 }
4172 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4173
4174 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4175 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004176 throw new SecurityException("Calling package must be configured in the device config: "
4177 + "calling package: " + callingPackage
4178 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004179 }
4180
joonhunshin4ac60942023-11-15 15:23:39 +00004181 enforceTelephonyFeatureWithException(callingPackage,
4182 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4183
Hall Liud892bec2018-11-30 14:51:45 -08004184 if (range == null) {
4185 throw new NullPointerException("Range must be non-null");
4186 }
4187
4188 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004189 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004190
4191 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4192 }
4193
Junda Liuca05d5d2014-08-14 22:36:34 -07004194 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004195 * Returns true if CDMA provisioning needs to run.
4196 */
4197 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004198 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4199 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004201 final long identity = Binder.clearCallingIdentity();
4202 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004203 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004207 }
4208
4209 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004210 * Sets the voice mail number of a given subId.
4211 */
4212 @Override
4213 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004214 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4215 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004216
joonhunshin4ac60942023-11-15 15:23:39 +00004217 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4218 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004220 final long identity = Binder.clearCallingIdentity();
4221 try {
4222 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4223 new Pair<String, String>(alphaTag, number), new Integer(subId));
4224 return success;
4225 } finally {
4226 Binder.restoreCallingIdentity(identity);
4227 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004228 }
4229
Ta-wei Yen87c49842016-05-13 21:19:52 -07004230 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004231 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4232 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004233 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4234 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004235 if (!TextUtils.equals(callingPackage, systemDialer)) {
4236 throw new SecurityException("caller must be system dialer");
4237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238
joonhunshin4ac60942023-11-15 15:23:39 +00004239 enforceTelephonyFeatureWithException(callingPackage,
4240 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 final long identity = Binder.clearCallingIdentity();
4243 try {
4244 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4245 if (phoneAccountHandle == null) {
4246 return null;
4247 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004248 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249 } finally {
4250 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004251 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004252 }
4253
4254 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004255 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4256 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004257 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004258 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004259 mApp, subId, callingPackage, callingFeatureId,
4260 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004261 return null;
4262 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004263
joonhunshin4ac60942023-11-15 15:23:39 +00004264 enforceTelephonyFeatureWithException(callingPackage,
4265 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4266
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004267 final long identity = Binder.clearCallingIdentity();
4268 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004269 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004270 } finally {
4271 Binder.restoreCallingIdentity(identity);
4272 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004273 }
4274
4275 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004276 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4277 VisualVoicemailSmsFilterSettings settings) {
4278 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004279 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004280 enforceTelephonyFeatureWithException(callingPackage,
4281 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282 final long identity = Binder.clearCallingIdentity();
4283 try {
4284 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004285 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004289 }
4290
4291 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004292 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4293 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004294 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004295 enforceTelephonyFeatureWithException(callingPackage,
4296 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004298 final long identity = Binder.clearCallingIdentity();
4299 try {
4300 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004301 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004305 }
4306
4307 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004308 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4309 String callingPackage, int subId) {
4310 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004311
4312 final long identity = Binder.clearCallingIdentity();
4313 try {
4314 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004315 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004319 }
4320
4321 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004322 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004323 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004324
4325 final long identity = Binder.clearCallingIdentity();
4326 try {
4327 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004328 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004329 } finally {
4330 Binder.restoreCallingIdentity(identity);
4331 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004332 }
4333
4334 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004335 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4336 String callingAttributionTag, int subId, String number, int port, String text,
4337 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004338 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004339 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004340 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004341
4342 enforceTelephonyFeatureWithException(callingPackage,
4343 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4344
Amit Mahajandccb3f12019-05-13 13:48:32 -07004345 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004346 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4347 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004348 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004349
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004350 /**
fionaxu0152e512016-11-14 13:36:14 -08004351 * Sets the voice activation state of a given subId.
4352 */
4353 @Override
4354 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4356 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357
joonhunshin4ac60942023-11-15 15:23:39 +00004358 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4359 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361 final long identity = Binder.clearCallingIdentity();
4362 try {
4363 final Phone phone = getPhone(subId);
4364 if (phone != null) {
4365 phone.setVoiceActivationState(activationState);
4366 } else {
4367 loge("setVoiceActivationState fails with invalid subId: " + subId);
4368 }
4369 } finally {
4370 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004371 }
4372 }
4373
4374 /**
4375 * Sets the data activation state of a given subId.
4376 */
4377 @Override
4378 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4380 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381
joonhunshin4ac60942023-11-15 15:23:39 +00004382 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4383 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004385 final long identity = Binder.clearCallingIdentity();
4386 try {
4387 final Phone phone = getPhone(subId);
4388 if (phone != null) {
4389 phone.setDataActivationState(activationState);
4390 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004391 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392 }
4393 } finally {
4394 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004395 }
4396 }
4397
4398 /**
4399 * Returns the voice activation state of a given subId.
4400 */
4401 @Override
4402 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004403 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404
joonhunshin4ac60942023-11-15 15:23:39 +00004405 enforceTelephonyFeatureWithException(callingPackage,
4406 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4407
fionaxu0152e512016-11-14 13:36:14 -08004408 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 final long identity = Binder.clearCallingIdentity();
4410 try {
4411 if (phone != null) {
4412 return phone.getVoiceActivationState();
4413 } else {
4414 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4415 }
4416 } finally {
4417 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004418 }
4419 }
4420
4421 /**
4422 * Returns the data activation state of a given subId.
4423 */
4424 @Override
4425 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004426 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427
joonhunshin4ac60942023-11-15 15:23:39 +00004428 enforceTelephonyFeatureWithException(callingPackage,
4429 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4430
fionaxu0152e512016-11-14 13:36:14 -08004431 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004432 final long identity = Binder.clearCallingIdentity();
4433 try {
4434 if (phone != null) {
4435 return phone.getDataActivationState();
4436 } else {
4437 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4438 }
4439 } finally {
4440 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004441 }
4442 }
4443
4444 /**
Wink Saville36469e72014-06-11 15:17:00 -07004445 * Returns the unread count of voicemails for a subId
4446 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004447 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004448 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4449 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004451 mApp, subId, callingPackage, callingFeatureId,
4452 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004453 return 0;
4454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 final long identity = Binder.clearCallingIdentity();
4456 try {
4457 final Phone phone = getPhone(subId);
4458 if (phone != null) {
4459 return phone.getVoiceMessageCount();
4460 } else {
4461 return 0;
4462 }
4463 } finally {
4464 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004466 }
4467
4468 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004469 * returns true, if the device is in a state where both voice and data
4470 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004471 */
4472 @Override
4473 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004474 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4475 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 final long identity = Binder.clearCallingIdentity();
4478 try {
Ling Mac28f0212023-03-24 16:07:15 -07004479 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004483 }
4484
4485 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004486 * Send the dialer code if called from the current default dialer or the caller has
4487 * carrier privilege.
4488 * @param inputCode The dialer code to send
4489 */
4490 @Override
4491 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004492 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004494 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4495 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004496 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004497 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004498 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500
joonhunshin4ac60942023-11-15 15:23:39 +00004501 enforceTelephonyFeatureWithException(callingPackage,
4502 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004504 final long identity = Binder.clearCallingIdentity();
4505 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004506 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004507 } finally {
4508 Binder.restoreCallingIdentity(identity);
4509 }
fionaxu235cc5e2017-03-06 22:25:57 -08004510 }
4511
Pengquan Menga1bb6272018-09-06 09:59:22 -07004512 @Override
4513 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004514 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004515 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4516 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004517
4518 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4519 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4520
shilufc958392020-01-20 11:36:01 -08004521 final long identity = Binder.clearCallingIdentity();
4522 try {
4523 if (!isActiveSubscription(subId)) {
4524 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4525 }
4526 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4527 } finally {
4528 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004529 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004530 }
4531
Brad Ebinger35c841c2018-10-01 10:40:55 -07004532 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004533 public boolean isInEmergencySmsMode() {
4534 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004535
4536 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4537 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4538
Brad Ebingerb2b65522019-03-15 13:48:47 -07004539 final long identity = Binder.clearCallingIdentity();
4540 try {
4541 for (Phone phone : PhoneFactory.getPhones()) {
4542 if (phone.isInEmergencySmsMode()) {
4543 return true;
4544 }
4545 }
4546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
4549 return false;
4550 }
4551
shilu366312e2019-12-17 09:28:10 -08004552 /**
4553 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4554 * @param subId The subscription to use to check the configuration.
4555 * @param c The callback that will be used to send the result.
4556 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004557 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004558 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4559 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004560 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004561 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004562
4563 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4564 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4565 "IMS not available on device.");
4566 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004567 final long token = Binder.clearCallingIdentity();
4568 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004569 int slotId = getSlotIndexOrException(subId);
4570 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004571
4572 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4573 if (controller != null) {
4574 ImsManager imsManager = controller.getImsManager(subId);
4575 if (imsManager != null) {
4576 imsManager.addRegistrationCallbackForSubscription(c, subId);
4577 } else {
4578 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4579 }
4580 } else {
4581 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4582 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004583 } catch (ImsException e) {
4584 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004585 } finally {
4586 Binder.restoreCallingIdentity(token);
4587 }
4588 }
4589
shilu366312e2019-12-17 09:28:10 -08004590 /**
4591 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4592 * @param subId The subscription to use to check the configuration.
4593 * @param c The callback that will be used to send the result.
4594 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004595 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004596 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004597 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004598 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004599 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4600 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4601 }
Meng Wangafbc5852019-09-19 17:37:13 -07004602 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004603
Meng Wangafbc5852019-09-19 17:37:13 -07004604 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004605 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4606 if (controller != null) {
4607 ImsManager imsManager = controller.getImsManager(subId);
4608 if (imsManager != null) {
4609 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4610 } else {
4611 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4612 + "is inactive, ignoring unregister.");
4613 // If the ImsManager is not valid, just return, since the callback
4614 // will already have been removed internally.
4615 }
4616 }
Meng Wangafbc5852019-09-19 17:37:13 -07004617 } finally {
4618 Binder.restoreCallingIdentity(token);
4619 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004620 }
4621
Brad Ebingera34a6c22019-10-22 17:36:18 -07004622 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004623 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4624 * @param subId The subscription to use to check the configuration.
4625 * @param c The callback that will be used to send the result.
4626 */
4627 @Override
4628 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4629 throws RemoteException {
4630 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4631 mApp, subId, "registerImsEmergencyRegistrationCallback");
4632
4633 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4634 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4635 "IMS not available on device.");
4636 }
4637 final long token = Binder.clearCallingIdentity();
4638 try {
4639 int slotId = getSlotIndexOrException(subId);
4640 verifyImsMmTelConfiguredOrThrow(slotId);
4641
4642 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4643 if (controller != null) {
4644 ImsManager imsManager = controller.getImsManager(subId);
4645 if (imsManager != null) {
4646 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4647 } else {
4648 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4649 }
4650 } else {
4651 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4652 }
4653 } catch (ImsException e) {
4654 throw new ServiceSpecificException(e.getCode());
4655 } finally {
4656 Binder.restoreCallingIdentity(token);
4657 }
4658 }
4659
4660 /**
4661 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4662 * @param subId The subscription to use to check the configuration.
4663 * @param c The callback that will be used to send the result.
4664 */
4665 @Override
4666 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4667 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4668 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4670 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4671 }
4672 final long token = Binder.clearCallingIdentity();
4673
4674 try {
4675 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4676 if (controller != null) {
4677 ImsManager imsManager = controller.getImsManager(subId);
4678 if (imsManager != null) {
4679 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4680 } else {
4681 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4682 + "is inactive, ignoring unregister.");
4683 // If the ImsManager is not valid, just return, since the callback
4684 // will already have been removed internally.
4685 }
4686 }
4687 } finally {
4688 Binder.restoreCallingIdentity(token);
4689 }
4690 }
4691
4692 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004693 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4694 */
4695 @Override
4696 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4697 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4698 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4699 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4700 "IMS not available on device.");
4701 }
4702 final long token = Binder.clearCallingIdentity();
4703 try {
4704 Phone phone = getPhone(subId);
4705 if (phone == null) {
4706 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4707 + subId + "'");
4708 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4709 }
4710 phone.getImsRegistrationState(regState -> {
4711 try {
4712 consumer.accept((regState == null)
4713 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4714 } catch (RemoteException e) {
4715 // Ignore if the remote process is no longer available to call back.
4716 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4717 }
4718 });
4719 } finally {
4720 Binder.restoreCallingIdentity(token);
4721 }
4722 }
4723
4724 /**
4725 * Get the transport type for the IMS service registration state.
4726 */
4727 @Override
4728 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004729 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004730 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004731 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4732 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4733 "IMS not available on device.");
4734 }
4735 final long token = Binder.clearCallingIdentity();
4736 try {
4737 Phone phone = getPhone(subId);
4738 if (phone == null) {
4739 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4740 + subId + "'");
4741 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4742 }
4743 phone.getImsRegistrationTech(regTech -> {
4744 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4745 int regTechConverted = (regTech == null)
4746 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4747 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4748 regTechConverted);
4749 try {
4750 consumer.accept(regTechConverted);
4751 } catch (RemoteException e) {
4752 // Ignore if the remote process is no longer available to call back.
4753 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4754 }
4755 });
4756 } finally {
4757 Binder.restoreCallingIdentity(token);
4758 }
4759 }
4760
shilu366312e2019-12-17 09:28:10 -08004761 /**
4762 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4763 * @param subId The subscription to use to check the configuration.
4764 * @param c The callback that will be used to send the result.
4765 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004766 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004767 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4768 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004769 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004770 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004771 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4772 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4773 "IMS not available on device.");
4774 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004775 final long token = Binder.clearCallingIdentity();
4776 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004777 int slotId = getSlotIndexOrException(subId);
4778 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004779
4780 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4781 if (controller != null) {
4782 ImsManager imsManager = controller.getImsManager(subId);
4783 if (imsManager != null) {
4784 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4785 } else {
4786 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4787 }
4788 } else {
4789 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4790 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004791 } catch (ImsException e) {
4792 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004793 } finally {
4794 Binder.restoreCallingIdentity(token);
4795 }
4796 }
4797
shilu366312e2019-12-17 09:28:10 -08004798 /**
4799 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4800 * @param subId The subscription to use to check the configuration.
4801 * @param c The callback that will be used to send the result.
4802 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004803 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004804 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004805 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004806 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004807 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4808 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4809 }
Meng Wangafbc5852019-09-19 17:37:13 -07004810
4811 final long token = Binder.clearCallingIdentity();
4812 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004813 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4814 if (controller != null) {
4815 ImsManager imsManager = controller.getImsManager(subId);
4816 if (imsManager != null) {
4817 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4818 } else {
4819 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4820 + " is inactive, ignoring unregister.");
4821 // If the ImsManager is not valid, just return, since the callback
4822 // will already have been removed internally.
4823 }
4824 }
Meng Wangafbc5852019-09-19 17:37:13 -07004825 } finally {
4826 Binder.restoreCallingIdentity(token);
4827 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004828 }
4829
4830 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004831 public boolean isCapable(int subId, int capability, int regTech) {
4832 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004833
4834 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4835 FEATURE_TELEPHONY_IMS, "isCapable");
4836
Brad Ebinger35c841c2018-10-01 10:40:55 -07004837 final long token = Binder.clearCallingIdentity();
4838 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004839 int slotId = getSlotIndexOrException(subId);
4840 verifyImsMmTelConfiguredOrThrow(slotId);
4841 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4842 } catch (com.android.ims.ImsException e) {
4843 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4844 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004845 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004846 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4847 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004848 } finally {
4849 Binder.restoreCallingIdentity(token);
4850 }
4851 }
4852
4853 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004854 public boolean isAvailable(int subId, int capability, int regTech) {
4855 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004856
4857 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4858 FEATURE_TELEPHONY_IMS, "isAvailable");
4859
Brad Ebinger35c841c2018-10-01 10:40:55 -07004860 final long token = Binder.clearCallingIdentity();
4861 try {
4862 Phone phone = getPhone(subId);
4863 if (phone == null) return false;
4864 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004865 } catch (com.android.ims.ImsException e) {
4866 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4867 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004868 } finally {
4869 Binder.restoreCallingIdentity(token);
4870 }
4871 }
4872
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004873 /**
4874 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4875 * subscription.
4876 * @param subId The subscription to use to check the configuration.
4877 * @param callback The callback that will be used to send the result.
4878 * @param capability The MmTelFeature capability that will be used to send the result.
4879 * @param transportType The transport type of the MmTelFeature capability.
4880 */
4881 @Override
4882 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4883 int transportType) {
4884 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004885 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4886 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4887 "IMS not available on device.");
4888 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004889 final long token = Binder.clearCallingIdentity();
4890 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004891 int slotId = getSlotIndex(subId);
4892 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4893 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4894 + subId + "'");
4895 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4896 }
4897 verifyImsMmTelConfiguredOrThrow(slotId);
4898 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4899 transportType, aBoolean -> {
4900 try {
4901 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4902 } catch (RemoteException e) {
4903 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4904 + "running. Ignore");
4905 }
4906 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004907 } catch (ImsException e) {
4908 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004909 } finally {
4910 Binder.restoreCallingIdentity(token);
4911 }
4912 }
4913
shilu366312e2019-12-17 09:28:10 -08004914 /**
4915 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4916 * @param subId The subscription to use to check the configuration.
4917 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004918 @Override
4919 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004920 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004921 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004922
joonhunshin4ac60942023-11-15 15:23:39 +00004923 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4924 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4925
Brad Ebinger35c841c2018-10-01 10:40:55 -07004926 final long token = Binder.clearCallingIdentity();
4927 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004928 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004929 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004930 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004931 } catch (ImsException e) {
4932 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004933 } finally {
4934 Binder.restoreCallingIdentity(token);
4935 }
4936 }
4937
4938 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004939 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004941 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004942
4943 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4944 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4945
Brad Ebinger35c841c2018-10-01 10:40:55 -07004946 final long identity = Binder.clearCallingIdentity();
4947 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004948 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004949 // This setting doesn't require an active ImsService connection, so do not verify. The
4950 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004951 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004952 } catch (ImsException e) {
4953 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004954 } finally {
4955 Binder.restoreCallingIdentity(identity);
4956 }
4957 }
4958
shilu366312e2019-12-17 09:28:10 -08004959 /**
4960 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4961 * @param subId The subscription to use to check the configuration.
4962 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004963 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004964 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004965 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004966 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004967
4968 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4969 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4970
Brad Ebinger35c841c2018-10-01 10:40:55 -07004971 final long identity = Binder.clearCallingIdentity();
4972 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004973 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004974 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004975 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004976 } catch (ImsException e) {
4977 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004978 } finally {
4979 Binder.restoreCallingIdentity(identity);
4980 }
4981 }
4982
4983 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004984 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004986 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004987
4988 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4989 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4990
Brad Ebinger35c841c2018-10-01 10:40:55 -07004991 final long identity = Binder.clearCallingIdentity();
4992 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004993 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004994 // This setting doesn't require an active ImsService connection, so do not verify. The
4995 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004996 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004997 } catch (ImsException e) {
4998 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004999 } finally {
5000 Binder.restoreCallingIdentity(identity);
5001 }
5002 }
5003
shilu366312e2019-12-17 09:28:10 -08005004 /**
5005 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5006 * @param subId The subscription to use to check the configuration.
5007 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005008 @Override
5009 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005010 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005011 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005012
5013 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5014 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5015
Brad Ebinger35c841c2018-10-01 10:40:55 -07005016 final long identity = Binder.clearCallingIdentity();
5017 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005018 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005019 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005020 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005021 } catch (ImsException e) {
5022 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005023 } finally {
5024 Binder.restoreCallingIdentity(identity);
5025 }
5026 }
5027
5028 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005029 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005031 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005032
5033 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5034 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5035
Brad Ebinger35c841c2018-10-01 10:40:55 -07005036 final long identity = Binder.clearCallingIdentity();
5037 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005038 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005039 // This setting doesn't require an active ImsService connection, so do not verify. The
5040 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005041 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005042 } catch (ImsException e) {
5043 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005044 } finally {
5045 Binder.restoreCallingIdentity(identity);
5046 }
5047 }
5048
shilu366312e2019-12-17 09:28:10 -08005049 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005050 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5051 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5052 * @param subId The subscription to use to check the configuration.
5053 */
5054 @Override
5055 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005056 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005057 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005058
5059 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5060 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5061
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005062 final long identity = Binder.clearCallingIdentity();
5063 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005064 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005065 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005066 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005067 } catch (ImsException e) {
5068 throw new ServiceSpecificException(e.getCode());
5069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
5072 }
5073
5074 /**
5075 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5076 * Requires MODIFY_PHONE_STATE permission.
5077 * @param subId The subscription to use to check the configuration.
5078 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5079 * false otherwise
5080 */
5081 @Override
5082 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5084 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005085
5086 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5087 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5088
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005089 final long identity = Binder.clearCallingIdentity();
5090 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005091 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005092 // This setting doesn't require an active ImsService connection, so do not verify. The
5093 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005094 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005095 } catch (ImsException e) {
5096 throw new ServiceSpecificException(e.getCode());
5097 } finally {
5098 Binder.restoreCallingIdentity(identity);
5099 }
5100 }
5101
5102 /**
shilu366312e2019-12-17 09:28:10 -08005103 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5104 * @param subId The subscription to use to check the configuration.
5105 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005106 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005107
Brad Ebinger35c841c2018-10-01 10:40:55 -07005108 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005109 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005110 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005111
5112 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5113 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5114
Brad Ebinger35c841c2018-10-01 10:40:55 -07005115 final long identity = Binder.clearCallingIdentity();
5116 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005117 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005118 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005119 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005120 } catch (ImsException e) {
5121 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005122 } finally {
5123 Binder.restoreCallingIdentity(identity);
5124 }
5125 }
5126
5127 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005128 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005130 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005131
5132 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5133 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5134
Brad Ebinger35c841c2018-10-01 10:40:55 -07005135 final long identity = Binder.clearCallingIdentity();
5136 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005137 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005138 // This setting doesn't require an active ImsService connection, so do not verify. The
5139 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005140 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005141 } catch (ImsException e) {
5142 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005143 } finally {
5144 Binder.restoreCallingIdentity(identity);
5145 }
5146 }
5147
5148 @Override
5149 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5151 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005152
5153 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5154 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5155
Brad Ebinger35c841c2018-10-01 10:40:55 -07005156 final long identity = Binder.clearCallingIdentity();
5157 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005158 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005159 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005160 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005161 } catch (ImsException e) {
5162 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005163 } finally {
5164 Binder.restoreCallingIdentity(identity);
5165 }
5166 }
5167
shilu366312e2019-12-17 09:28:10 -08005168 /**
5169 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5170 * @param subId The subscription to use to check the configuration.
5171 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005172 @Override
5173 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005174 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005175 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005176
5177 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5178 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5179
Brad Ebinger35c841c2018-10-01 10:40:55 -07005180 final long identity = Binder.clearCallingIdentity();
5181 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005182 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005183 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005184 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005185 } catch (ImsException e) {
5186 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005187 } finally {
5188 Binder.restoreCallingIdentity(identity);
5189 }
5190 }
5191
5192 @Override
5193 public void setVoWiFiModeSetting(int subId, int mode) {
5194 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5195 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005196
5197 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5198 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5199
Brad Ebinger35c841c2018-10-01 10:40:55 -07005200 final long identity = Binder.clearCallingIdentity();
5201 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005202 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005203 // This setting doesn't require an active ImsService connection, so do not verify. The
5204 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005205 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005206 } catch (ImsException e) {
5207 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
5211 }
5212
5213 @Override
5214 public int getVoWiFiRoamingModeSetting(int subId) {
5215 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005216
5217 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5218 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5219
Brad Ebinger35c841c2018-10-01 10:40:55 -07005220 final long identity = Binder.clearCallingIdentity();
5221 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005222 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005223 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005224 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005225 } catch (ImsException e) {
5226 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
5230 }
5231
5232 @Override
5233 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5235 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005236
5237 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5238 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5239
Brad Ebinger35c841c2018-10-01 10:40:55 -07005240 final long identity = Binder.clearCallingIdentity();
5241 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005242 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005243 // This setting doesn't require an active ImsService connection, so do not verify. The
5244 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005245 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005246 } catch (ImsException e) {
5247 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005248 } finally {
5249 Binder.restoreCallingIdentity(identity);
5250 }
5251 }
5252
5253 @Override
5254 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5256 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005257
5258 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5259 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5260
Brad Ebinger35c841c2018-10-01 10:40:55 -07005261 final long identity = Binder.clearCallingIdentity();
5262 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005263 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005264 // This setting doesn't require an active ImsService connection, so do not verify. The
5265 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005266 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005267 } catch (ImsException e) {
5268 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005269 } finally {
5270 Binder.restoreCallingIdentity(identity);
5271 }
5272 }
5273
shilu366312e2019-12-17 09:28:10 -08005274 /**
5275 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5276 * @param subId The subscription to use to check the configuration.
5277 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005278 @Override
5279 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005280 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005281 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005282
5283 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5284 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5285
Brad Ebinger35c841c2018-10-01 10:40:55 -07005286 final long identity = Binder.clearCallingIdentity();
5287 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005288 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005289 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005290 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005291 } catch (ImsException e) {
5292 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005293 } finally {
5294 Binder.restoreCallingIdentity(identity);
5295 }
5296 }
5297
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005298 @Override
5299 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5300 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005301
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005302 final long identity = Binder.clearCallingIdentity();
5303 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005304 if (!isImsAvailableOnDevice()) {
5305 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5306 "IMS not available on device.");
5307 }
5308 int slotId = getSlotIndexOrException(subId);
5309 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005310
5311 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5312 if (controller != null) {
5313 ImsManager imsManager = controller.getImsManager(subId);
5314 if (imsManager != null) {
5315 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5316 } else {
5317 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5318 }
5319 } else {
5320 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5321 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005322 } catch (ImsException e) {
5323 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005324 } finally {
5325 Binder.restoreCallingIdentity(identity);
5326 }
5327 }
5328
5329 @Override
5330 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5331 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005332
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005333 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005334 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5335 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5336 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005337 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005338 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5339 if (controller != null) {
5340 ImsManager imsManager = controller.getImsManager(subId);
5341 if (imsManager != null) {
5342 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5343 } else {
5344 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5345 + " is inactive, ignoring unregister.");
5346 // If the ImsManager is not valid, just return, since the callback will already
5347 // have been removed internally.
5348 }
5349 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005350 } finally {
5351 Binder.restoreCallingIdentity(identity);
5352 }
5353 }
5354
joonhunshincffb7fc2021-11-28 07:32:01 +00005355 @Override
5356 public void registerFeatureProvisioningChangedCallback(int subId,
5357 IFeatureProvisioningCallback callback) {
5358 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5359 mApp, subId, "registerFeatureProvisioningChangedCallback");
5360
5361 final long identity = Binder.clearCallingIdentity();
5362 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5363 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5364 }
5365
joonhunshin91bc1952022-04-29 08:47:15 +00005366 try {
5367 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5368 if (controller == null) {
5369 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5370 "Device does not support IMS");
5371 }
5372 controller.addFeatureProvisioningChangedCallback(subId, callback);
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
5375 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005376 }
5377
5378 @Override
5379 public void unregisterFeatureProvisioningChangedCallback(int subId,
5380 IFeatureProvisioningCallback callback) {
5381 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5382 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5383
5384 final long identity = Binder.clearCallingIdentity();
5385 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5386 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5387 }
5388
joonhunshin91bc1952022-04-29 08:47:15 +00005389 try {
5390 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5391 if (controller == null) {
5392 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5393 return;
5394 }
5395 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005399 }
allenwtsu99c623b2020-01-03 18:24:23 +08005400
5401 private void checkModifyPhoneStatePermission(int subId, String message) {
5402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5403 message);
5404 }
5405
allenwtsu99c623b2020-01-03 18:24:23 +08005406 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005407 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005408 boolean isProvisioned) {
5409 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5410
joonhunshin4ac60942023-11-15 15:23:39 +00005411 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5412 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5413
allenwtsu99c623b2020-01-03 18:24:23 +08005414 final long identity = Binder.clearCallingIdentity();
5415 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005416 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5417 if (controller == null) {
5418 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5419 return;
5420 }
5421 controller.setRcsProvisioningStatusForCapability(
5422 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005423 } finally {
5424 Binder.restoreCallingIdentity(identity);
5425 }
allenwtsu99c623b2020-01-03 18:24:23 +08005426 }
5427
5428
5429 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005430 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5431 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5432 mApp, subId, "getRcsProvisioningStatusForCapability");
5433
joonhunshin4ac60942023-11-15 15:23:39 +00005434 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5435 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5436
allenwtsu99c623b2020-01-03 18:24:23 +08005437 final long identity = Binder.clearCallingIdentity();
5438 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005439 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5440 if (controller == null) {
5441 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5442
5443 // device does not support IMS, this method will return true always.
5444 return true;
5445 }
5446 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005447 } finally {
5448 Binder.restoreCallingIdentity(identity);
5449 }
5450 }
5451
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005452 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005453 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5454 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005455 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005456
joonhunshin4ac60942023-11-15 15:23:39 +00005457 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5458 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5459
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005460 final long identity = Binder.clearCallingIdentity();
5461 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005462 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5463 if (controller == null) {
5464 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5465 return;
5466 }
5467 controller.setImsProvisioningStatusForCapability(
5468 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005469 } finally {
5470 Binder.restoreCallingIdentity(identity);
5471 }
5472 }
5473
5474 @Override
5475 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005476 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5477 mApp, subId, "getProvisioningStatusForCapability");
5478
joonhunshin4ac60942023-11-15 15:23:39 +00005479 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5480 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5481
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005482 final long identity = Binder.clearCallingIdentity();
5483 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005484 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5485 if (controller == null) {
5486 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005487
joonhunshin91bc1952022-04-29 08:47:15 +00005488 // device does not support IMS, this method will return true always.
5489 return true;
5490 }
5491 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005492 } finally {
5493 Binder.restoreCallingIdentity(identity);
5494 }
5495 }
5496
5497 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005498 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5499 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5500 mApp, subId, "isProvisioningRequiredForCapability");
5501
joonhunshin4ac60942023-11-15 15:23:39 +00005502 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5503 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5504
joonhunshincffb7fc2021-11-28 07:32:01 +00005505 final long identity = Binder.clearCallingIdentity();
5506 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005507 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5508 if (controller == null) {
5509 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5510
5511 // device does not support IMS, this method will return false
5512 return false;
5513 }
5514 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005515 } finally {
5516 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005517 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005518 }
5519
5520 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005521 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5522 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5523 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005524
joonhunshin4ac60942023-11-15 15:23:39 +00005525 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5526 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5527
joonhunshincffb7fc2021-11-28 07:32:01 +00005528 final long identity = Binder.clearCallingIdentity();
5529 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005530 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5531 if (controller == null) {
5532 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5533
5534 // device does not support IMS, this method will return false
5535 return false;
5536 }
5537 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005538 } finally {
5539 Binder.restoreCallingIdentity(identity);
5540 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005541 }
5542
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005543 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005544 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005545 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5546 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5547 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005548 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5549 mApp, subId, "getImsProvisioningInt");
5550
joonhunshin4ac60942023-11-15 15:23:39 +00005551 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5552 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5553
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005554 final long identity = Binder.clearCallingIdentity();
5555 try {
5556 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005557 int slotId = getSlotIndex(subId);
5558 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5559 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5560 + subId + "' for key:" + key);
5561 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5562 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005563
joonhunshin91bc1952022-04-29 08:47:15 +00005564 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5565 if (controller == null) {
5566 loge("getImsProvisioningInt: Device does not support IMS");
5567
5568 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5569 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5570 }
5571 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005572 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5573 return retVal;
5574 }
5575
calvinpanb5a34062021-02-08 19:59:36 +08005576 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005577 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005578 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5579 + subId + "' for key:" + key);
5580 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005581 } finally {
5582 Binder.restoreCallingIdentity(identity);
5583 }
5584 }
5585
5586 @Override
5587 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005588 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5589 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5590 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005591 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5592 mApp, subId, "getImsProvisioningString");
5593
joonhunshin4ac60942023-11-15 15:23:39 +00005594 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5595 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5596
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005597 final long identity = Binder.clearCallingIdentity();
5598 try {
5599 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005600 int slotId = getSlotIndex(subId);
5601 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5602 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5603 + subId + "' for key:" + key);
5604 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5605 }
calvinpanb5a34062021-02-08 19:59:36 +08005606 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005607 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005608 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5609 + subId + "' for key:" + key);
5610 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
5614 }
5615
5616 @Override
5617 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005618 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5619 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5620 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5622 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005623
joonhunshin4ac60942023-11-15 15:23:39 +00005624 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5625 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5626
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005627 final long identity = Binder.clearCallingIdentity();
5628 try {
5629 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005630 int slotId = getSlotIndex(subId);
5631 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5632 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5633 + subId + "' for key:" + key);
5634 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5635 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005636
joonhunshin91bc1952022-04-29 08:47:15 +00005637 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5638 if (controller == null) {
5639 loge("setImsProvisioningInt: Device does not support IMS");
5640
5641 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5642 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5643 }
5644 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005645 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5646 return retVal;
5647 }
5648
calvinpanb5a34062021-02-08 19:59:36 +08005649 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5650 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005651 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005652 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005653 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
5657 }
5658
5659 @Override
5660 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005661 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5662 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5663 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5665 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005666
5667 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5668 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5669
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005670 final long identity = Binder.clearCallingIdentity();
5671 try {
5672 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005673 int slotId = getSlotIndex(subId);
5674 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5675 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5676 + subId + "' for key:" + key);
5677 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5678 }
calvinpanb5a34062021-02-08 19:59:36 +08005679 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5680 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005681 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005682 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005683 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
5687 }
5688
Brad Ebinger919631e2021-06-02 17:46:35 -07005689 /**
5690 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5691 * for the given slot ID or no ImsResolver instance has been created.
5692 * @param slotId The slot ID that the IMS service is created for.
5693 * @throws ImsException If there is no ImsService configured for this slot.
5694 */
5695 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5696 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5697 ImsFeature.FEATURE_MMTEL)) {
5698 throw new ImsException("This subscription does not support MMTEL over IMS",
5699 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5700 }
5701 }
5702
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005703 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005704 int slotId = SubscriptionManager.getSlotIndex(subId);
5705 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005706 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5707 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005708 }
5709 return slotId;
5710 }
5711
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005712 private int getSlotIndex(int subId) {
5713 int slotId = SubscriptionManager.getSlotIndex(subId);
5714 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5715 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5716 }
5717 return slotId;
5718 }
5719
Wink Saville36469e72014-06-11 15:17:00 -07005720 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005721 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005722 */
5723 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005724 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5725 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005726 try {
5727 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5728 } catch (SecurityException se) {
5729 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5730 throw new SecurityException("Package " + callingPackage + " does not belong to "
5731 + Binder.getCallingUid());
5732 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005733 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005734 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005735 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005736 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005737 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005738 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005739 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005740 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5741 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005742
joonhunshin4ac60942023-11-15 15:23:39 +00005743 enforceTelephonyFeatureWithException(callingPackage,
5744 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 final long identity = Binder.clearCallingIdentity();
5747 try {
5748 final Phone phone = getPhone(subId);
5749 if (phone != null) {
5750 return phone.getServiceState().getDataNetworkType();
5751 } else {
5752 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5753 }
5754 } finally {
5755 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005757 }
5758
5759 /**
5760 * Returns the data network type
5761 */
5762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005763 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005764 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005765 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005766 }
5767
5768 /**
5769 * Returns the data network type for a subId
5770 */
5771 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005772 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5773 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005774 String functionName = "getDataNetworkTypeForSubscriber";
5775 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5776 mApp, functionName)) {
5777 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5778 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5779 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5780 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005781 }
5782
joonhunshin4ac60942023-11-15 15:23:39 +00005783 enforceTelephonyFeatureWithException(callingPackage,
5784 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 final long identity = Binder.clearCallingIdentity();
5787 try {
5788 final Phone phone = getPhone(subId);
5789 if (phone != null) {
5790 return phone.getServiceState().getDataNetworkType();
5791 } else {
5792 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5793 }
5794 } finally {
5795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005797 }
5798
5799 /**
Wink Saville36469e72014-06-11 15:17:00 -07005800 * Returns the Voice network type for a subId
5801 */
5802 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005803 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5804 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005805 String functionName = "getVoiceNetworkTypeForSubscriber";
5806 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5807 mApp, functionName)) {
5808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5809 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5810 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5811 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005812 }
5813
joonhunshin4ac60942023-11-15 15:23:39 +00005814 enforceTelephonyFeatureWithException(callingPackage,
5815 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817 final long identity = Binder.clearCallingIdentity();
5818 try {
5819 final Phone phone = getPhone(subId);
5820 if (phone != null) {
5821 return phone.getServiceState().getVoiceNetworkType();
5822 } else {
5823 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5824 }
5825 } finally {
5826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005828 }
5829
5830 /**
5831 * @return true if a ICC card is present
5832 */
5833 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005834 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005835 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005836 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005837 }
5838
5839 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005840 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005841 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005842 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005843 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005844 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5845 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 final long identity = Binder.clearCallingIdentity();
5848 try {
5849 final Phone phone = PhoneFactory.getPhone(slotIndex);
5850 if (phone != null) {
5851 return phone.getIccCard().hasIccCard();
5852 } else {
5853 return false;
5854 }
5855 } finally {
5856 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005858 }
5859
5860 /**
5861 * Return if the current radio is LTE on CDMA. This
5862 * is a tri-state return value as for a period of time
5863 * the mode may be unknown.
5864 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005865 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005866 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005867 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005868 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005869 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005870 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5871 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5872 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005873 }
5874
Sanket Padawe356d7632015-06-22 14:03:32 -07005875 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005876 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5877 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005878 try {
5879 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5880 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005881 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5882 }
5883
joonhunshin4ac60942023-11-15 15:23:39 +00005884 enforceTelephonyFeatureWithException(callingPackage,
5885 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 final long identity = Binder.clearCallingIdentity();
5888 try {
5889 final Phone phone = getPhone(subId);
5890 if (phone == null) {
5891 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5892 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005893 return TelephonyProperties.lte_on_cdma_device()
5894 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 }
5896 } finally {
5897 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005898 }
Wink Saville36469e72014-06-11 15:17:00 -07005899 }
5900
Wink Saville36469e72014-06-11 15:17:00 -07005901 /**
5902 * {@hide}
5903 * Returns Default subId, 0 in the case of single standby.
5904 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005905 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005906 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005907 }
5908
Shishir Agrawala9f32182016-04-12 12:00:16 -07005909 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005910 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005911 }
5912
Wink Savilleb564aae2014-10-23 10:18:09 -07005913 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005914 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005915 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005916
Pengquan Menge92a50d2018-09-21 15:54:48 -07005917 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005918 return getSubscriptionManagerService().isActiveSubId(subId,
5919 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005920 }
5921
Ihab Awadf2177b72013-11-25 13:33:23 -08005922 /**
5923 * @see android.telephony.TelephonyManager.WifiCallingChoices
5924 */
5925 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926 final long identity = Binder.clearCallingIdentity();
5927 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005928 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5930 getWhenToMakeWifiCallsDefaultPreference());
5931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005934 }
5935
5936 /**
5937 * @see android.telephony.TelephonyManager.WifiCallingChoices
5938 */
5939 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940 final long identity = Binder.clearCallingIdentity();
5941 try {
5942 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005943 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5945 } finally {
5946 Binder.restoreCallingIdentity(identity);
5947 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005948 }
5949
Sailesh Nepald1e68152013-12-12 19:08:02 -08005950 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005951 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005952 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005953 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005954
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005955 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5956 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5957 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005958 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005959 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005960 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005961 }
5962 return PhoneFactory.getPhone(phoneId);
5963 }
5964
Shishir Agrawal566b7612013-10-28 14:41:00 -07005965 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005966 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005967 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005968
Rambo Wanga1782702021-11-10 20:15:19 -08005969 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5970 /*message=*/ "iccOpenLogicalChannel");
5971
5972 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5973 // Verify that the callingPackage in the request belongs to the calling UID
5974 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5975
joonhunshin4ac60942023-11-15 15:23:39 +00005976 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5977 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5978
Rambo Wanga1782702021-11-10 20:15:19 -08005979 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005980 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005981
Rambo Wanga1782702021-11-10 20:15:19 -08005982 private Phone getPhoneFromValidIccLogicalChannelRequest(
5983 @NonNull IccLogicalChannelRequest request, String message) {
5984 Phone phone;
5985 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5987 mApp, request.subId, message);
5988 phone = getPhoneFromSubId(request.subId);
5989 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5990 enforceModifyPermission();
5991 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5992 } else {
5993 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005994 }
Rambo Wanga1782702021-11-10 20:15:19 -08005995 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005996 }
5997
5998 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005999 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 final long identity = Binder.clearCallingIdentity();
6001 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006002 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006004 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6005 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006006 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6007 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 loge("The calling package is not allowed to access ISD-R.");
6009 throw new SecurityException(
6010 "The calling package is not allowed to access ISD-R.");
6011 }
Derek Tan740e1672017-06-27 14:56:27 -07006012 }
Derek Tan740e1672017-06-27 14:56:27 -07006013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006015 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6016 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 return response;
6018 } finally {
6019 Binder.restoreCallingIdentity(identity);
6020 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006021 }
6022
6023 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006024 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006025 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6026 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6027
Rambo Wanga1782702021-11-10 20:15:19 -08006028 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6029 /*message=*/"iccCloseLogicalChannel");
6030
6031 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6032
6033 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006034 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006035
Rambo Wanga1782702021-11-10 20:15:19 -08006036 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6037 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006038 // before this feature is enabled, this API should only return false if
6039 // the operation fails instead of throwing runtime exception for
6040 // backward-compatibility.
6041 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6042 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043 final long identity = Binder.clearCallingIdentity();
6044 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006045 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006046 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047 }
Chen Xue9d737e2022-01-01 23:41:31 -08006048 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006049 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006050 Boolean success = false;
6051 if (result instanceof RuntimeException) {
6052 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006053 if (shouldThrowExceptionOnFailure) {
6054 throw (RuntimeException) result;
6055 } else {
6056 return false;
6057 }
Chen Xue9d737e2022-01-01 23:41:31 -08006058 } else if (result instanceof Boolean) {
6059 success = (Boolean) result;
6060 } else {
6061 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6062 }
Rambo Wanga1782702021-11-10 20:15:19 -08006063 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 return success;
6065 } finally {
6066 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006067 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006068 }
6069
6070 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006071 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006072 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6074 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006075
6076 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6077 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6078
Jordan Liu4c733742019-02-28 12:03:40 -08006079 if (DBG) {
6080 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6081 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6082 + p3 + " data=" + data);
6083 }
6084 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6085 command, p1, p2, p3, data);
6086 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006087
Jordan Liu4c733742019-02-28 12:03:40 -08006088 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006089 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006090 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006091 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006092
6093 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6094 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6095 "iccTransmitApduLogicalChannelBySlot");
6096
Jordan Liu4c733742019-02-28 12:03:40 -08006097 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006098 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006099 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6100 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006101 }
6102 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006103 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6104 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006105 }
6106
6107 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6108 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109 final long identity = Binder.clearCallingIdentity();
6110 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006111 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 return "";
6113 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006116 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6117 null /* workSource */);
6118 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120 // Append the returned status code to the end of the response payload.
6121 String s = Integer.toHexString(
6122 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6123 if (response.payload != null) {
6124 s = IccUtils.bytesToHexString(response.payload) + s;
6125 }
6126 return s;
6127 } finally {
6128 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006129 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006130 }
Jake Hambye994d462014-02-03 13:10:13 -08006131
Evan Charltonc66da362014-05-16 14:06:40 -07006132 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006133 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6134 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6136 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006138
6139 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6140 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6141
Jordan Liu4c733742019-02-28 12:03:40 -08006142 if (DBG) {
6143 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6144 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6145 }
6146 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6147 cla, command, p1, p2, p3, data);
6148 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006149
Jordan Liu4c733742019-02-28 12:03:40 -08006150 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006151 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006152 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006153 enforceModifyPermission();
6154 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006155
6156 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6157 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6158
Jordan Liu4c733742019-02-28 12:03:40 -08006159 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006160 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006161 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6162 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006163 }
6164
6165 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006166 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6167 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006168 }
6169
6170 // open APDU basic channel assuming the caller has sufficient permissions
6171 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6172 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006173 final long identity = Binder.clearCallingIdentity();
6174 try {
6175 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6176 && TextUtils.equals(ISDR_AID, data)) {
6177 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006178 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6179 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006180 if (bestComponent == null
6181 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6182 loge("The calling package is not allowed to select ISD-R.");
6183 throw new SecurityException(
6184 "The calling package is not allowed to select ISD-R.");
6185 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006186 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006189 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6190 null /* workSource */);
6191 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 // Append the returned status code to the end of the response payload.
6194 String s = Integer.toHexString(
6195 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6196 if (response.payload != null) {
6197 s = IccUtils.bytesToHexString(response.payload) + s;
6198 }
6199 return s;
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006202 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006203 }
6204
6205 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006206 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006207 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6209 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006210
joonhunshin4ac60942023-11-15 15:23:39 +00006211 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6212 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 final long identity = Binder.clearCallingIdentity();
6215 try {
6216 if (DBG) {
6217 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6218 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6219 }
6220
6221 IccIoResult response =
6222 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6223 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6224 subId);
6225
6226 if (DBG) {
6227 log("Exchange SIM_IO [R]" + response);
6228 }
6229
6230 byte[] result = null;
6231 int length = 2;
6232 if (response.payload != null) {
6233 length = 2 + response.payload.length;
6234 result = new byte[length];
6235 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6236 } else {
6237 result = new byte[length];
6238 }
6239
6240 result[length - 1] = (byte) response.sw2;
6241 result[length - 2] = (byte) response.sw1;
6242 return result;
6243 } finally {
6244 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006245 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006246 }
6247
Nathan Haroldb3014052017-01-25 15:57:32 -08006248 /**
6249 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6250 * on a particular subscription
6251 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006252 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6253 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006254 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006255 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006256 return null;
6257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258
joonhunshin4ac60942023-11-15 15:23:39 +00006259 enforceTelephonyFeatureWithException(callingPackage,
6260 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 final long identity = Binder.clearCallingIdentity();
6263 try {
6264 if (appType != TelephonyManager.APPTYPE_USIM
6265 && appType != TelephonyManager.APPTYPE_SIM) {
6266 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6267 return null;
6268 }
6269 Object response = sendRequest(
6270 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6271 if (response instanceof String[]) {
6272 return (String[]) response;
6273 }
yincheng zhao2737e882019-09-06 17:06:54 -07006274 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006276 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277 } finally {
6278 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006279 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006280 }
6281
yincheng zhao2737e882019-09-06 17:06:54 -07006282 /**
6283 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6284 * subscription.
6285 *
6286 * @param subId the id of the subscription.
6287 * @param appType the uicc app type, must be USIM or SIM.
6288 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6289 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006290 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006291 * @return number of fplmns that is successfully written to the SIM.
6292 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006293 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6294 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6296 mApp, subId, "setForbiddenPlmns");
6297
joonhunshin4ac60942023-11-15 15:23:39 +00006298 enforceTelephonyFeatureWithException(callingPackage,
6299 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6300
yincheng zhao2737e882019-09-06 17:06:54 -07006301 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6302 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6303 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6304 }
6305 if (fplmns == null) {
6306 throw new IllegalArgumentException("Fplmn List provided is null");
6307 }
6308 for (String fplmn : fplmns) {
6309 if (!CellIdentity.isValidPlmn(fplmn)) {
6310 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6311 }
6312 }
6313 final long identity = Binder.clearCallingIdentity();
6314 try {
6315 Object response = sendRequest(
6316 CMD_SET_FORBIDDEN_PLMNS,
6317 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6318 subId);
6319 return (int) response;
6320 } finally {
6321 Binder.restoreCallingIdentity(identity);
6322 }
6323 }
6324
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006325 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006326 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6328 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006329
joonhunshin4ac60942023-11-15 15:23:39 +00006330 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6331 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333 final long identity = Binder.clearCallingIdentity();
6334 try {
6335 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6336 if (response.payload == null) {
6337 return "";
6338 }
Evan Charltonc66da362014-05-16 14:06:40 -07006339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006340 // Append the returned status code to the end of the response payload.
6341 String s = Integer.toHexString(
6342 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6343 s = IccUtils.bytesToHexString(response.payload) + s;
6344 return s;
6345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
Evan Charltonc66da362014-05-16 14:06:40 -07006348 }
6349
Jake Hambye994d462014-02-03 13:10:13 -08006350 /**
6351 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6352 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6353 *
6354 * @param itemID the ID of the item to read
6355 * @return the NV item as a String, or null on error.
6356 */
6357 @Override
6358 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006359 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6361 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362
6363 final long identity = Binder.clearCallingIdentity();
6364 try {
6365 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006366 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6368 return value;
6369 } finally {
6370 Binder.restoreCallingIdentity(identity);
6371 }
Jake Hambye994d462014-02-03 13:10:13 -08006372 }
6373
6374 /**
6375 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6376 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6377 *
6378 * @param itemID the ID of the item to read
6379 * @param itemValue the value to write, as a String
6380 * @return true on success; false on any failure
6381 */
6382 @Override
6383 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006384 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6386 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387
6388 final long identity = Binder.clearCallingIdentity();
6389 try {
6390 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6391 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006392 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6394 return success;
6395 } finally {
6396 Binder.restoreCallingIdentity(identity);
6397 }
Jake Hambye994d462014-02-03 13:10:13 -08006398 }
6399
6400 /**
6401 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6402 * Used for device configuration by some CDMA operators.
6403 *
6404 * @param preferredRoamingList byte array containing the new PRL
6405 * @return true on success; false on any failure
6406 */
6407 @Override
6408 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6410 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411
6412 final long identity = Binder.clearCallingIdentity();
6413 try {
6414 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6415 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6416 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6417 return success;
6418 } finally {
6419 Binder.restoreCallingIdentity(identity);
6420 }
Jake Hambye994d462014-02-03 13:10:13 -08006421 }
6422
6423 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006424 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006425 * Used for device configuration by some CDMA operators.
6426 *
chen xu6dac5ab2018-10-26 17:39:23 -07006427 * @param slotIndex - device slot.
6428 *
Jake Hambye994d462014-02-03 13:10:13 -08006429 * @return true on success; false on any failure
6430 */
6431 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006432 public boolean resetModemConfig(int slotIndex) {
6433 Phone phone = PhoneFactory.getPhone(slotIndex);
6434 if (phone != null) {
6435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6436 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437
joonhunshin4ac60942023-11-15 15:23:39 +00006438 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6439 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6440
chen xu6dac5ab2018-10-26 17:39:23 -07006441 final long identity = Binder.clearCallingIdentity();
6442 try {
6443 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6444 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6445 return success;
6446 } finally {
6447 Binder.restoreCallingIdentity(identity);
6448 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449 }
chen xu6dac5ab2018-10-26 17:39:23 -07006450 return false;
6451 }
6452
6453 /**
6454 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6455 *
6456 * @param slotIndex - device slot.
6457 *
6458 * @return true on success; false on any failure
6459 */
6460 @Override
6461 public boolean rebootModem(int slotIndex) {
6462 Phone phone = PhoneFactory.getPhone(slotIndex);
6463 if (phone != null) {
6464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6465 mApp, phone.getSubId(), "rebootModem");
6466
joonhunshin4ac60942023-11-15 15:23:39 +00006467 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6468 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6469
chen xu6dac5ab2018-10-26 17:39:23 -07006470 final long identity = Binder.clearCallingIdentity();
6471 try {
6472 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6473 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6474 return success;
6475 } finally {
6476 Binder.restoreCallingIdentity(identity);
6477 }
6478 }
6479 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006480 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006481
Brad Ebinger51f743a2017-01-23 13:50:20 -08006482 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006483 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6484 * {@link #disableIms(int)}.
6485 * @param slotIndex device slot.
6486 */
6487 public void resetIms(int slotIndex) {
6488 enforceModifyPermission();
6489
joonhunshin4ac60942023-11-15 15:23:39 +00006490 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6491 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6492
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006493 final long identity = Binder.clearCallingIdentity();
6494 try {
6495 if (mImsResolver == null) {
6496 // may happen if the does not support IMS.
6497 return;
6498 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006499 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006500 } finally {
6501 Binder.restoreCallingIdentity(identity);
6502 }
6503 }
6504
6505 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006506 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6507 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006508 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006509 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006511
6512 final long identity = Binder.clearCallingIdentity();
6513 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006514 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006515 // may happen if the device does not support IMS.
6516 return;
6517 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006518 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006519 } finally {
6520 Binder.restoreCallingIdentity(identity);
6521 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006522 }
6523
6524 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006525 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6526 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006527 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006528 public void disableIms(int slotId) {
6529 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530
6531 final long identity = Binder.clearCallingIdentity();
6532 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006533 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006534 // may happen if the device does not support IMS.
6535 return;
6536 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006537 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538 } finally {
6539 Binder.restoreCallingIdentity(identity);
6540 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006541 }
6542
6543 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006544 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6545 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006546 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006547 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006548 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006549 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550
6551 final long identity = Binder.clearCallingIdentity();
6552 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006553 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006554 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6555 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006556 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006557 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 } finally {
6559 Binder.restoreCallingIdentity(identity);
6560 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006561 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006562 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006563 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6564 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006565 @Override
6566 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006567 enforceModifyPermission();
6568
6569 final long identity = Binder.clearCallingIdentity();
6570 try {
6571 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006572 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006573 } finally {
6574 Binder.restoreCallingIdentity(identity);
6575 }
6576 }
6577
6578 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006579 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006580 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006581 */
6582 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6583 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584
6585 final long identity = Binder.clearCallingIdentity();
6586 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006587 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006588 // may happen if the device does not support IMS.
6589 return null;
6590 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006591 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592 } finally {
6593 Binder.restoreCallingIdentity(identity);
6594 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006595 }
6596
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006597 /**
6598 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006599 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006600 */
6601 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6602 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603
6604 final long identity = Binder.clearCallingIdentity();
6605 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006606 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006607 // may happen if the device does not support IMS.
6608 return null;
6609 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006610 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611 } finally {
6612 Binder.restoreCallingIdentity(identity);
6613 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006614 }
6615
Brad Ebinger884c07b2018-02-15 16:17:40 -08006616 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006617 * Sets the ImsService Package Name that Telephony will bind to.
6618 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006619 * @param slotIndex the slot ID that the ImsService should bind for.
6620 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006621 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006622 * @param featureTypes An integer array of feature types associated with a packageName.
6623 * @param packageName The name of the package that the current configuration will be replaced
6624 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006625 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006626 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006627 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6628 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006629 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006631 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633 final long identity = Binder.clearCallingIdentity();
6634 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006635 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006636 // may happen if the device does not support IMS.
6637 return false;
6638 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006639 Map<Integer, String> featureConfig = new HashMap<>();
6640 for (int featureType : featureTypes) {
6641 featureConfig.put(featureType, packageName);
6642 }
6643 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6644 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645 } finally {
6646 Binder.restoreCallingIdentity(identity);
6647 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006648 }
6649
6650 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006651 * Clears any carrier ImsService overrides for the slot index specified that were previously
6652 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6653 *
6654 * This should only be used for testing.
6655 *
6656 * @param slotIndex the slot ID that the ImsService should bind for.
6657 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6658 */
6659 @Override
6660 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006661 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6662 "clearCarrierImsServiceOverride");
6663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006664 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006665
6666 final long identity = Binder.clearCallingIdentity();
6667 try {
6668 if (mImsResolver == null) {
6669 // may happen if the device does not support IMS.
6670 return false;
6671 }
6672 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6673 } finally {
6674 Binder.restoreCallingIdentity(identity);
6675 }
6676 }
6677
6678 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006679 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006680 *
6681 * @param slotId The slot that the ImsService is associated with.
6682 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6683 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006684 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006685 * @return the package name of the ImsService configuration.
6686 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006687 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6688 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006689 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006690 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6691 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 final long identity = Binder.clearCallingIdentity();
6694 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006695 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006696 // may happen if the device does not support IMS.
6697 return "";
6698 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006699 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006700 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6701 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702 } finally {
6703 Binder.restoreCallingIdentity(identity);
6704 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006705 }
6706
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006707 /**
6708 * Get the MmTelFeature state associated with the requested subscription id.
6709 * @param subId The subscription that the MmTelFeature is associated with.
6710 * @param callback A callback with an integer containing the
6711 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6712 */
6713 @Override
6714 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6715 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006716 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6717 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6718 "IMS not available on device.");
6719 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006720 final long token = Binder.clearCallingIdentity();
6721 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006722 int slotId = getSlotIndex(subId);
6723 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6724 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6725 + subId + "'");
6726 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6727 }
6728 verifyImsMmTelConfiguredOrThrow(slotId);
6729 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6730 try {
6731 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6732 } catch (RemoteException e) {
6733 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6734 + "Ignore");
6735 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006736 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006737 } catch (ImsException e) {
6738 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006739 } finally {
6740 Binder.restoreCallingIdentity(token);
6741 }
6742 }
6743
Daniel Brightbb5840b2021-01-12 15:48:18 -08006744 /**
6745 * Sets the ims registration state on all valid {@link Phone}s.
6746 */
6747 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749
6750 final long identity = Binder.clearCallingIdentity();
6751 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006752 // NOTE: Before S, this method only set the default phone.
6753 for (final Phone phone : PhoneFactory.getPhones()) {
6754 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6755 phone.setImsRegistrationState(registered);
6756 }
6757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 } finally {
6759 Binder.restoreCallingIdentity(identity);
6760 }
Wink Saville36469e72014-06-11 15:17:00 -07006761 }
6762
6763 /**
Stuart Scott54788802015-03-30 13:18:01 -07006764 * Set the network selection mode to automatic.
6765 *
6766 */
6767 @Override
6768 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6770 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771
joonhunshin4ac60942023-11-15 15:23:39 +00006772 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6773 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 final long identity = Binder.clearCallingIdentity();
6776 try {
shilufc958392020-01-20 11:36:01 -08006777 if (!isActiveSubscription(subId)) {
6778 return;
6779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006781 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6782 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 } finally {
6784 Binder.restoreCallingIdentity(identity);
6785 }
Stuart Scott54788802015-03-30 13:18:01 -07006786 }
6787
Jack Yud10cdd42020-09-28 20:28:01 -07006788 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006789 * Ask the radio to connect to the input network and change selection mode to manual.
6790 *
6791 * @param subId the id of the subscription.
6792 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6793 * the operator to attach to.
6794 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6795 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6796 * normal network selection next time.
6797 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006798 */
6799 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006800 public boolean setNetworkSelectionModeManual(
6801 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6803 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006804
joonhunshin4ac60942023-11-15 15:23:39 +00006805 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6806 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6807
Jack Yu285100e2022-12-02 22:48:35 -08006808 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006809 if (!isActiveSubscription(subId)) {
6810 return false;
6811 }
6812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006814 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006815 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006816 if (DBG) {
6817 log("setNetworkSelectionModeManual: subId: " + subId
6818 + " operator: " + operatorInfo);
6819 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006820 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6821 } finally {
6822 Binder.restoreCallingIdentity(identity);
6823 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006824 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006825 /**
shilu84f6e8b2019-12-19 13:58:01 -08006826 * Get the manual network selection
6827 *
6828 * @param subId the id of the subscription.
6829 *
6830 * @return the previously saved user selected PLMN
6831 */
6832 @Override
6833 public String getManualNetworkSelectionPlmn(int subId) {
6834 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006835 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6836 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006837
joonhunshin4ac60942023-11-15 15:23:39 +00006838 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6839 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6840
shilu84f6e8b2019-12-19 13:58:01 -08006841 final long identity = Binder.clearCallingIdentity();
6842 try {
6843 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006844 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006845 }
6846
6847 final Phone phone = getPhone(subId);
6848 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006849 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006850 }
6851 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6852 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006853 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006854 } finally {
6855 Binder.restoreCallingIdentity(identity);
6856 }
6857 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006858
6859 /**
6860 * Scans for available networks.
6861 */
6862 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006863 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6864 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6866 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006867 LocationAccessPolicy.LocationPermissionResult locationResult =
6868 LocationAccessPolicy.checkLocationPermission(mApp,
6869 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6870 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006871 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006872 .setCallingPid(Binder.getCallingPid())
6873 .setCallingUid(Binder.getCallingUid())
6874 .setMethod("getCellNetworkScanResults")
6875 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006876 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6877 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006878 .build());
6879 switch (locationResult) {
6880 case DENIED_HARD:
6881 throw new SecurityException("Not allowed to access scan results -- location");
6882 case DENIED_SOFT:
6883 return null;
6884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885
Pengquan Menga1bb6272018-09-06 09:59:22 -07006886 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006887 try {
6888 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006889 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 } finally {
6892 Binder.restoreCallingIdentity(identity);
6893 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006894 }
6895
6896 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006897 * Get the call forwarding info, given the call forwarding reason.
6898 */
6899 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006900 public void getCallForwarding(int subId, int callForwardingReason,
6901 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006902 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006903
6904 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6905 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6906
Shuo Qian4a594052020-01-23 11:59:30 -08006907 long identity = Binder.clearCallingIdentity();
6908 try {
6909 if (DBG) {
6910 log("getCallForwarding: subId " + subId
6911 + " callForwardingReason" + callForwardingReason);
6912 }
Hall Liu27d24262020-09-18 19:04:59 -07006913
6914 Phone phone = getPhone(subId);
6915 if (phone == null) {
6916 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006917 callback.onError(
6918 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006919 } catch (RemoteException e) {
6920 // ignore
6921 }
6922 return;
6923 }
6924
6925 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6926 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6927 @Override
6928 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6929 try {
6930 callback.onCallForwardingInfoAvailable(info);
6931 } catch (RemoteException e) {
6932 // ignore
6933 }
6934 }
6935
6936 @Override
6937 public void onError(int error) {
6938 try {
6939 callback.onError(error);
6940 } catch (RemoteException e) {
6941 // ignore
6942 }
6943 }
6944 });
6945 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006946 } finally {
6947 Binder.restoreCallingIdentity(identity);
6948 }
6949 }
6950
6951 /**
6952 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6953 * reason, the number to forward, and the timeout before the forwarding is attempted.
6954 */
6955 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006956 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6957 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006958 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006959
6960 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6961 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6962
Shuo Qian4a594052020-01-23 11:59:30 -08006963 long identity = Binder.clearCallingIdentity();
6964 try {
6965 if (DBG) {
6966 log("setCallForwarding: subId " + subId
6967 + " callForwardingInfo" + callForwardingInfo);
6968 }
Hall Liu27d24262020-09-18 19:04:59 -07006969
6970 Phone phone = getPhone(subId);
6971 if (phone == null) {
6972 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006973 callback.accept(
6974 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006975 } catch (RemoteException e) {
6976 // ignore
6977 }
6978 return;
6979 }
6980
6981 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6982 FunctionalUtils.ignoreRemoteException(callback::accept));
6983
6984 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006985 } finally {
6986 Binder.restoreCallingIdentity(identity);
6987 }
6988 }
6989
6990 /**
Hall Liu27d24262020-09-18 19:04:59 -07006991 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006992 */
6993 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006994 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006995 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006996
6997 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6998 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6999
Shuo Qian4a594052020-01-23 11:59:30 -08007000 long identity = Binder.clearCallingIdentity();
7001 try {
Hall Liu27d24262020-09-18 19:04:59 -07007002 Phone phone = getPhone(subId);
7003 if (phone == null) {
7004 try {
7005 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7006 } catch (RemoteException e) {
7007 // ignore
7008 }
7009 return;
7010 }
SongFerngWang0e767992021-03-31 22:08:45 +08007011 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7012 PersistableBundle c = configManager.getConfigForSubId(subId);
7013 boolean requireUssd = c.getBoolean(
7014 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007015
Shuo Qian4a594052020-01-23 11:59:30 -08007016 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007017 if (requireUssd) {
7018 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7019 getSubscriptionCarrierId(subId));
7020 String newUssdCommand = "";
7021 try {
7022 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007023 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007024 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7025 } catch (NullPointerException e) {
7026 loge("Failed to generate USSD number" + e);
7027 }
7028 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7029 mMainThreadHandler, callback, carrierXmlParser,
7030 CarrierXmlParser.SsEntry.SSAction.QUERY);
7031 final String ussdCommand = newUssdCommand;
7032 Executors.newSingleThreadExecutor().execute(() -> {
7033 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7034 });
7035 } else {
7036 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7037 callback::accept);
7038 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7039 }
Shuo Qian4a594052020-01-23 11:59:30 -08007040 } finally {
7041 Binder.restoreCallingIdentity(identity);
7042 }
7043 }
7044
7045 /**
Hall Liu27d24262020-09-18 19:04:59 -07007046 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007047 */
7048 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007049 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007050 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007051
7052 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7053 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7054
Shuo Qian4a594052020-01-23 11:59:30 -08007055 long identity = Binder.clearCallingIdentity();
7056 try {
Hall Liu27d24262020-09-18 19:04:59 -07007057 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7058
7059 Phone phone = getPhone(subId);
7060 if (phone == null) {
7061 try {
7062 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7063 } catch (RemoteException e) {
7064 // ignore
7065 }
7066 return;
7067 }
7068
SongFerngWang0e767992021-03-31 22:08:45 +08007069 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7070 PersistableBundle c = configManager.getConfigForSubId(subId);
7071 boolean requireUssd = c.getBoolean(
7072 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007073
SongFerngWang0e767992021-03-31 22:08:45 +08007074 if (DBG) log("getCallWaitingStatus: subId " + subId);
7075 if (requireUssd) {
7076 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7077 getSubscriptionCarrierId(subId));
7078 CarrierXmlParser.SsEntry.SSAction ssAction =
7079 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7080 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7081 String newUssdCommand = "";
7082 try {
7083 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007084 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007085 .makeCommand(ssAction, null);
7086 } catch (NullPointerException e) {
7087 loge("Failed to generate USSD number" + e);
7088 }
7089 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7090 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7091 final String ussdCommand = newUssdCommand;
7092 Executors.newSingleThreadExecutor().execute(() -> {
7093 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7094 });
7095 } else {
7096 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7097 FunctionalUtils.ignoreRemoteException(callback::accept));
7098
7099 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7100 }
Shuo Qian4a594052020-01-23 11:59:30 -08007101 } finally {
7102 Binder.restoreCallingIdentity(identity);
7103 }
7104 }
7105
7106 /**
yinxub1bed742017-04-17 11:45:04 -07007107 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007108 *
yinxub1bed742017-04-17 11:45:04 -07007109 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007110 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7111 * location related information which will be sent if the caller already possess
7112 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007113 * @param request contains the radio access networks with bands/channels to scan
7114 * @param messenger callback messenger for scan results or errors
7115 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007116 * @return the id of the requested scan which can be used to stop the scan.
7117 */
7118 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007119 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7120 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007121 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7123 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007124 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007125 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7126 if (!renounceFineLocationAccess) {
7127 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007128 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7129 .setCallingPackage(callingPackage)
7130 .setCallingFeatureId(callingFeatureId)
7131 .setCallingPid(Binder.getCallingPid())
7132 .setCallingUid(Binder.getCallingUid())
7133 .setMethod("requestNetworkScan")
7134 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7135 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7136 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7137 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007138 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007139 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007140 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7141 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007142 if (e != null) {
7143 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7144 throw e;
7145 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007146 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007147 return TelephonyScanManager.INVALID_SCAN_ID;
7148 }
7149 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150 }
joonhunshin4ac60942023-11-15 15:23:39 +00007151
7152 enforceTelephonyFeatureWithException(callingPackage,
7153 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7154
Hall Liu912dfd32019-04-25 14:02:26 -07007155 int callingUid = Binder.getCallingUid();
7156 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007157 final long identity = Binder.clearCallingIdentity();
7158 try {
7159 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007160 renounceFineLocationAccess, request, messenger, binder,
7161 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007162 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007163 } finally {
7164 Binder.restoreCallingIdentity(identity);
7165 }
yinxu504e1392017-04-12 16:03:22 -07007166 }
7167
Hall Liub2ac8ef2019-02-28 15:56:23 -08007168 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007169 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007170 boolean hasCarrierPriv;
7171 final long identity = Binder.clearCallingIdentity();
7172 try {
7173 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7174 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7175 } finally {
7176 Binder.restoreCallingIdentity(identity);
7177 }
Hall Liu558027f2019-05-15 19:14:05 -07007178 boolean hasNetworkScanPermission =
7179 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007180 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007181
7182 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7183 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7184 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007185 }
7186
7187 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7188 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007189 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7190 return new SecurityException("Specific channels must not be"
7191 + " scanned without location access.");
7192 }
7193 }
7194 }
7195
Hall Liub2ac8ef2019-02-28 15:56:23 -08007196 return null;
7197 }
7198
yinxu504e1392017-04-12 16:03:22 -07007199 /**
7200 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007201 *
7202 * @param subId id of the subscription
7203 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007204 */
7205 @Override
7206 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7208 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209
Hall Liu912dfd32019-04-25 14:02:26 -07007210 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 final long identity = Binder.clearCallingIdentity();
7212 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007213 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214 } finally {
7215 Binder.restoreCallingIdentity(identity);
7216 }
yinxu504e1392017-04-12 16:03:22 -07007217 }
7218
7219 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007220 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007221 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007222 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007223 */
7224 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007225 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007226 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007227 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007228 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007229
joonhunshin4ac60942023-11-15 15:23:39 +00007230 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7231 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 final long identity = Binder.clearCallingIdentity();
7234 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007235 if (DBG) log("getAllowedNetworkTypesBitmask");
7236 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7237 int networkTypesBitmask = (result != null ? result[0] : -1);
7238 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7239 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240 } finally {
7241 Binder.restoreCallingIdentity(identity);
7242 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007243 }
7244
7245 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007246 * Get the allowed network types for certain reason.
7247 *
7248 * @param subId the id of the subscription.
7249 * @param reason the reason the allowed network type change is taking place
7250 * @return the allowed network types.
7251 */
7252 @Override
7253 public long getAllowedNetworkTypesForReason(int subId,
7254 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007255 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007256 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007257
7258 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7259 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7260
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007261 final long identity = Binder.clearCallingIdentity();
7262 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007263 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266 }
7267 }
7268
7269 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007270 * Enable/Disable E-UTRA-NR Dual Connectivity
7271 * @param subId subscription id of the sim card
7272 * @param nrDualConnectivityState expected NR dual connectivity state
7273 * This can be passed following states
7274 * <ol>
7275 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7276 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7277 * <li>Disable NR dual connectivity and force secondary cell to be released
7278 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7279 * </ol>
7280 * @return operation result.
7281 */
7282 @Override
7283 public int setNrDualConnectivityState(int subId,
7284 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7286 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007287 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007288 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7289 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7290 }
7291
Sooraj Sasindran37444802020-08-11 10:40:43 -07007292 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7293 final long identity = Binder.clearCallingIdentity();
7294 try {
7295 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7296 nrDualConnectivityState, subId,
7297 workSource);
7298 if (DBG) log("enableNRDualConnectivity result: " + result);
7299 return result;
7300 } finally {
7301 Binder.restoreCallingIdentity(identity);
7302 }
7303 }
7304
7305 /**
7306 * Is E-UTRA-NR Dual Connectivity enabled
7307 * @return true if dual connectivity is enabled else false
7308 */
7309 @Override
7310 public boolean isNrDualConnectivityEnabled(int subId) {
7311 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007312 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007313 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007314 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007315 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7316 return false;
7317 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7322 null, subId, workSource);
7323 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7324 return isEnabled;
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
7327 }
7328 }
7329
7330 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007331 * Set the allowed network types of the device and
7332 * provide the reason triggering the allowed network change.
7333 *
7334 * @param subId the id of the subscription.
7335 * @param reason the reason the allowed network type change is taking place
7336 * @param allowedNetworkTypes the allowed network types.
7337 * @return true on success; false on any failure.
7338 */
7339 @Override
7340 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007341 @TelephonyManager.AllowedNetworkTypesReason int reason,
7342 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7344 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007345 // If the caller only has carrier privileges, then they should not be able to override
7346 // any network types which were set for security reasons.
7347 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7348 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007349 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007350 throw new SecurityException(
7351 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007352 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007353 }
joonhunshin4ac60942023-11-15 15:23:39 +00007354
7355 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7356 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7357
SongFerngWang3ef3e072020-12-21 16:41:52 +08007358 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007359 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007360 return false;
7361 }
7362 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7363 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007364 return false;
7365 }
7366
Jack Yu5b494332023-01-23 18:18:04 +00007367 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7368 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007369
Jack Yue37dd262022-12-16 11:53:37 -08007370 Phone phone = getPhone(subId);
7371 if (phone == null) {
7372 return false;
7373 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007374
Jack Yue37dd262022-12-16 11:53:37 -08007375 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007376 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007377 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007378 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007379
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007380 final long identity = Binder.clearCallingIdentity();
7381 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007382 Boolean success = (Boolean) sendRequest(
7383 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7384 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7385
7386 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7387 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007388 } finally {
7389 Binder.restoreCallingIdentity(identity);
7390 }
7391 }
7392
7393 /**
Miaoa84611c2019-03-15 09:21:10 +08007394 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007395 *
Miaoa84611c2019-03-15 09:21:10 +08007396 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007397 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007398 * @hide
7399 */
7400 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007401 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007402 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007403
7404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7405 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007408 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007409 try {
Miaoa84611c2019-03-15 09:21:10 +08007410 if (phone != null) {
7411 return phone.hasMatchedTetherApnSetting();
7412 } else {
7413 return false;
7414 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 } finally {
7416 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007417 }
Junda Liu475951f2014-11-07 16:45:03 -08007418 }
7419
7420 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007421 * Get the user enabled state of Mobile Data.
7422 *
7423 * TODO: remove and use isUserDataEnabled.
7424 * This can't be removed now because some vendor codes
7425 * calls through ITelephony directly while they should
7426 * use TelephonyManager.
7427 *
7428 * @return true on enabled
7429 */
7430 @Override
7431 public boolean getDataEnabled(int subId) {
7432 return isUserDataEnabled(subId);
7433 }
7434
7435 /**
7436 * Get whether mobile data is enabled per user setting.
7437 *
7438 * There are other factors deciding whether mobile data is actually enabled, but they are
7439 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007440 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007441 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7442 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007443 *
7444 * @return {@code true} if data is enabled else {@code false}
7445 */
7446 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007447 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007448 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007449 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007450 try {
7451 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7452 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007453 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007454 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7455 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007456 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007458 mApp, subId, functionName);
7459
Robert Greenwalt646120a2014-05-23 11:54:03 -07007460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461
7462 final long identity = Binder.clearCallingIdentity();
7463 try {
Jack Yu285100e2022-12-02 22:48:35 -08007464 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7466 Phone phone = PhoneFactory.getPhone(phoneId);
7467 if (phone != null) {
7468 boolean retVal = phone.isUserDataEnabled();
7469 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7470 return retVal;
7471 } else {
7472 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7473 return false;
7474 }
7475 } finally {
7476 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007477 }
7478 }
7479
7480 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007481 * Checks if the device is capable of mobile data by considering whether whether the
7482 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7483 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007484 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007485 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007486 */
7487 @Override
7488 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007489 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007490 try {
7491 try {
7492 mApp.enforceCallingOrSelfPermission(
7493 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007494 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007495 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007496 try {
7497 mApp.enforceCallingOrSelfPermission(
7498 android.Manifest.permission.READ_PHONE_STATE,
7499 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007500 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007501 mApp.enforceCallingOrSelfPermission(
7502 permission.READ_BASIC_PHONE_STATE, functionName);
7503 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007504 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007505 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007506 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508
joonhunshin4ac60942023-11-15 15:23:39 +00007509 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7510 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 final long identity = Binder.clearCallingIdentity();
7513 try {
Jack Yu285100e2022-12-02 22:48:35 -08007514 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007516 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007517 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007518 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007519 return retVal;
7520 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007521 if (DBG) {
7522 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7523 + subId + " retVal=false");
7524 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 return false;
7526 }
7527 } finally {
7528 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007529 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007530 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007531
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007532 /**
7533 * Check if data is enabled for a specific reason
7534 * @param subId Subscription index
7535 * @param reason the reason the data enable change is taking place
7536 * @return {@code true} if the overall data is enabled; {@code false} if not.
7537 */
7538 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007539 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007540 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007541 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007542 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007543 try {
7544 mApp.enforceCallingOrSelfPermission(
7545 android.Manifest.permission.ACCESS_NETWORK_STATE,
7546 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007547 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007548 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7549 functionName);
7550 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007551 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007552 try {
7553 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007554 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007555 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007557 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007558 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007559 }
7560
joonhunshin4ac60942023-11-15 15:23:39 +00007561 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7562 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007563
7564 final long identity = Binder.clearCallingIdentity();
7565 try {
Jack Yu285100e2022-12-02 22:48:35 -08007566 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007567 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007568 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007569 + " reason=" + reason);
7570 }
7571 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007572 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007573 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007574 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007575 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007576 return retVal;
7577 } else {
7578 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007579 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007580 + subId + " retVal=false");
7581 }
7582 return false;
7583 }
7584 } finally {
7585 Binder.restoreCallingIdentity(identity);
7586 }
7587 }
7588
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007589 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007590 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007591 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7592 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7593
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007594 // No permission needed; this only lets the caller inspect their own status.
7595 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007596 }
Junda Liu29340342014-07-10 15:23:27 -07007597
7598 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007599 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007600 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007601
7602 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7603 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7604
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007605 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7606 }
7607
7608 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7609 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007610 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007611 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007612 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7613 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007614 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7615 if (cpt == null) {
7616 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007617 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7618 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007619 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007620 }
7621
7622 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007623 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007624 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007625
7626 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7627 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7628
chen xuf7e9fe82019-05-09 19:31:02 -07007629 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007630 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007631 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007632 Phone phone = getPhone(subId);
7633 if (phone == null) {
7634 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7635 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7636 }
7637 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7638 if (cpt == null) {
7639 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007640 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7641 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007642 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007643 }
7644
7645 @Override
7646 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007647 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007648
7649 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7650 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7651 "checkCarrierPrivilegesForPackageAnyPhone");
7652
Rambo Wange7209ce2022-02-23 13:41:02 -08007653 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7654 }
7655
7656 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007657 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007658 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007659 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007660 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007661 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7662 Phone phone = PhoneFactory.getPhone(phoneId);
7663 if (phone == null) {
7664 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007665 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007666 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7667 if (cpt == null) {
7668 continue;
7669 }
7670 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007671 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7672 break;
7673 }
7674 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007675 return result;
Junda Liu29340342014-07-10 15:23:27 -07007676 }
Derek Tan89e89d42014-07-08 17:00:10 -07007677
7678 @Override
Junda Liue64de782015-04-16 17:19:16 -07007679 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007680 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007681
7682 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7683 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7684 "getCarrierPackageNamesForIntentAndPhone");
7685
Rambo Wang8a247eb2022-02-08 21:11:18 +00007686 Phone phone = PhoneFactory.getPhone(phoneId);
7687 if (phone == null) {
7688 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007689 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007690 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7691 if (cpt == null) {
7692 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007693 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007694 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007695 }
7696
Amith Yamasani6e118872016-02-19 12:53:51 -08007697 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007698 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007699 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007700 Phone phone = PhoneFactory.getPhone(phoneId);
7701 if (phone == null) {
7702 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007703 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007704 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7705 if (cpt == null) {
7706 return Collections.emptyList();
7707 }
7708 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007709 }
7710
chen xuf7e9fe82019-05-09 19:31:02 -07007711 @Override
7712 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007713 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007714
7715 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7716 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7717 "getPackagesWithCarrierPrivilegesForAllPhones");
7718
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007719 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007720 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007721 try {
7722 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7723 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7724 }
7725 } finally {
7726 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007727 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007728 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007729 }
7730
Rambo Wang6812ffb2022-03-15 16:54:17 -07007731 @Override
7732 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7733 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7734
joonhunshin4ac60942023-11-15 15:23:39 +00007735 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7736 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7737 "getCarrierServicePackageNameForLogicalSlot");
7738
Rambo Wang6812ffb2022-03-15 16:54:17 -07007739 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7740 if (phone == null) {
7741 return null;
7742 }
7743 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7744 if (cpt == null) {
7745 return null;
7746 }
7747 return cpt.getCarrierServicePackageName();
7748 }
7749
Wink Savilleb564aae2014-10-23 10:18:09 -07007750 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007751 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007752 UiccPort port = phone == null ? null : phone.getUiccPort();
7753 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007754 return null;
7755 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007756 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007757 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007758 return null;
7759 }
7760 return iccId;
7761 }
7762
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007763 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007764 public void setCallComposerStatus(int subId, int status) {
7765 enforceModifyPermission();
7766
joonhunshin4ac60942023-11-15 15:23:39 +00007767 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7768 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7769
Shuo Qiane4e11672020-12-15 22:15:33 -08007770 final long identity = Binder.clearCallingIdentity();
7771 try {
7772 Phone phone = getPhone(subId);
7773 if (phone != null) {
7774 Phone defaultPhone = phone.getImsPhone();
7775 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7776 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7777 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007778 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7779 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007780 }
7781 }
Shuo Qian284ae752020-12-22 19:10:14 -08007782 } catch (ImsException e) {
7783 throw new ServiceSpecificException(e.getCode());
7784 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007785 Binder.restoreCallingIdentity(identity);
7786 }
7787 }
7788
7789 @Override
7790 public int getCallComposerStatus(int subId) {
7791 enforceReadPrivilegedPermission("getCallComposerStatus");
7792
joonhunshin4ac60942023-11-15 15:23:39 +00007793 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7794 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7795
Shuo Qiane4e11672020-12-15 22:15:33 -08007796 final long identity = Binder.clearCallingIdentity();
7797 try {
7798 Phone phone = getPhone(subId);
7799 if (phone != null) {
7800 Phone defaultPhone = phone.getImsPhone();
7801 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7802 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7803 return imsPhone.getCallComposerStatus();
7804 }
7805 }
7806 } finally {
7807 Binder.restoreCallingIdentity(identity);
7808 }
7809 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7810 }
7811
7812 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007813 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7814 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007815 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007816 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007817
joonhunshin4ac60942023-11-15 15:23:39 +00007818 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7819 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7820 "setLine1NumberForDisplayForSubscriber");
7821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 final long identity = Binder.clearCallingIdentity();
7823 try {
7824 final String iccId = getIccId(subId);
7825 final Phone phone = getPhone(subId);
7826 if (phone == null) {
7827 return false;
7828 }
7829 final String subscriberId = phone.getSubscriberId();
7830
7831 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007832 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007833 + subscriberId + " to " + number);
7834 }
7835
7836 if (TextUtils.isEmpty(iccId)) {
7837 return false;
7838 }
7839
7840 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7841
7842 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7843 if (alphaTag == null) {
7844 editor.remove(alphaTagPrefKey);
7845 } else {
7846 editor.putString(alphaTagPrefKey, alphaTag);
7847 }
7848
7849 // Record both the line number and IMSI for this ICCID, since we need to
7850 // track all merged IMSIs based on line number
7851 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7852 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7853 if (number == null) {
7854 editor.remove(numberPrefKey);
7855 editor.remove(subscriberPrefKey);
7856 } else {
7857 editor.putString(numberPrefKey, number);
7858 editor.putString(subscriberPrefKey, subscriberId);
7859 }
7860
7861 editor.commit();
7862 return true;
7863 } finally {
7864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007865 }
Derek Tan7226c842014-07-02 17:42:23 -07007866 }
7867
7868 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007869 public String getLine1NumberForDisplay(int subId, String callingPackage,
7870 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007871 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007873 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007874 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007875 return null;
7876 }
Derek Tan97ebb422014-09-05 16:55:38 -07007877
joonhunshin4ac60942023-11-15 15:23:39 +00007878 enforceTelephonyFeatureWithException(callingPackage,
7879 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007881 final long identity = Binder.clearCallingIdentity();
7882 try {
7883 String iccId = getIccId(subId);
7884 if (iccId != null) {
7885 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7886 if (DBG_MERGE) {
7887 log("getLine1NumberForDisplay returning "
7888 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7889 }
7890 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007891 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007892 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7893 return null;
7894 } finally {
7895 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007896 }
Derek Tan7226c842014-07-02 17:42:23 -07007897 }
7898
7899 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007900 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7901 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007902 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007903 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007904 return null;
7905 }
Derek Tan97ebb422014-09-05 16:55:38 -07007906
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907 final long identity = Binder.clearCallingIdentity();
7908 try {
7909 String iccId = getIccId(subId);
7910 if (iccId != null) {
7911 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7912 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7913 }
7914 return null;
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007917 }
Derek Tan7226c842014-07-02 17:42:23 -07007918 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007919
7920 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007921 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7922 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007923 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7924 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007926 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007927 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007928 return null;
7929 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007930
Jordan Liub49b04b2019-05-06 14:45:15 -07007931 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7932 // the process, where TelephonyManager was instantiated.
7933 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007934 final long identity = Binder.clearCallingIdentity();
7935 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007936 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 final TelephonyManager tele = TelephonyManager.from(context);
7938 final SubscriptionManager sub = SubscriptionManager.from(context);
7939
7940 // Figure out what subscribers are currently active
7941 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942
Jordan Liub49b04b2019-05-06 14:45:15 -07007943 // Only consider subs which match the current subId
7944 // This logic can be simplified. See b/131189269 for progress.
7945 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007946 activeSubscriberIds.add(tele.getSubscriberId(subId));
7947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948
7949 // First pass, find a number override for an active subscriber
7950 String mergeNumber = null;
7951 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7952 for (String key : prefs.keySet()) {
7953 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7954 final String subscriberId = (String) prefs.get(key);
7955 if (activeSubscriberIds.contains(subscriberId)) {
7956 final String iccId = key.substring(
7957 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7958 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7959 mergeNumber = (String) prefs.get(numberKey);
7960 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007961 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962 + " for active subscriber " + subscriberId);
7963 }
7964 if (!TextUtils.isEmpty(mergeNumber)) {
7965 break;
7966 }
7967 }
7968 }
7969 }
7970
7971 // Shortcut when no active merged subscribers
7972 if (TextUtils.isEmpty(mergeNumber)) {
7973 return null;
7974 }
7975
7976 // Second pass, find all subscribers under that line override
7977 final ArraySet<String> result = new ArraySet<>();
7978 for (String key : prefs.keySet()) {
7979 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7980 final String number = (String) prefs.get(key);
7981 if (mergeNumber.equals(number)) {
7982 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7983 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7984 final String subscriberId = (String) prefs.get(subscriberKey);
7985 if (!TextUtils.isEmpty(subscriberId)) {
7986 result.add(subscriberId);
7987 }
7988 }
7989 }
7990 }
7991
7992 final String[] resultArray = result.toArray(new String[result.size()]);
7993 Arrays.sort(resultArray);
7994 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007995 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7997 }
7998 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007999 } finally {
8000 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008001 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008002 }
8003
8004 @Override
zoey chen38003472019-12-13 17:16:31 +08008005 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8006 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008007
joonhunshin4ac60942023-11-15 15:23:39 +00008008 enforceTelephonyFeatureWithException(callingPackage,
8009 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8010
Malcolm Chen6ca97372019-07-01 16:28:21 -07008011 final long identity = Binder.clearCallingIdentity();
8012 try {
8013 final TelephonyManager telephonyManager = mApp.getSystemService(
8014 TelephonyManager.class);
8015 String subscriberId = telephonyManager.getSubscriberId(subId);
8016 if (subscriberId == null) {
8017 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008018 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008019 + subId);
8020 }
8021 return null;
8022 }
8023
Jack Yu3beaf9d2023-04-14 09:17:27 -07008024 final SubscriptionInfo info = getSubscriptionManagerService()
8025 .getSubscriptionInfo(subId);
8026 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008027 // If it doesn't belong to any group, return just subscriberId of itself.
8028 if (groupUuid == null) {
8029 return new String[]{subscriberId};
8030 }
8031
8032 // Get all subscriberIds from the group.
8033 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008034 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8035 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8036 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008037 for (SubscriptionInfo subInfo : groupInfos) {
8038 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8039 if (subscriberId != null) {
8040 mergedSubscriberIds.add(subscriberId);
8041 }
8042 }
8043
8044 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8045 } finally {
8046 Binder.restoreCallingIdentity(identity);
8047
8048 }
8049 }
8050
8051 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008052 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008053 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008054 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055
joonhunshin4ac60942023-11-15 15:23:39 +00008056 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8057 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008059 final long identity = Binder.clearCallingIdentity();
8060 try {
8061 final Phone phone = getPhone(subId);
8062 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8063 } finally {
8064 Binder.restoreCallingIdentity(identity);
8065 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008066 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008067
8068 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008069 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008070 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8071 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008072 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8073 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074
8075 final long identity = Binder.clearCallingIdentity();
8076 try {
8077 final Phone phone = getPhone(subId);
8078 if (phone == null) {
8079 return false;
8080 }
8081 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8082 cdmaNonRoamingList);
8083 } finally {
8084 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008085 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008086 }
8087
8088 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008089 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008090 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008091 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008092 if (phone == null) {
8093 return raf;
8094 }
8095
Shuo Qiandee53402020-05-29 14:08:15 -07008096 try {
8097 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008098 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008099 mApp, phone.getSubId(), "getRadioAccessFamily");
8100 } catch (SecurityException e) {
8101 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8102 throw e;
8103 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008104
joonhunshin4ac60942023-11-15 15:23:39 +00008105 enforceTelephonyFeatureWithException(callingPackage,
8106 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8107
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 final long identity = Binder.clearCallingIdentity();
8109 try {
chen xub97461a2018-10-26 14:17:57 -07008110 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111 } finally {
8112 Binder.restoreCallingIdentity(identity);
8113 }
chen xub97461a2018-10-26 14:17:57 -07008114 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008115 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008116
8117 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008118 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008119 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008120 try {
8121 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8122 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008123 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008124 }
8125 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008126 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008127 }
joonhunshin4ac60942023-11-15 15:23:39 +00008128
8129 enforceTelephonyFeatureWithException(callingPackage,
8130 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8131
Hall Liu82694d52020-12-11 18:22:04 -08008132 RoleManager rm = mApp.getSystemService(RoleManager.class);
8133 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8134 if (!dialerRoleHolders.contains(callingPackage)) {
8135 throw new SecurityException("App must be the dialer role holder to"
8136 + " upload a call composer pic");
8137 }
8138
8139 Executors.newSingleThreadExecutor().execute(() -> {
8140 ByteArrayOutputStream output = new ByteArrayOutputStream(
8141 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8142 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8143 boolean readUntilEnd = false;
8144 int totalBytesRead = 0;
8145 byte[] buffer = new byte[16 * 1024];
8146 while (true) {
8147 int numRead;
8148 try {
8149 numRead = input.read(buffer);
8150 } catch (IOException e) {
8151 try {
8152 fd.checkError();
8153 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8154 null);
8155 } catch (IOException e1) {
8156 // This means that the other side closed explicitly with an error. If this
8157 // happens, log and ignore.
8158 loge("Remote end of call composer picture pipe closed: " + e1);
8159 }
8160 break;
8161 }
8162 if (numRead == -1) {
8163 readUntilEnd = true;
8164 break;
8165 }
8166 totalBytesRead += numRead;
8167 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8168 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8169 try {
8170 input.close();
8171 } catch (IOException e) {
8172 // ignore
8173 }
8174 break;
8175 }
8176 output.write(buffer, 0, numRead);
8177 }
8178 // Generally, the remote end will close the file descriptors. The only case where we
8179 // close is above, where the picture size is too big.
8180
8181 try {
8182 fd.checkError();
8183 } catch (IOException e) {
8184 loge("Remote end for call composer closed with an error: " + e);
8185 return;
8186 }
8187
Hall Liuaa4211e2021-01-20 15:43:39 -08008188 if (!readUntilEnd) {
8189 loge("Did not finish reading entire image; aborting");
8190 return;
8191 }
Hall Liu82694d52020-12-11 18:22:04 -08008192
Hall Liuaa4211e2021-01-20 15:43:39 -08008193 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8194 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8195 new CallComposerPictureTransfer.Factory() {},
8196 imageData,
8197 (result) -> {
8198 if (result.first != null) {
8199 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8200 Bundle outputResult = new Bundle();
8201 outputResult.putParcelable(
8202 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8203 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8204 outputResult);
8205 } else {
8206 callback.send(result.second, null);
8207 }
8208 }
8209 );
Hall Liu82694d52020-12-11 18:22:04 -08008210 });
8211 }
8212
8213 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008214 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008215 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008216 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217
joonhunshin4ac60942023-11-15 15:23:39 +00008218 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8219 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 final long identity = Binder.clearCallingIdentity();
8222 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008223 ImsManager.getInstance(defaultPhone.getContext(),
8224 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 } finally {
8226 Binder.restoreCallingIdentity(identity);
8227 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008228 }
8229
8230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008231 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008232 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8234 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008235 return false;
8236 }
Svet Ganovb320e182015-04-16 12:30:10 -07008237
joonhunshin4ac60942023-11-15 15:23:39 +00008238 enforceTelephonyFeatureWithException(callingPackage,
8239 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 final long identity = Binder.clearCallingIdentity();
8242 try {
8243 // Check the user preference and the system-level IMS setting. Even if the user has
8244 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8245 // In the long run, we may instead need to check if there exists a connection service
8246 // which can support video calling.
8247 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008248 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 return imsManager.isVtEnabledByPlatform()
8250 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8251 && imsManager.isVtEnabledByUser();
8252 } finally {
8253 Binder.restoreCallingIdentity(identity);
8254 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008255 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008256
Andrew Leea1239f22015-03-02 17:44:07 -08008257 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008258 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8259 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008261 mApp, subId, callingPackage, callingFeatureId,
8262 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008263 return false;
8264 }
8265
joonhunshin4ac60942023-11-15 15:23:39 +00008266 enforceTelephonyFeatureWithException(callingPackage,
8267 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008269 final long identity = Binder.clearCallingIdentity();
8270 try {
8271 CarrierConfigManager configManager =
8272 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008273 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8275 } finally {
8276 Binder.restoreCallingIdentity(identity);
8277 }
Andrew Leea1239f22015-03-02 17:44:07 -08008278 }
8279
8280 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008281 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008283 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008284 return false;
8285 }
8286
joonhunshin4ac60942023-11-15 15:23:39 +00008287 enforceTelephonyFeatureWithException(callingPackage,
8288 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008290 final long identity = Binder.clearCallingIdentity();
8291 try {
8292 CarrierConfigManager configManager =
8293 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008294 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008295 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8296 } finally {
8297 Binder.restoreCallingIdentity(identity);
8298 }
Andrew Leea1239f22015-03-02 17:44:07 -08008299 }
8300
Andrew Lee9431b832015-03-09 18:46:45 -07008301 @Override
8302 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008303 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008304 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008305 }
8306
8307 @Override
8308 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008309 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8310 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312 final long identity = Binder.clearCallingIdentity();
8313 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008314 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315 } finally {
8316 Binder.restoreCallingIdentity(identity);
8317 }
Andrew Lee9431b832015-03-09 18:46:45 -07008318 }
8319
Hall Liuf6668912018-10-31 17:05:23 -07008320 /**
8321 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8322 * support for the feature and device firmware support.
8323 *
8324 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8325 */
8326 @Override
8327 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008328 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8329 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008332 final Phone phone = getPhone(subscriptionId);
8333 if (phone == null) {
8334 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8335 return false;
8336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008338 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008340 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8341 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8342 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343 return isCarrierSupported && isDeviceSupported;
8344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
Hall Liu98187582018-01-22 19:15:32 -08008347 }
8348
Hall Liuf6668912018-10-31 17:05:23 -07008349 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008350 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8351 * RTT setting, will return true if the device and carrier both support RTT.
8352 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008353 */
8354 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008355 final long identity = Binder.clearCallingIdentity();
8356 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008357 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8358 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8359 return false;
8360 }
8361 }
8362
Hall Liu5bab75c2019-12-11 23:58:20 +00008363 boolean isRttSupported = isRttSupported(subscriptionId);
8364 boolean isUserRttSettingOn = Settings.Secure.getInt(
8365 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8366 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8367 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8368 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369 } finally {
8370 Binder.restoreCallingIdentity(identity);
8371 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008372 }
8373
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008374 @Deprecated
8375 @Override
8376 public String getDeviceId(String callingPackage) {
8377 return getDeviceIdWithFeature(callingPackage, null);
8378 }
8379
Sanket Padawe7310cc72015-01-14 09:53:20 -08008380 /**
8381 * Returns the unique device ID of phone, for example, the IMEI for
8382 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8383 *
8384 * <p>Requires Permission:
8385 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8386 */
8387 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008388 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008389 try {
8390 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8391 } catch (SecurityException se) {
8392 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8393 throw new SecurityException("Package " + callingPackage + " does not belong to "
8394 + Binder.getCallingUid());
8395 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008396 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008397 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008398 return null;
8399 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008400 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008401 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008402 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008403 return null;
8404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008405
8406 final long identity = Binder.clearCallingIdentity();
8407 try {
8408 return phone.getDeviceId();
8409 } finally {
8410 Binder.restoreCallingIdentity(identity);
8411 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008412 }
8413
Ping Sunc67b7c22016-03-02 19:16:45 +08008414 /**
8415 * {@hide}
8416 * Returns the IMS Registration Status on a particular subid
8417 *
8418 * @param subId
8419 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008420 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008421 Phone phone = getPhone(subId);
8422 if (phone != null) {
8423 return phone.isImsRegistered();
8424 } else {
8425 return false;
8426 }
8427 }
8428
Santos Cordon7a1885b2015-02-03 11:15:19 -08008429 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008430 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008431 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008433 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008434 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8435 }
8436 final long identity = Binder.clearCallingIdentity();
8437 try {
8438 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8439 } finally {
8440 Binder.restoreCallingIdentity(identity);
8441 }
8442 }
8443
8444 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008445 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008446 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008447 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008448 mApp,
8449 subscriptionId,
8450 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8451 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008452
8453 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8454 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8455
Tyler Gunnf70ed162019-04-03 15:28:53 -07008456 final long identity = Binder.clearCallingIdentity();
8457 try {
8458 Phone phone = getPhone(subscriptionId);
8459 if (phone == null) {
8460 return null;
8461 }
8462 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8463 } finally {
8464 Binder.restoreCallingIdentity(identity);
8465 }
8466 }
8467
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008468 /**
8469 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008470 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008471 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008472 final long identity = Binder.clearCallingIdentity();
8473 try {
8474 Phone phone = getPhone(subId);
8475 if (phone != null) {
8476 return phone.isWifiCallingEnabled();
8477 } else {
8478 return false;
8479 }
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008482 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008483 }
8484
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008485 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008486 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008487 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008488 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008489 final long identity = Binder.clearCallingIdentity();
8490 try {
8491 Phone phone = getPhone(subId);
8492 if (phone != null) {
8493 return phone.isVideoEnabled();
8494 } else {
8495 return false;
8496 }
8497 } finally {
8498 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008499 }
8500 }
8501
8502 /**
8503 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8504 * defined in {@link ImsRegistrationImplBase}.
8505 */
8506 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008507 final long identity = Binder.clearCallingIdentity();
8508 try {
8509 Phone phone = getPhone(subId);
8510 if (phone != null) {
8511 return phone.getImsRegistrationTech();
8512 } else {
8513 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8514 }
8515 } finally {
8516 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008517 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008518 }
8519
Stuart Scott8eef64f2015-04-08 15:13:54 -07008520 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008521 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008522 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008523
8524 enforceTelephonyFeatureWithException(callingPackage,
8525 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8526
Stuart Scott981d8582015-04-21 14:09:50 -07008527 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8528 return;
8529 }
Kai Shif70f46f2021-03-03 13:59:46 -08008530 Phone defaultPhone = getDefaultPhone();
8531 if (defaultPhone != null) {
8532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8533 mApp, getDefaultPhone().getSubId(), "factoryReset");
8534 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008535 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008536
Svet Ganovcc087f82015-05-12 20:35:54 -07008537 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008538 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8539 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008540 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008541 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008542 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008543 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008544 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008545 setDataRoamingEnabled(subId, phone == null ? false
8546 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008547 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008548 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008549 // There has been issues when Sms raw table somehow stores orphan
8550 // fragments. They lead to garbled message when new fragments come
8551 // in and combined with those stale ones. In case this happens again,
8552 // user can reset all network settings which will clean up this table.
8553 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008554 // Clean up IMS settings as well here.
8555 int slotId = getSlotIndex(subId);
8556 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8557 ImsManager.getInstance(mApp, slotId).factoryReset();
8558 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008559
Kai Shif70f46f2021-03-03 13:59:46 -08008560 if (defaultPhone == null) {
8561 return;
8562 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008563 // Erase modem config if erase modem on network setting is enabled.
8564 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8565 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8566 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008567 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008568 }
Kai Shif70f46f2021-03-03 13:59:46 -08008569
8570 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008571 } finally {
8572 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008573 }
8574 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008575
SongFerngWangfd89b102021-05-27 22:44:54 +08008576 @VisibleForTesting
8577 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8578 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8579 return;
8580 }
8581 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8582 RILConstants.PREFERRED_NETWORK_MODE);
8583 SubscriptionManager.setSubscriptionProperty(subId,
8584 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8585 "user=" + defaultNetworkType);
8586 phone.loadAllowedNetworksFromSubscriptionDatabase();
8587 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8588 defaultNetworkType, null);
8589 }
8590
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008591 private void cleanUpSmsRawTable(Context context) {
8592 ContentResolver resolver = context.getContentResolver();
8593 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8594 resolver.delete(uri, null, null);
8595 }
8596
Narayan Kamath1c496c22015-04-16 14:40:19 +01008597 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008598 public String getSimLocaleForSubscriber(int subId) {
8599 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008600
8601 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8602 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8603
chen xu5d3637b2019-01-21 23:31:38 -08008604 final Phone phone = getPhone(subId);
8605 if (phone == null) {
8606 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008607 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008609 final long identity = Binder.clearCallingIdentity();
8610 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008611 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8612 phone.getContext().getOpPackageName(),
8613 phone.getContext().getAttributionTag());
8614 if (info == null) {
8615 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8616 return null;
chen xu6291c472019-02-04 12:55:53 -08008617 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008618 // Try and fetch the locale from the carrier properties or from the SIM language
8619 // preferences (EF-PL and EF-LI)...
8620 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008621 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008622 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8623 if (localeFromDefaultSim != null) {
8624 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8625 if (DBG) log("Using locale from subId: " + subId + " locale: "
8626 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008627 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008628 } else {
8629 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008630 }
8631 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008633 // The SIM language preferences only store a language (e.g. fr = French), not an
8634 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8635 // the SIM and carrier preferences does not include a country we add the country
8636 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008637 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008638 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008639 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008640 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008641 }
8642
8643 if (DBG) log("No locale found - returning null");
8644 return null;
8645 } finally {
8646 Binder.restoreCallingIdentity(identity);
8647 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008648 }
8649
tom hsu0b59d292022-09-29 23:49:21 +08008650 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008651 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008652 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008653 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008654 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008655 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8656 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008657 Locale.forLanguageTag(localeTag).getCountry())) {
8658 return localeTag;
8659 }
8660 }
8661 return inputLocale.toLanguageTag();
8662 }
8663
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008664 /**
8665 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8666 */
8667 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008668 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008669 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008670 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008671
Gary Jian3aa9a762022-01-24 16:41:19 +08008672 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8673 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008674
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008675 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008676 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8677 * representing the state of the modem.
8678 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008679 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8680 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008681 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008682 */
8683 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008684 public void requestModemActivityInfo(ResultReceiver result) {
8685 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008686
8687 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8688 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8689
vagdeviaf9a5b92018-08-15 16:01:53 -07008690 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008691
8692 final long identity = Binder.clearCallingIdentity();
8693 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008694 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008695 } finally {
8696 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008697 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008698 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008699
Gary Jian76280a42022-12-07 16:18:33 +08008700 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008701 // less than total activity duration.
8702 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8703 if (info == null) {
8704 return false;
8705 }
8706 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008707 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008708 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8709
Hall Liu49656c02020-10-09 19:00:11 -07008710 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8711
Siddharth Rayb8114062018-06-17 15:02:38 -07008712 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008713 && (info.getSleepTimeMillis() <= activityDurationMs)
8714 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008715 }
8716
Gary Jian3aa9a762022-01-24 16:41:19 +08008717 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8718 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8719 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8720 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8721
8722 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8723 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8724 }
8725
8726 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8727 mLastModemActivityInfo.setReceiveTimeMillis(
8728 rat,
8729 freq,
8730 info.getReceiveTimeMillis(rat, freq)
8731 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8732 }
8733
8734 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8735 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8736 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8737 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8738
8739 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8740 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8741 }
8742 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8743 mLastModemActivityInfo.setReceiveTimeMillis(
8744 rat,
8745 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8746 }
8747
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008748 /**
8749 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8750 * @param info recent ModemActivityInfo
8751 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008752 private void mergeModemActivityInfo(ModemActivityInfo info) {
8753 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008754 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008755 boolean matched;
8756 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8757 matched = false;
8758 int rat = info.getSpecificInfoRat(i);
8759 int freq = info.getSpecificInfoFrequencyRange(i);
8760 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8761 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8762 //if it already exists
8763 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8764 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8765 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8766 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8767 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8768 updateLastModemActivityInfo(info, rat, freq);
8769 matched = true;
8770 }
8771 } else {
8772 updateLastModemActivityInfo(info, rat);
8773 matched = true;
8774 }
8775 }
8776 }
8777
8778 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008779 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008780 new ActivityStatsTechSpecificInfo(
8781 rat,
8782 freq,
8783 info.getTransmitTimeMillis(rat, freq),
8784 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008785 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008786 }
8787 }
8788 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8789 mLastModemActivitySpecificInfo =
8790 new ActivityStatsTechSpecificInfo[merged.size()];
8791 merged.toArray(mLastModemActivitySpecificInfo);
8792
8793 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8794 mLastModemActivityInfo.setSleepTimeMillis(
8795 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008796 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008797 mLastModemActivityInfo.setIdleTimeMillis(
8798 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008799 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008800
8801 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008802 new ModemActivityInfo(
8803 mLastModemActivityInfo.getTimestampMillis(),
8804 mLastModemActivityInfo.getSleepTimeMillis(),
8805 mLastModemActivityInfo.getIdleTimeMillis(),
8806 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008807 }
8808
8809 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8810 ActivityStatsTechSpecificInfo[] info) {
8811 int infoSize = info.length;
8812 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8813 for (int i = 0; i < infoSize; i++) {
8814 ret[i] = new ActivityStatsTechSpecificInfo(
8815 info[i].getRat(), info[i].getFrequencyRange(),
8816 info[i].getTransmitTimeMillis(),
8817 (int) info[i].getReceiveTimeMillis());
8818 }
8819 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008820 }
8821
Jack Yu85bd38a2015-11-09 11:34:32 -08008822 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008823 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008824 */
8825 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008826 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8827 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8828 Phone phone = PhoneFactory.getPhone(slotIndex);
8829 if (phone == null) {
8830 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8831 return null;
8832 }
8833
8834 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008835 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008836 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008837 return null;
8838 }
8839
joonhunshin4ac60942023-11-15 15:23:39 +00008840 enforceTelephonyFeatureWithException(callingPackage,
8841 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8842
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008843 boolean hasFinePermission = false;
8844 boolean hasCoarsePermission = false;
8845 if (!renounceFineLocationAccess) {
8846 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8847 LocationAccessPolicy.checkLocationPermission(mApp,
8848 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8849 .setCallingPackage(callingPackage)
8850 .setCallingFeatureId(callingFeatureId)
8851 .setCallingPid(Binder.getCallingPid())
8852 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008853 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008854 .setLogAsInfo(true)
8855 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8856 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8857 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8858 .build());
8859 hasFinePermission =
8860 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8861 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008862
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008863 if (!renounceCoarseLocationAccess) {
8864 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8865 LocationAccessPolicy.checkLocationPermission(mApp,
8866 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8867 .setCallingPackage(callingPackage)
8868 .setCallingFeatureId(callingFeatureId)
8869 .setCallingPid(Binder.getCallingPid())
8870 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008871 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008872 .setLogAsInfo(true)
8873 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8874 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8875 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8876 .build());
8877 hasCoarsePermission =
8878 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8879 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008880
Jordan Liu0f2bc442020-11-18 16:47:37 -08008881 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008882 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008883 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8884 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008885 if (subInfo != null && !subInfo.isActive()) {
8886 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008887 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008888 }
8889
Hall Liuf19c44f2018-11-27 14:38:17 -08008890 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008891 boolean isCallingPackageDataService = phone.getDataServicePackages()
8892 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008893
8894 // Scrub out the location info in ServiceState depending on what level of access
8895 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008896 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008897 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8898 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008899 } finally {
8900 Binder.restoreCallingIdentity(identity);
8901 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008902 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008903
8904 /**
8905 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8906 *
8907 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8908 * voicemail ringtone.
8909 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8910 * PhoneAccount.
8911 */
8912 @Override
8913 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008914 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8915 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008917 final long identity = Binder.clearCallingIdentity();
8918 try {
8919 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8920 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008921 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008922 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008924 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8925 } finally {
8926 Binder.restoreCallingIdentity(identity);
8927 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008928 }
8929
8930 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008931 * Sets the per-account voicemail ringtone.
8932 *
8933 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8934 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8935 *
8936 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8937 * voicemail ringtone.
8938 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8939 * PhoneAccount.
8940 */
8941 @Override
8942 public void setVoicemailRingtoneUri(String callingPackage,
8943 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008944 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008945 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008946 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8947 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8949 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8950 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008952
joonhunshin4ac60942023-11-15 15:23:39 +00008953 enforceTelephonyFeatureWithException(callingPackage,
8954 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8955
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008956 final long identity = Binder.clearCallingIdentity();
8957 try {
8958 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8959 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008960 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008961 }
8962 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8963 } finally {
8964 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008965 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008966 }
8967
8968 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008969 * Returns whether vibration is set for voicemail notification in Phone settings.
8970 *
8971 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8972 * voicemail vibration setting.
8973 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8974 */
8975 @Override
8976 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008977 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8978 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008980 final long identity = Binder.clearCallingIdentity();
8981 try {
8982 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8983 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008984 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008985 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008987 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8988 } finally {
8989 Binder.restoreCallingIdentity(identity);
8990 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008991 }
8992
Youhan Wange64578a2016-05-02 15:32:42 -07008993 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008994 * Sets the per-account voicemail vibration.
8995 *
8996 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8997 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8998 *
8999 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9000 * voicemail vibration setting.
9001 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9002 * specific PhoneAccount.
9003 */
9004 @Override
9005 public void setVoicemailVibrationEnabled(String callingPackage,
9006 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009007 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009008 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009009 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9010 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9012 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9013 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009014 }
9015
joonhunshin4ac60942023-11-15 15:23:39 +00009016 enforceTelephonyFeatureWithException(callingPackage,
9017 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009019 final long identity = Binder.clearCallingIdentity();
9020 try {
9021 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9022 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009023 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009024 }
9025 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9026 } finally {
9027 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009028 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009029 }
9030
9031 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009032 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9033 *
9034 * @throws SecurityException if the caller does not have the required permission
9035 */
arunvoddud7401012022-12-15 16:08:12 +00009036 @VisibleForTesting
9037 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009038 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009039 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009040 }
9041
9042 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009043 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9044 * permission.
9045 *
9046 * @throws SecurityException if the caller does not have the required permission
9047 */
9048 private void enforceSendSmsPermission() {
9049 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9050 }
9051
9052 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009053 * Make sure either called from same process as self (phone) or IPC caller has interact across
9054 * users permission.
9055 *
9056 * @throws SecurityException if the caller does not have the required permission
9057 */
9058 private void enforceInteractAcrossUsersPermission(String message) {
9059 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9060 }
9061
9062 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009063 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009064 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009065 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009066 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009067 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009068 final long identity = Binder.clearCallingIdentity();
9069 try {
9070 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009071 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009072 if (componentName == null) {
9073 throw new SecurityException(
9074 "Caller not current active visual voicemail package[null]");
9075 }
9076 String vvmPackage = componentName.getPackageName();
9077 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009078 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009079 }
9080 } finally {
9081 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009082 }
9083 }
9084
9085 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009086 * Return the application ID for the app type.
9087 *
9088 * @param subId the subscription ID that this request applies to.
9089 * @param appType the uicc app type.
9090 * @return Application ID for specificied app type, or null if no uicc.
9091 */
9092 @Override
9093 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009094 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009095
9096 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9097 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9098
Youhan Wange64578a2016-05-02 15:32:42 -07009099 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009100
9101 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009102 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009103 if (phone == null) {
9104 return null;
9105 }
9106 String aid = null;
9107 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009108 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009109 .getApplicationByType(appType).getAid();
9110 } catch (Exception e) {
9111 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9112 }
9113 return aid;
9114 } finally {
9115 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009116 }
Youhan Wange64578a2016-05-02 15:32:42 -07009117 }
9118
Youhan Wang4001d252016-05-11 10:29:41 -07009119 /**
9120 * Return the Electronic Serial Number.
9121 *
9122 * @param subId the subscription ID that this request applies to.
9123 * @return ESN or null if error.
9124 */
9125 @Override
9126 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009127 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009128 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009129
9130 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009131 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009132 if (phone == null) {
9133 return null;
9134 }
9135 String esn = null;
9136 try {
9137 esn = phone.getEsn();
9138 } catch (Exception e) {
9139 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9140 }
9141 return esn;
9142 } finally {
9143 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009144 }
Youhan Wang4001d252016-05-11 10:29:41 -07009145 }
9146
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009147 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009148 * Return the Preferred Roaming List Version.
9149 *
9150 * @param subId the subscription ID that this request applies to.
9151 * @return PRLVersion or null if error.
9152 */
9153 @Override
9154 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009155 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009156
9157 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9158 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9159
Youhan Wang66ad5d72016-07-18 17:56:58 -07009160 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009161
9162 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009163 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009164 if (phone == null) {
9165 return null;
9166 }
9167 String cdmaPrlVersion = null;
9168 try {
9169 cdmaPrlVersion = phone.getCdmaPrlVersion();
9170 } catch (Exception e) {
9171 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9172 }
9173 return cdmaPrlVersion;
9174 } finally {
9175 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009176 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009177 }
9178
9179 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009180 * Get snapshot of Telephony histograms
9181 * @return List of Telephony histograms
9182 * @hide
9183 */
9184 @Override
9185 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9187 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009188
9189 final long identity = Binder.clearCallingIdentity();
9190 try {
9191 return RIL.getTelephonyRILTimingHistograms();
9192 } finally {
9193 Binder.restoreCallingIdentity(identity);
9194 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009195 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009196
9197 /**
9198 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009199 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9200 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009201 * Require system privileges. In the future we may add this to carrier APIs.
9202 *
Michele Berionne482f8202018-11-27 18:57:59 -08009203 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009204 */
9205 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009206 @TelephonyManager.SetCarrierRestrictionResult
9207 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009208 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009209
9210 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9211 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9212
vagdeviaf9a5b92018-08-15 16:01:53 -07009213 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009214
Michele Berionne482f8202018-11-27 18:57:59 -08009215 if (carrierRestrictionRules == null) {
9216 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009217 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009219 final long identity = Binder.clearCallingIdentity();
9220 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009221 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009222 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009223 } finally {
9224 Binder.restoreCallingIdentity(identity);
9225 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009226 }
9227
9228 /**
9229 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009230 * Get the allowed carrier list and the excluded carrier list, including the priority between
9231 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009232 * Require system privileges. In the future we may add this to carrier APIs.
9233 *
Michele Berionne482f8202018-11-27 18:57:59 -08009234 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009235 */
9236 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009237 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009238 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009239
9240 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9241 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9242
vagdeviaf9a5b92018-08-15 16:01:53 -07009243 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009244
9245 final long identity = Binder.clearCallingIdentity();
9246 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009247 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9248 if (response instanceof CarrierRestrictionRules) {
9249 return (CarrierRestrictionRules) response;
9250 }
9251 // Response is an Exception of some kind,
9252 // which is signalled to the user as a NULL retval
9253 return null;
9254 } catch (Exception e) {
9255 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9256 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009257 } finally {
9258 Binder.restoreCallingIdentity(identity);
9259 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009260 }
9261
fionaxu59545b42016-05-25 15:53:37 -07009262 /**
arunvoddud7401012022-12-15 16:08:12 +00009263 * Fetches the carrier restriction status of the device and sends the status to the caller
9264 * through the callback.
9265 *
9266 * @param callback The callback that will be used to send the result.
9267 * @throws SecurityException if the caller does not have the required permission/privileges or
9268 * the caller is not allowlisted.
9269 */
9270 @Override
9271 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9272 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009273
9274 enforceTelephonyFeatureWithException(packageName,
9275 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9276
Steve Statia28b7cb32024-03-11 23:58:50 +00009277 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9278 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009279 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9280 throw new SecurityException("Not an authorized caller");
9281 }
9282 final long identity = Binder.clearCallingIdentity();
9283 try {
9284 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009285 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009286 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9287 } finally {
9288 Binder.restoreCallingIdentity(identity);
9289 }
9290 }
9291
arunvoddu567f2b42023-04-25 17:22:00 +00009292 @Override
9293 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9294 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9295 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9296 return allowListInfo.getShaIdList(pkgName, carrierId);
9297 }
9298
arunvoddud7401012022-12-15 16:08:12 +00009299 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009300 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009301 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009302 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009303 }
9304
9305 /**
fionaxu59545b42016-05-25 15:53:37 -07009306 * Action set from carrier signalling broadcast receivers to enable/disable radio
9307 * @param subId the subscription ID that this action applies to.
9308 * @param enabled control enable or disable radio.
9309 * {@hide}
9310 */
9311 @Override
9312 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9313 enforceModifyPermission();
9314 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009315
9316 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009317 if (phone == null) {
9318 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9319 return;
9320 }
9321 try {
9322 phone.carrierActionSetRadioEnabled(enabled);
9323 } catch (Exception e) {
9324 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009325 } finally {
9326 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009327 }
9328 }
9329
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009330 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009331 * Enable or disable Voice over NR (VoNR)
9332 * @param subId the subscription ID that this action applies to.
9333 * @param enabled enable or disable VoNR.
9334 * @return operation result.
9335 */
9336 @Override
9337 public int setVoNrEnabled(int subId, boolean enabled) {
9338 enforceModifyPermission();
9339 final Phone phone = getPhone(subId);
9340
9341 final long identity = Binder.clearCallingIdentity();
9342 if (phone == null) {
9343 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9344 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9345 }
9346
9347 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9348 try {
9349 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9350 workSource);
9351 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009352
9353 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9354 if (DBG) {
9355 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9356 }
9357 SubscriptionManager.setSubscriptionProperty(
9358 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9359 (enabled ? "1" : "0"));
9360 }
9361
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009362 return result;
9363 } finally {
9364 Binder.restoreCallingIdentity(identity);
9365 }
9366 }
9367
9368 /**
9369 * Is voice over NR enabled
9370 * @return true if VoNR is enabled else false
9371 */
9372 @Override
9373 public boolean isVoNrEnabled(int subId) {
9374 enforceReadPrivilegedPermission("isVoNrEnabled");
9375 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9376 final long identity = Binder.clearCallingIdentity();
9377 try {
9378 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9379 null, subId, workSource);
9380 if (DBG) log("isVoNrEnabled: " + isEnabled);
9381 return isEnabled;
9382 } finally {
9383 Binder.restoreCallingIdentity(identity);
9384 }
9385 }
9386
9387 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009388 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9389 * network status based on which carrier apps could apply actions accordingly,
9390 * enable/disable default url handler for example.
9391 *
9392 * @param subId the subscription ID that this action applies to.
9393 * @param report control start/stop reporting the default network status.
9394 * {@hide}
9395 */
9396 @Override
9397 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9398 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009399
9400 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9401 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9402 "carrierActionReportDefaultNetworkStatus");
9403
fionaxu8da9cb12017-05-23 15:02:46 -07009404 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009405
9406 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009407 if (phone == null) {
9408 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9409 return;
9410 }
9411 try {
9412 phone.carrierActionReportDefaultNetworkStatus(report);
9413 } catch (Exception e) {
9414 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009415 } finally {
9416 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009417 }
9418 }
9419
9420 /**
fionaxud9622282017-07-17 17:51:30 -07009421 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9422 * @param subId the subscription ID that this action applies to.
9423 * {@hide}
9424 */
9425 @Override
9426 public void carrierActionResetAll(int subId) {
9427 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009428
9429 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9430 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9431
fionaxud9622282017-07-17 17:51:30 -07009432 final Phone phone = getPhone(subId);
9433 if (phone == null) {
9434 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9435 return;
9436 }
9437 try {
9438 phone.carrierActionResetAll();
9439 } catch (Exception e) {
9440 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9441 }
9442 }
9443
9444 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009445 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9446 * bug report is being generated.
9447 */
9448 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009449 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009450 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9451 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009452 writer.println("Permission Denial: can't dump Phone from pid="
9453 + Binder.getCallingPid()
9454 + ", uid=" + Binder.getCallingUid()
9455 + "without permission "
9456 + android.Manifest.permission.DUMP);
9457 return;
9458 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009459 try {
9460 DumpsysHandler.dump(mApp, fd, writer, args);
9461 } catch (Exception e) {
9462 writer.println("Failed to dump phone information: " + e);
9463 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009464 }
Jack Yueb89b242016-06-22 13:27:47 -07009465
Brad Ebingerdac2f002018-04-03 15:17:52 -07009466 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009467 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9468 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9469 @NonNull String[] args) {
9470 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9471 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009472 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009473 }
9474
Jack Yueb89b242016-06-22 13:27:47 -07009475 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009476 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009477 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009478 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009479 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009480 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009481 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009482 */
9483 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009484 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009485 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009486 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9487 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9488 try {
9489 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009490 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009491 } catch (SecurityException se) {
9492 enforceModifyPermission();
9493 }
9494 } else {
9495 enforceModifyPermission();
9496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009497
joonhunshin4ac60942023-11-15 15:23:39 +00009498 enforceTelephonyFeatureWithException(callingPackage,
9499 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9500
Nate Myren116695d2024-02-09 09:36:01 -08009501 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009502 final long identity = Binder.clearCallingIdentity();
9503 try {
Nate Myren116695d2024-02-09 09:36:01 -08009504 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9505 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009506 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009507 callingUid, callingPackage, null, null);
9508 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009509 Phone phone = getPhone(subId);
9510 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009511 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9512 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009513 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009514 phone.getDataSettingsManager().setDataEnabled(
9515 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009516 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009517 }
9518 } finally {
9519 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009520 }
9521 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009522
9523 /**
9524 * Get Client request stats
9525 * @return List of Client Request Stats
9526 * @hide
9527 */
9528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009529 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9530 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009532 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009533 return null;
9534 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009535 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009537 final long identity = Binder.clearCallingIdentity();
9538 try {
9539 if (phone != null) {
9540 return phone.getClientRequestStats();
9541 }
9542
9543 return null;
9544 } finally {
9545 Binder.restoreCallingIdentity(identity);
9546 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009547 }
9548
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009549 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009550 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009551 if (uid == Process.ROOT_UID && packageName == null) {
9552 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9553 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9554 // exception. ROOT_UID seems not to have a valid package name returned by
9555 // PackageManager, so just fake it here to avoid issues when running telephony shell
9556 // commands that plumb through the RIL as root, like so:
9557 // $ adb root
9558 // $ adb shell cmd phone ...
9559 packageName = "root";
9560 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009561 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009562 }
Jack Yueb4124c2017-02-16 15:32:43 -08009563
9564 /**
Grace Chen70990072017-03-24 17:21:30 -07009565 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009566 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009567 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009568 * @param state State of SIM (power down, power up, pass through)
9569 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9570 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9571 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009572 *
9573 **/
9574 @Override
Grace Chen70990072017-03-24 17:21:30 -07009575 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009576 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009577
9578 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9579 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9580
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009581 Phone phone = PhoneFactory.getPhone(slotIndex);
9582
vagdeviaf9a5b92018-08-15 16:01:53 -07009583 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9584
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009585 final long identity = Binder.clearCallingIdentity();
9586 try {
9587 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009588 phone.setSimPowerState(state, null, workSource);
9589 }
9590 } finally {
9591 Binder.restoreCallingIdentity(identity);
9592 }
9593 }
9594
9595 /**
9596 * Set SIM card power state.
9597 *
9598 * @param slotIndex SIM slot id.
9599 * @param state State of SIM (power down, power up, pass through)
9600 * @param callback callback to trigger after success or failure
9601 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9602 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9603 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9604 *
9605 **/
9606 @Override
9607 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9608 IIntegerConsumer callback) {
9609 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009610
9611 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9612 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9613 "setSimPowerStateForSlotWithCallback");
9614
Jordan Liu109698e2020-11-24 14:50:34 -08009615 Phone phone = PhoneFactory.getPhone(slotIndex);
9616
9617 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9618
9619 final long identity = Binder.clearCallingIdentity();
9620 try {
9621 if (phone != null) {
9622 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9623 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009624 }
9625 } finally {
9626 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009627 }
9628 }
Shuo Qiandd210312017-04-12 22:11:33 +00009629
Tyler Gunn65d45c22017-06-05 11:22:26 -07009630 private boolean isUssdApiAllowed(int subId) {
9631 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009632 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009633 if (configManager == null) {
9634 return false;
9635 }
9636 PersistableBundle pb = configManager.getConfigForSubId(subId);
9637 if (pb == null) {
9638 return false;
9639 }
9640 return pb.getBoolean(
9641 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9642 }
9643
Shuo Qiandd210312017-04-12 22:11:33 +00009644 /**
Ling Mac28f0212023-03-24 16:07:15 -07009645 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009646 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009647 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009648 */
goneil9c5f4872017-12-05 14:07:56 -08009649 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009650 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009651 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009652
9653 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9654 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009656 final long identity = Binder.clearCallingIdentity();
9657 try {
Ling Mac28f0212023-03-24 16:07:15 -07009658 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009659 } finally {
9660 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009661 }
9662 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009663
9664 /**
9665 * Get the current signal strength information for the given subscription.
9666 * Because this information is not updated when the device is in a low power state
9667 * it should not be relied-upon to be current.
9668 * @param subId Subscription index
9669 * @return the most recent cached signal strength info from the modem
9670 */
9671 @Override
9672 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009673 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9674 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009676 final long identity = Binder.clearCallingIdentity();
9677 try {
9678 Phone p = getPhone(subId);
9679 if (p == null) {
9680 return null;
9681 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009683 return p.getSignalStrength();
9684 } finally {
9685 Binder.restoreCallingIdentity(identity);
9686 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009687 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009688
Pengquan Meng77b7f132018-08-22 14:49:57 -07009689 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009690 * Get the current modem radio state for the given slot.
9691 * @param slotIndex slot index.
9692 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009693 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009694 * @return the current radio power state from the modem
9695 */
9696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009697 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009698 Phone phone = PhoneFactory.getPhone(slotIndex);
9699 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9701 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009702 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9703 }
9704
joonhunshin4ac60942023-11-15 15:23:39 +00009705 enforceTelephonyFeatureWithException(callingPackage,
9706 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9707
Chen Xuf792fd62018-10-17 17:54:36 +00009708 final long identity = Binder.clearCallingIdentity();
9709 try {
9710 return phone.getRadioPowerState();
9711 } finally {
9712 Binder.restoreCallingIdentity(identity);
9713 }
9714 }
9715 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9716 }
9717
9718 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009719 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9720 *
9721 * <p>Requires one of the following permissions:
9722 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009723 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009724 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9725 * privileges.
9726 *
9727 * @param subId subscription id
9728 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9729 * {@code false}.
9730 */
9731 @Override
9732 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009733 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009734 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009735 try {
9736 mApp.enforceCallingOrSelfPermission(
9737 android.Manifest.permission.ACCESS_NETWORK_STATE,
9738 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009739 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009740 mApp.enforceCallingOrSelfPermission(
9741 permission.READ_BASIC_PHONE_STATE, functionName);
9742 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009743 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009744 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009745 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009746 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009747
joonhunshin4ac60942023-11-15 15:23:39 +00009748 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9749 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9750
Pengquan Menga1bb6272018-09-06 09:59:22 -07009751 boolean isEnabled = false;
9752 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009753 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009754 Phone phone = getPhone(subId);
9755 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009756 } finally {
9757 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009758 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009759 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009760 }
9761
9762
9763 /**
9764 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9765 *
9766 * <p> Requires permission:
9767 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9768 * privileges.
9769 *
9770 * @param subId subscription id
9771 * @param isEnabled {@code true} means enable, {@code false} means disable.
9772 */
9773 @Override
9774 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9776 mApp, subId, "setDataRoamingEnabled");
9777
joonhunshin4ac60942023-11-15 15:23:39 +00009778 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9779 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9780
Pengquan Menga1bb6272018-09-06 09:59:22 -07009781 final long identity = Binder.clearCallingIdentity();
9782 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009783 Phone phone = getPhone(subId);
9784 if (phone != null) {
9785 phone.setDataRoamingEnabled(isEnabled);
9786 }
9787 } finally {
9788 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009789 }
9790 }
9791
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009792 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009793 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009794 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009795 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009796 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009797
joonhunshin4ac60942023-11-15 15:23:39 +00009798 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9799 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9800
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009801 boolean isAllowed = true;
9802 final long identity = Binder.clearCallingIdentity();
9803 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009804 Phone phone = getPhone(subId);
9805 if (phone != null) {
9806 isAllowed = phone.isCspPlmnEnabled();
9807 }
9808 } finally {
9809 Binder.restoreCallingIdentity(identity);
9810 }
9811 return isAllowed;
9812 }
9813
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009814 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9815 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009816 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009817 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009818 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009819 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9820 if (phone == null) {
9821 return false;
9822 }
9823 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9824 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9825 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009826 }
9827
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009828 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009829 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009830 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009831 mApp.getSystemService(AppOpsManager.class)
9832 .checkPackage(Binder.getCallingUid(), callingPackage);
9833
Jordan Liu1e142fc2019-04-22 15:10:43 -07009834 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009835 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009836 try {
9837 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009838 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009839 } catch (SecurityException e) {
9840 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9841 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009842 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009843 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009844 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009845 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009846 }
joonhunshin4ac60942023-11-15 15:23:39 +00009847
9848 enforceTelephonyFeatureWithException(callingPackage,
9849 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9850
sandeepjsb6c87872021-09-27 15:34:44 +00009851 // checking compatibility, if calling app's target SDK is T and beyond.
9852 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9853 Binder.getCallingUid())) {
9854 isIccIdAccessRestricted = true;
9855 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009856 final long identity = Binder.clearCallingIdentity();
9857 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009858 UiccController uiccController = UiccController.getInstance();
9859 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009860 if (hasReadPermission) {
9861 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009862 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009863
9864 // Remove private info if the caller doesn't have access
9865 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9866 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009867 //setting the value after compatibility check
9868 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009869 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9870 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009871 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009872 if (card == null) {
9873 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009874 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009875 continue;
9876 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009877 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9878 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009879 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009880 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009881 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009882 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9883 for (UiccPortInfo portInfo : portInfos) {
9884 UiccPort port = uiccController.getUiccPortForSlot(
9885 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9886 if (port == null) {
9887 // assume no access if port is null
9888 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9889 continue;
9890 }
9891 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9892 uiccPortInfos.add(portInfo);
9893 } else {
9894 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9895 }
9896 }
9897 filteredInfos.add(new UiccCardInfo(
9898 cardInfo.isEuicc(),
9899 cardInfo.getCardId(),
9900 null,
9901 cardInfo.getPhysicalSlotIndex(),
9902 cardInfo.isRemovable(),
9903 cardInfo.isMultipleEnabledProfilesSupported(),
9904 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009905 }
9906 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009907 } finally {
9908 Binder.restoreCallingIdentity(identity);
9909 }
9910 }
9911
sandeepjsb6c87872021-09-27 15:34:44 +00009912 /**
9913 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9914 * generally private and require carrier privileges to view.
9915 *
9916 * @hide
9917 */
9918 @NonNull
9919 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9920 List<UiccPortInfo> portinfo = new ArrayList<>();
9921 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9922 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9923 }
9924 return new UiccCardInfo(
9925 cardInfo.isEuicc(),
9926 cardInfo.getCardId(),
9927 null,
9928 cardInfo.getPhysicalSlotIndex(),
9929 cardInfo.isRemovable(),
9930 cardInfo.isMultipleEnabledProfilesSupported(),
9931 portinfo
9932 );
9933 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009934
sandeepjsb6c87872021-09-27 15:34:44 +00009935 /**
9936 * @hide
9937 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9938 * These values are generally private and require carrier privileges to view.
9939 */
9940 @NonNull
9941 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9942 return new UiccPortInfo(
9943 UiccPortInfo.ICCID_REDACTED,
9944 portInfo.getPortIndex(),
9945 portInfo.getLogicalSlotIndex(),
9946 portInfo.isActive()
9947 );
9948 }
9949 @Override
9950 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009951 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009952 mApp.getSystemService(AppOpsManager.class)
9953 .checkPackage(Binder.getCallingUid(), callingPackage);
9954
sandeepjsb6c87872021-09-27 15:34:44 +00009955 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009956
Aman Guptaf3c90b32022-03-17 04:54:16 +00009957 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9958 // we are reading iccId which is PII data.
9959 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009960
joonhunshin4ac60942023-11-15 15:23:39 +00009961 enforceTelephonyFeatureWithException(callingPackage,
9962 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9963
sandeepjsb6c87872021-09-27 15:34:44 +00009964 // checking compatibility, if calling app's target SDK is T and beyond.
9965 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9966 Binder.getCallingUid())) {
9967 isLogicalSlotAccessRestricted = true;
9968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009969 final long identity = Binder.clearCallingIdentity();
9970 try {
9971 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009972 if (slots == null || slots.length == 0) {
9973 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009974 return null;
9975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009976 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9977 for (int i = 0; i < slots.length; i++) {
9978 UiccSlot slot = slots[i];
9979 if (slot == null) {
9980 continue;
9981 }
9982
Jordan Liu7be7e652019-05-06 18:55:02 +00009983 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009984 UiccCard card = slot.getUiccCard();
9985 if (card != null) {
9986 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009987 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009988 cardId = slot.getEid();
9989 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009990 // If cardId is null, use iccId of default port as cardId.
9991 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009993 }
9994
Jordan Liu857451f2019-05-09 16:35:35 -07009995 if (cardId != null) {
9996 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9997 // if cardId is an EID, it's all digits so this is fine
9998 cardId = IccUtils.stripTrailingFs(cardId);
9999 }
10000
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010001 int cardState = 0;
10002 switch (slot.getCardState()) {
10003 case CARDSTATE_ABSENT:
10004 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10005 break;
10006 case CARDSTATE_PRESENT:
10007 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10008 break;
10009 case CARDSTATE_ERROR:
10010 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10011 break;
10012 case CARDSTATE_RESTRICTED:
10013 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10014 break;
10015 default:
10016 break;
10017
10018 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010019 List<UiccPortInfo> portInfos = new ArrayList<>();
10020 int[] portIndexes = slot.getPortList();
10021 for (int portIdx : portIndexes) {
10022 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010023 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010024 portInfos.add(new UiccPortInfo(iccId, portIdx,
10025 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010027 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010028 slot.isEuicc(),
10029 cardId,
10030 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010031 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010032 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010033 //setting the value after compatibility check
10034 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010035 }
10036 return infos;
10037 } finally {
10038 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010039 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010040 }
10041
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010042 /* Returns null if doesn't have read permission or carrier privilege access. */
10043 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10044 boolean hasReadPermission) {
10045 String iccId = slot.getIccId(portIndex);
10046 if (hasReadPermission) { // if has read permission
10047 return iccId;
10048 } else {
10049 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10050 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10051 // if no read permission, checking carrier privilege access
10052 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10053 return iccId;
10054 }
10055 }
10056 }
10057 // No read permission or carrier privilege access.
10058 return UiccPortInfo.ICCID_REDACTED;
10059 }
10060
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010061 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010062 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010063 public boolean switchSlots(int[] physicalSlots) {
10064 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010065
joonhunshin4ac60942023-11-15 15:23:39 +000010066 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10067 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10068
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010069 final long identity = Binder.clearCallingIdentity();
10070 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010071 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10072 for (int i = 0; i < physicalSlots.length; i++) {
10073 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10074 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10075 physicalSlots[i], i));
10076 }
10077 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010078 } finally {
10079 Binder.restoreCallingIdentity(identity);
10080 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010081 }
Jack Yu4c988042018-02-27 15:30:01 -080010082
10083 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010084 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10085 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10086 enforceModifyPermission();
10087
joonhunshin4ac60942023-11-15 15:23:39 +000010088 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10089 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10090
sandeepjsb6c87872021-09-27 15:34:44 +000010091 final long identity = Binder.clearCallingIdentity();
10092 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010093 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010094 } finally {
10095 Binder.restoreCallingIdentity(identity);
10096 }
10097 }
10098
10099 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010100 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010101 enforceTelephonyFeatureWithException(callingPackage,
10102 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10103
Jordan Liu7de49fa2018-12-06 14:48:49 -080010104 final long identity = Binder.clearCallingIdentity();
10105 try {
10106 return UiccController.getInstance().getCardIdForDefaultEuicc();
10107 } finally {
10108 Binder.restoreCallingIdentity(identity);
10109 }
10110 }
10111
Pengquan Meng85728fb2018-03-12 16:31:21 -070010112 /**
goneil47ffb6e2018-04-06 15:40:58 -070010113 * A test API to reload the UICC profile.
10114 *
10115 * <p>Requires that the calling app has permission
10116 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10117 * @hide
10118 */
10119 @Override
10120 public void refreshUiccProfile(int subId) {
10121 enforceModifyPermission();
10122
10123 final long identity = Binder.clearCallingIdentity();
10124 try {
10125 Phone phone = getPhone(subId);
10126 if (phone == null) {
10127 return;
10128 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010129 UiccPort uiccPort = phone.getUiccPort();
10130 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010131 return;
10132 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010133 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010134 if (uiccProfile == null) {
10135 return;
10136 }
10137 uiccProfile.refresh();
10138 } finally {
10139 Binder.restoreCallingIdentity(identity);
10140 }
10141 }
10142
10143 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010144 * Returns false if the mobile data is disabled by default, otherwise return true.
10145 */
10146 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010147 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010148 }
10149
10150 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010151 * Returns the default network type for the given {@code subId}, if the default network type is
10152 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10153 */
10154 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010155 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010156 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010157 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10158 return list.get(phoneId);
10159 }
10160 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010161 }
fionaxua13278b2018-03-21 00:08:13 -070010162
10163 @Override
10164 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010165 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010166 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010167
10168 final long identity = Binder.clearCallingIdentity();
10169 try {
10170 final Phone phone = getPhone(subId);
10171 if (phone == null) {
10172 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10173 return;
10174 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010175 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10176 if (cpt != null) {
10177 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10178 }
10179 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010180 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10181 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010182 if (carrierPrivilegeRules == null) {
10183 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10184 } else {
10185 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10186 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010187 } finally {
10188 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010189 }
fionaxua13278b2018-03-21 00:08:13 -070010190 }
10191
10192 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010193 public void setCarrierServicePackageOverride(
10194 int subId, String carrierServicePackage, String callingPackage) {
10195 TelephonyPermissions.enforceShellOnly(
10196 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10197
Benedict Wong66477622023-02-03 23:30:57 +000010198 final long identity = Binder.clearCallingIdentity();
10199 try {
10200 final Phone phone = getPhone(subId);
10201 if (phone == null || phone.getSubId() != subId) {
10202 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10203 throw new IllegalArgumentException("No phone for subid");
10204 }
10205 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10206 if (cpt == null) {
10207 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10208 throw new IllegalStateException("No CPT for phone");
10209 }
10210 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10211 } finally {
10212 Binder.restoreCallingIdentity(identity);
10213 }
10214 }
10215
10216 @Override
fionaxua13278b2018-03-21 00:08:13 -070010217 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010218 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010219
10220 final long identity = Binder.clearCallingIdentity();
10221 try {
10222 final Phone phone = getPhone(subId);
10223 if (phone == null) {
10224 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10225 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10226 }
10227 return phone.getCarrierIdListVersion();
10228 } finally {
10229 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010230 }
fionaxua13278b2018-03-21 00:08:13 -070010231 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010232
10233 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010234 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10235 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010236 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010237 mApp, subId, callingPackage, callingFeatureId,
10238 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010239 return -1;
10240 }
10241
10242 final long identity = Binder.clearCallingIdentity();
10243 try {
10244 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10245 } finally {
10246 Binder.restoreCallingIdentity(identity);
10247 }
10248 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010249
10250 @Override
10251 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010252 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010253 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010254 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010255
joonhunshin4ac60942023-11-15 15:23:39 +000010256 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10257 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10258
Pengquan Menga1bb6272018-09-06 09:59:22 -070010259 final long identity = Binder.clearCallingIdentity();
10260 try {
10261 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10262 } finally {
10263 Binder.restoreCallingIdentity(identity);
10264 }
10265 }
10266
10267 @Override
10268 public boolean setCdmaRoamingMode(int subId, int mode) {
10269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10270 mApp, subId, "setCdmaRoamingMode");
10271
joonhunshin4ac60942023-11-15 15:23:39 +000010272 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10273 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10274
Pengquan Menga1bb6272018-09-06 09:59:22 -070010275 final long identity = Binder.clearCallingIdentity();
10276 try {
10277 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10278 } finally {
10279 Binder.restoreCallingIdentity(identity);
10280 }
10281 }
10282
10283 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010284 public int getCdmaSubscriptionMode(int subId) {
10285 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010286 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010287 mApp, subId, "getCdmaSubscriptionMode");
10288
joonhunshin4ac60942023-11-15 15:23:39 +000010289 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10290 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10291
Sarah Chinbaab1432020-10-28 13:46:24 -070010292 final long identity = Binder.clearCallingIdentity();
10293 try {
10294 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10295 } finally {
10296 Binder.restoreCallingIdentity(identity);
10297 }
10298 }
10299
10300 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010301 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10303 mApp, subId, "setCdmaSubscriptionMode");
10304
joonhunshin4ac60942023-11-15 15:23:39 +000010305 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10306 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10307
Pengquan Menga1bb6272018-09-06 09:59:22 -070010308 final long identity = Binder.clearCallingIdentity();
10309 try {
10310 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10311 } finally {
10312 Binder.restoreCallingIdentity(identity);
10313 }
10314 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010315
sqianc5eccab2018-10-19 18:46:41 -070010316 @Override
sqian8c685422019-02-22 15:55:18 -080010317 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010318 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010320 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10321 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010322 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10323 }
joonhunshin4ac60942023-11-15 15:23:39 +000010324
10325 enforceTelephonyFeatureWithException(callingPackage,
10326 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10327
sqian11b7a0e2018-12-05 18:48:28 -080010328 final long identity = Binder.clearCallingIdentity();
10329 try {
sqian854d44b2018-12-12 16:48:18 -080010330 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10331 for (Phone phone: PhoneFactory.getPhones()) {
10332 if (phone.getEmergencyNumberTracker() != null
10333 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10334 emergencyNumberListInternal.put(
10335 phone.getSubId(),
10336 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10337 }
sqian11b7a0e2018-12-05 18:48:28 -080010338 }
sqian854d44b2018-12-12 16:48:18 -080010339 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010340 } finally {
10341 Binder.restoreCallingIdentity(identity);
10342 }
sqianc5eccab2018-10-19 18:46:41 -070010343 }
10344
10345 @Override
sqian8c685422019-02-22 15:55:18 -080010346 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010347 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010348 if (!exactMatch) {
10349 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010350 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010351 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010352 }
joonhunshin4ac60942023-11-15 15:23:39 +000010353
10354 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10355 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10356
sqian11b7a0e2018-12-05 18:48:28 -080010357 final long identity = Binder.clearCallingIdentity();
10358 try {
sqian854d44b2018-12-12 16:48:18 -080010359 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010360 //Note: we ignore passed in param exactMatch. We can remove it once
10361 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010362 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010363 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010364 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010365 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010366 }
sqian11b7a0e2018-12-05 18:48:28 -080010367 }
10368 return false;
10369 } finally {
10370 Binder.restoreCallingIdentity(identity);
10371 }
10372 }
10373
sqianf4ca7ed2019-01-15 18:32:07 -080010374 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010375 * Start emergency callback mode for GsmCdmaPhone for testing.
10376 */
10377 @Override
10378 public void startEmergencyCallbackMode() {
10379 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10380 "startEmergencyCallbackMode");
10381 enforceModifyPermission();
10382 final long identity = Binder.clearCallingIdentity();
10383 try {
10384 for (Phone phone : PhoneFactory.getPhones()) {
10385 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10386 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10387 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10388 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10389 gsmCdmaPhone.obtainMessage(
10390 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10391 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10392 }
10393 }
10394 } finally {
10395 Binder.restoreCallingIdentity(identity);
10396 }
10397 }
10398
10399 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010400 * Update emergency number list for test mode.
10401 */
10402 @Override
10403 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10404 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10405 "updateEmergencyNumberListTestMode");
10406
10407 final long identity = Binder.clearCallingIdentity();
10408 try {
10409 for (Phone phone: PhoneFactory.getPhones()) {
10410 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10411 if (tracker != null) {
10412 tracker.executeEmergencyNumberTestModeCommand(action, num);
10413 }
10414 }
10415 } finally {
10416 Binder.restoreCallingIdentity(identity);
10417 }
10418 }
10419
10420 /**
10421 * Get the full emergency number list for test mode.
10422 */
10423 @Override
10424 public List<String> getEmergencyNumberListTestMode() {
10425 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10426 "getEmergencyNumberListTestMode");
10427
10428 final long identity = Binder.clearCallingIdentity();
10429 try {
10430 Set<String> emergencyNumbers = new HashSet<>();
10431 for (Phone phone: PhoneFactory.getPhones()) {
10432 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10433 if (tracker != null) {
10434 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10435 emergencyNumbers.add(num.getNumber());
10436 }
10437 }
10438 }
10439 return new ArrayList<>(emergencyNumbers);
10440 } finally {
10441 Binder.restoreCallingIdentity(identity);
10442 }
10443 }
10444
chen xud6b45bd2018-10-30 22:27:10 -070010445 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010446 public int getEmergencyNumberDbVersion(int subId) {
10447 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10448
joonhunshin4ac60942023-11-15 15:23:39 +000010449 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10450 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10451
Shuo Qian3b6ee772019-11-13 17:43:31 -080010452 final long identity = Binder.clearCallingIdentity();
10453 try {
10454 final Phone phone = getPhone(subId);
10455 if (phone == null) {
10456 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10457 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10458 }
10459 return phone.getEmergencyNumberDbVersion();
10460 } finally {
10461 Binder.restoreCallingIdentity(identity);
10462 }
10463 }
10464
10465 @Override
10466 public void notifyOtaEmergencyNumberDbInstalled() {
10467 enforceModifyPermission();
10468
joonhunshin4ac60942023-11-15 15:23:39 +000010469 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10470 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10471
Shuo Qian3b6ee772019-11-13 17:43:31 -080010472 final long identity = Binder.clearCallingIdentity();
10473 try {
10474 for (Phone phone: PhoneFactory.getPhones()) {
10475 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10476 if (tracker != null) {
10477 tracker.updateOtaEmergencyNumberDatabase();
10478 }
10479 }
10480 } finally {
10481 Binder.restoreCallingIdentity(identity);
10482 }
10483 }
10484
10485 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010486 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010487 enforceActiveEmergencySessionPermission();
10488
joonhunshin4ac60942023-11-15 15:23:39 +000010489 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10490 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10491
Shuo Qian3b6ee772019-11-13 17:43:31 -080010492 final long identity = Binder.clearCallingIdentity();
10493 try {
10494 for (Phone phone: PhoneFactory.getPhones()) {
10495 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10496 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010497 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10498 }
10499 }
10500 } finally {
10501 Binder.restoreCallingIdentity(identity);
10502 }
10503 }
10504
10505 @Override
10506 public void resetOtaEmergencyNumberDbFilePath() {
10507 enforceActiveEmergencySessionPermission();
10508
joonhunshin4ac60942023-11-15 15:23:39 +000010509 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10510 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10511
Shuo Qianc373f112020-03-05 17:55:34 -080010512 final long identity = Binder.clearCallingIdentity();
10513 try {
10514 for (Phone phone: PhoneFactory.getPhones()) {
10515 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10516 if (tracker != null) {
10517 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010518 }
10519 }
10520 } finally {
10521 Binder.restoreCallingIdentity(identity);
10522 }
10523 }
10524
10525 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010526 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10527 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10528 Phone phone = getPhone(subId);
10529 if (phone == null) {
10530 return null;
10531 }
10532 final long identity = Binder.clearCallingIdentity();
10533 try {
10534 UiccProfile profile = UiccController.getInstance()
10535 .getUiccProfileForPhone(phone.getPhoneId());
10536 if (profile != null) {
10537 return profile.getCertsFromCarrierPrivilegeAccessRules();
10538 }
10539 } finally {
10540 Binder.restoreCallingIdentity(identity);
10541 }
10542 return null;
10543 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010544
10545 /**
10546 * Enable or disable a modem stack.
10547 */
10548 @Override
10549 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10550 enforceModifyPermission();
10551
joonhunshin4ac60942023-11-15 15:23:39 +000010552 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10553 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10554
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010555 final long identity = Binder.clearCallingIdentity();
10556 try {
10557 Phone phone = PhoneFactory.getPhone(slotIndex);
10558 if (phone == null) {
10559 return false;
10560 } else {
10561 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10562 }
10563 } finally {
10564 Binder.restoreCallingIdentity(identity);
10565 }
10566 }
Michelecea4cf22018-12-21 15:00:11 -080010567
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010568 /**
10569 * Whether a modem stack is enabled or not.
10570 */
10571 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010572 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10573 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010574 Phone phone = PhoneFactory.getPhone(slotIndex);
10575 if (phone == null) return false;
10576
10577 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010578 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10579 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010580 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10581 }
10582
joonhunshin4ac60942023-11-15 15:23:39 +000010583 enforceTelephonyFeatureWithException(callingPackage,
10584 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10585
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010586 final long identity = Binder.clearCallingIdentity();
10587 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010588 try {
10589 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10590 } catch (NoSuchElementException ex) {
10591 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10592 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010593 } finally {
10594 Binder.restoreCallingIdentity(identity);
10595 }
10596 }
10597
Michelecea4cf22018-12-21 15:00:11 -080010598 @Override
Michele0ea7d782019-03-19 14:58:42 -070010599 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010600 enforceModifyPermission();
10601
joonhunshin4ac60942023-11-15 15:23:39 +000010602 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10603 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10604
Michelecea4cf22018-12-21 15:00:11 -080010605 final long identity = Binder.clearCallingIdentity();
10606 try {
10607 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010608 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010609 .commit();
10610 } finally {
10611 Binder.restoreCallingIdentity(identity);
10612 }
10613 }
10614
10615 @Override
Michele0ea7d782019-03-19 14:58:42 -070010616 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010617 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010619 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10620 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010621 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010622 }
Michelecea4cf22018-12-21 15:00:11 -080010623
joonhunshin4ac60942023-11-15 15:23:39 +000010624 enforceTelephonyFeatureWithException(callingPackage,
10625 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10626
Michelecea4cf22018-12-21 15:00:11 -080010627 final long identity = Binder.clearCallingIdentity();
10628 try {
Michele0ea7d782019-03-19 14:58:42 -070010629 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010630 } finally {
10631 Binder.restoreCallingIdentity(identity);
10632 }
10633 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010634
Michele0ea7d782019-03-19 14:58:42 -070010635 @TelephonyManager.IsMultiSimSupportedResult
10636 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010637 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10638 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10639 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010640 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10641 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010642 }
10643 // Check if the hardware supports multisim functionality. If usage of multisim is not
10644 // supported by the modem, indicate that it is restricted.
10645 PhoneCapability staticCapability =
10646 mPhoneConfigurationManager.getStaticPhoneCapability();
10647 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010648 loge("isMultiSimSupportedInternal: no static configuration available");
10649 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010650 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010651 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010652 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10653 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010654 }
10655 // Check if support of multiple SIMs is restricted by carrier
10656 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010657 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010658 }
10659
Michele0ea7d782019-03-19 14:58:42 -070010660 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010661 }
10662
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010663 /**
10664 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010665 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10666 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10667 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010668 * @param numOfSims number of active sims we want to switch to
10669 */
10670 @Override
10671 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010672 if (numOfSims == 1) {
10673 enforceModifyPermission();
10674 } else {
10675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10676 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10677 }
joonhunshin4ac60942023-11-15 15:23:39 +000010678
10679 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10680 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10681
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010682 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010683
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010684 try {
Michele30b57b22019-03-01 12:01:14 -080010685 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010686 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010687 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10688 return;
10689 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010690 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10691 } finally {
10692 Binder.restoreCallingIdentity(identity);
10693 }
10694 }
10695
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010696 @Override
10697 public boolean isApplicationOnUicc(int subId, int appType) {
10698 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010699
10700 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10701 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10702
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010703 Phone phone = getPhone(subId);
10704 if (phone == null) {
10705 return false;
10706 }
10707 final long identity = Binder.clearCallingIdentity();
10708 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010709 UiccPort uiccPort = phone.getUiccPort();
10710 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010711 return false;
10712 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010713 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010714 if (uiccProfile == null) {
10715 return false;
10716 }
10717 if (TelephonyManager.APPTYPE_SIM <= appType
10718 && appType <= TelephonyManager.APPTYPE_ISIM) {
10719 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10720 }
10721 return false;
10722 } finally {
10723 Binder.restoreCallingIdentity(identity);
10724 }
10725 }
10726
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010727 /**
chen xub4baa772019-04-03 10:23:41 -070010728 * Get whether making changes to modem configurations will trigger reboot.
10729 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010730 */
10731 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010732 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10733 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010735 mApp, subId, callingPackage, callingFeatureId,
10736 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010737 return false;
10738 }
joonhunshin4ac60942023-11-15 15:23:39 +000010739
10740 enforceTelephonyFeatureWithException(callingPackage,
10741 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10742 "doesSwitchMultiSimConfigTriggerReboot");
10743
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010744 final long identity = Binder.clearCallingIdentity();
10745 try {
10746 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10747 } finally {
10748 Binder.restoreCallingIdentity(identity);
10749 }
10750 }
10751
Nathan Harold29f5f052019-02-15 13:41:57 -080010752 private void updateModemStateMetrics() {
10753 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10754 // TODO: check the state for each modem if the api is ready.
10755 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10756 }
10757
Pengquan Meng3889a572019-01-23 11:16:29 -080010758 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010759 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010760 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010761 // Verify that the callingPackage belongs to the calling UID
10762 mApp.getSystemService(AppOpsManager.class)
10763 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010764
10765 enforceTelephonyFeatureWithException(callingPackage,
10766 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10767
Pengquan Meng3889a572019-01-23 11:16:29 -080010768 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010769 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010770 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010771 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10772 if (slotInfos != null) {
10773 for (int i = 0; i < slotInfos.length; i++) {
10774 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10775 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10776 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10777 portInfo.getLogicalSlotIndex()));
10778 }
10779 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010780 }
10781 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010782 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010783 } finally {
10784 Binder.restoreCallingIdentity(identity);
10785 }
10786 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010787
10788 /**
10789 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010790 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010791 */
jimsunf9ec1622022-09-13 21:18:43 +080010792 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010793 @Override
10794 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010795 return getHalVersion(HAL_SERVICE_RADIO);
10796 }
10797
10798 /**
10799 * Get the HAL Version of a specific service
10800 */
10801 @Override
10802 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010803 Phone phone = getDefaultPhone();
10804 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010805 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010806 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10807 return hv.major * 100 + hv.minor;
10808 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010809
10810 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010811 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010812 *
10813 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010814 */
10815 @Override
sangyun097dcf72024-01-04 10:35:49 +090010816 public @Nullable String getCurrentPackageName() {
10817 PackageManager pm = mApp.getPackageManager();
10818 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10819 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010820 }
10821
10822 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010823 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10824 * corresponding network requests on a subId.
10825 *
10826 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010827 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010828 * 2) APN is un-metered for this subscription, or
10829 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010830 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010831 *
10832 * @return whether data is allowed for a apn type.
10833 *
10834 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010835 */
10836 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010837 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010838 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10839 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010840
joonhunshin4ac60942023-11-15 15:23:39 +000010841 enforceTelephonyFeatureWithException(callingPackage,
10842 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10843
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010844 // Now that all security checks passes, perform the operation as ourselves.
10845 final long identity = Binder.clearCallingIdentity();
10846 try {
10847 Phone phone = getPhone(subId);
10848 if (phone == null) return false;
10849
Jack Yu27422a52022-03-21 10:38:05 -070010850 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010851 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010852 isMetered = phone.getDataNetworkController().getDataConfigManager()
10853 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10854 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010855 isDataEnabled = (phone.getDataSettingsManager() != null)
10856 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010857 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010858 } finally {
10859 Binder.restoreCallingIdentity(identity);
10860 }
10861 }
10862
10863 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010864 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010865 enforceReadPrivilegedPermission("isApnMetered");
10866
joonhunshin4ac60942023-11-15 15:23:39 +000010867 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10868 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10869
Malcolm Chene5ad5792019-04-18 13:51:02 -070010870 // Now that all security checks passes, perform the operation as ourselves.
10871 final long identity = Binder.clearCallingIdentity();
10872 try {
10873 Phone phone = getPhone(subId);
10874 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010875 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10876 DataUtils.apnTypeToNetworkCapability(apnType),
10877 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010878 } finally {
10879 Binder.restoreCallingIdentity(identity);
10880 }
10881 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010882
10883 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010884 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10885 int subscriptionId, IBooleanConsumer resultCallback) {
10886 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010887
10888 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10889 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10890
Hall Liu73f5d362020-01-20 13:42:00 -080010891 long token = Binder.clearCallingIdentity();
10892 try {
10893 Phone phone = getPhone(subscriptionId);
10894 if (phone == null) {
10895 try {
10896 if (resultCallback != null) {
10897 resultCallback.accept(false);
10898 }
10899 } catch (RemoteException e) {
10900 // ignore
10901 }
10902 return;
10903 }
10904 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10905 Pair.create(specifiers, (x) -> {
10906 try {
10907 if (resultCallback != null) {
10908 resultCallback.accept(x);
10909 }
10910 } catch (RemoteException e) {
10911 // ignore
10912 }
10913 });
10914 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10915 } finally {
10916 Binder.restoreCallingIdentity(token);
10917 }
10918 }
10919
10920 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010921 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10922 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010923 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010924 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010925
10926 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10927 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10928
Sarah Chin679c08a2020-11-18 13:39:35 -080010929 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10930 final long identity = Binder.clearCallingIdentity();
10931 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010932 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10933 if (result instanceof IllegalStateException) {
10934 throw (IllegalStateException) result;
10935 }
10936 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010937 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10938 return specifiers;
10939 } finally {
10940 Binder.restoreCallingIdentity(identity);
10941 }
10942 }
10943
10944 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010945 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010946 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010947
10948 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10949 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10950
Jack Yu8b766fc2022-03-21 09:42:33 -070010951 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010952 }
10953
10954 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010955 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10956 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010957 if (callingPackage == null) {
10958 callingPackage = getCurrentPackageName();
10959 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010960 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10961 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010962 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10963 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010964 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10965 }
10966 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10967 Intent intent = new Intent();
10968 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10969 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10970 // Bring up choose default SMS subscription dialog right now
10971 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10972 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10973 mApp.startActivity(intent);
10974 }
chen xud5ca2d52019-05-28 15:20:57 -070010975
10976 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010977 public void showSwitchToManagedProfileDialog() {
10978 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010979 try {
10980 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10981 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10982 // for work telephony.
10983 Intent intent = new Intent(Intent.ACTION_SENDTO);
10984 intent.setData(Uri.parse("smsto:"));
10985 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10986 mApp.startActivity(intent);
10987 } catch (ActivityNotFoundException e) {
10988 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10989 Intent intent = new Intent();
10990 intent.setClass(mApp, ErrorDialogActivity.class);
10991 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10992 mApp.startActivity(intent);
10993 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010994 }
10995
10996 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010997 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010998 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10999 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11000
chen xud5ca2d52019-05-28 15:20:57 -070011001 //TODO investigate if this API should require proper permission check in R b/133791609
11002 final long identity = Binder.clearCallingIdentity();
11003 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011004 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11005 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11006 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11007 return carrierUAProfUrl;
11008 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011009 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11010 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011011 } finally {
11012 Binder.restoreCallingIdentity(identity);
11013 }
11014 }
11015
11016 @Override
11017 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011018 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11019 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11020
chen xud5ca2d52019-05-28 15:20:57 -070011021 //TODO investigate if this API should require proper permission check in R b/133791609
11022 final long identity = Binder.clearCallingIdentity();
11023 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011024 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11025 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11026 if (!TextUtils.isEmpty(carrierUserAgent)) {
11027 return carrierUserAgent;
11028 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011029 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11030 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011031 } finally {
11032 Binder.restoreCallingIdentity(identity);
11033 }
11034 }
Jack Yub07d4972019-05-28 16:12:25 -070011035
11036 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011037 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11038 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011039
joonhunshin4ac60942023-11-15 15:23:39 +000011040 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11041 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11042
Jack Yub07d4972019-05-28 16:12:25 -070011043 final long identity = Binder.clearCallingIdentity();
11044 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011045 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011046 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011047
Ling Maf188d502022-09-16 15:22:36 -070011048 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011049 } finally {
11050 Binder.restoreCallingIdentity(identity);
11051 }
11052 }
11053
11054 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011055 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011056 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011057 enforceModifyPermission();
11058
joonhunshin4ac60942023-11-15 15:23:39 +000011059 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11060 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11061
changbettyd5c246e2019-12-24 15:40:37 +080011062 final long identity = Binder.clearCallingIdentity();
11063 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011064 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011065 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011066
Ling Maf188d502022-09-16 15:22:36 -070011067 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011068 } finally {
11069 Binder.restoreCallingIdentity(identity);
11070 }
11071 }
11072
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011073 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011074 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011075 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11076 * otherwise.
11077 */
11078 @Override
11079 public void setCepEnabled(boolean isCepEnabled) {
11080 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11081
11082 final long identity = Binder.clearCallingIdentity();
11083 try {
11084 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11085 for (Phone phone : PhoneFactory.getPhones()) {
11086 Phone defaultPhone = phone.getImsPhone();
11087 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11088 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11089 ImsPhoneCallTracker imsPhoneCallTracker =
11090 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11091 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11092 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11093 + imsPhone.getMsisdn());
11094 }
11095 }
11096 } finally {
11097 Binder.restoreCallingIdentity(identity);
11098 }
11099 }
allenwtsu46dcc572020-01-08 18:24:03 +080011100
11101 /**
11102 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11103 *
11104 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11105 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11106 * before being read.
11107 */
11108 @Override
11109 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11110 isCompressed) {
11111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11112 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011113 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11114 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11115 }
joonhunshin4ac60942023-11-15 15:23:39 +000011116
11117 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11118 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11119 Binder.getCallingUserHandle())) {
11120 if (!isImsAvailableOnDevice()) {
11121 // ProvisioningManager can not handle ServiceSpecificException.
11122 // Throw the IllegalStateException and annotate ProvisioningManager.
11123 throw new IllegalStateException("IMS not available on device.");
11124 }
11125 } else {
11126 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11127 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11128 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011129 }
11130
11131 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011132 try {
Hui Wang761a6682020-10-31 05:12:53 +000011133 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11134 } finally {
11135 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011136 }
11137 }
zoey chene02881a2019-12-30 16:11:23 +080011138
11139 @Override
11140 public boolean isIccLockEnabled(int subId) {
11141 enforceReadPrivilegedPermission("isIccLockEnabled");
11142
joonhunshin4ac60942023-11-15 15:23:39 +000011143 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11144 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11145
zoey chene02881a2019-12-30 16:11:23 +080011146 // Now that all security checks passes, perform the operation as ourselves.
11147 final long identity = Binder.clearCallingIdentity();
11148 try {
11149 Phone phone = getPhone(subId);
11150 if (phone != null && phone.getIccCard() != null) {
11151 return phone.getIccCard().getIccLockEnabled();
11152 } else {
11153 return false;
11154 }
11155 } finally {
11156 Binder.restoreCallingIdentity(identity);
11157 }
11158 }
11159
11160 /**
11161 * Set the ICC pin lock enabled or disabled.
11162 *
11163 * @return an integer representing the status of IccLock enabled or disabled in the following
11164 * three cases:
11165 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11166 * successfully.
11167 * - Positive number and zero for remaining password attempts.
11168 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11169 *
11170 */
11171 @Override
11172 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11173 enforceModifyPermission();
11174
joonhunshin4ac60942023-11-15 15:23:39 +000011175 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11176 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11177
zoey chene02881a2019-12-30 16:11:23 +080011178 Phone phone = getPhone(subId);
11179 if (phone == null) {
11180 return 0;
11181 }
11182 // Now that all security checks passes, perform the operation as ourselves.
11183 final long identity = Binder.clearCallingIdentity();
11184 try {
11185 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11186 new Pair<Boolean, String>(enabled, password), phone, null);
11187 return attemptsRemaining;
11188
11189 } catch (Exception e) {
11190 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11191 } finally {
11192 Binder.restoreCallingIdentity(identity);
11193 }
11194 return 0;
11195 }
11196
11197 /**
11198 * Change the ICC password used in ICC pin lock.
11199 *
11200 * @return an integer representing the status of IccLock changed in the following three cases:
11201 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11202 * - Positive number and zero for remaining password attempts.
11203 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11204 *
11205 */
11206 @Override
11207 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11208 enforceModifyPermission();
11209
joonhunshin4ac60942023-11-15 15:23:39 +000011210 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11211 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11212
zoey chene02881a2019-12-30 16:11:23 +080011213 Phone phone = getPhone(subId);
11214 if (phone == null) {
11215 return 0;
11216 }
11217 // Now that all security checks passes, perform the operation as ourselves.
11218 final long identity = Binder.clearCallingIdentity();
11219 try {
11220 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11221 new Pair<String, String>(oldPassword, newPassword), phone, null);
11222 return attemptsRemaining;
11223
11224 } catch (Exception e) {
11225 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11226 } finally {
11227 Binder.restoreCallingIdentity(identity);
11228 }
11229 return 0;
11230 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011231
11232 /**
11233 * Request for receiving user activity notification
11234 */
11235 @Override
11236 public void requestUserActivityNotification() {
11237 if (!mNotifyUserActivity.get()
11238 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11239 mNotifyUserActivity.set(true);
11240 }
11241 }
11242
11243 /**
11244 * Called when userActivity is signalled in the power manager.
11245 * This is safe to call from any thread, with any window manager locks held or not.
11246 */
11247 @Override
11248 public void userActivity() {
11249 // ***************************************
11250 // * Inherited from PhoneWindowManager *
11251 // ***************************************
11252 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11253 // WITH ITS LOCKS HELD.
11254 //
11255 // This code must be VERY careful about the locks
11256 // it acquires.
11257 // In fact, the current code acquires way too many,
11258 // and probably has lurking deadlocks.
11259
11260 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11261 throw new SecurityException("Only the OS may call notifyUserActivity()");
11262 }
11263
11264 if (mNotifyUserActivity.getAndSet(false)) {
11265 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11266 USER_ACTIVITY_NOTIFICATION_DELAY);
11267 }
11268 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011269
11270 @Override
11271 public boolean canConnectTo5GInDsdsMode() {
11272 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11273 }
Jack Yud10cdd42020-09-28 20:28:01 -070011274
11275 @Override
11276 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11277 String callingFeatureId) {
11278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11279 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11280 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11281 }
11282
joonhunshin4ac60942023-11-15 15:23:39 +000011283 enforceTelephonyFeatureWithException(callingPackage,
11284 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11285
Jack Yud10cdd42020-09-28 20:28:01 -070011286 Phone phone = getPhone(subId);
11287 if (phone == null) {
11288 throw new RuntimeException("phone is not available");
11289 }
11290 // Now that all security checks passes, perform the operation as ourselves.
11291 final long identity = Binder.clearCallingIdentity();
11292 try {
11293 return phone.getEquivalentHomePlmns();
11294 } finally {
11295 Binder.restoreCallingIdentity(identity);
11296 }
11297 }
Daniel Bright59e67312020-11-13 11:49:37 -080011298
11299 @Override
11300 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011301 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011302 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11303 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11304 "isRadioInterfaceCapabilitySupported");
11305
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011306 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011307 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011308 if (radioInterfaceCapabilities == null) {
11309 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011310 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011311 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011312 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011313
Hui Wang641e81c2020-10-12 12:14:23 -070011314 @Override
11315 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11316 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011317 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11318 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11319 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11320 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11321 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011322
11323 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11324 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11325
Hui Wang641e81c2020-10-12 12:14:23 -070011326 if (DBG) {
11327 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11328 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11329 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11330 }
11331
11332 if (!SubscriptionManager.isValidSubscriptionId(subId)
11333 || appType < TelephonyManager.APPTYPE_UNKNOWN
11334 || appType > TelephonyManager.APPTYPE_ISIM
11335 || nafUrl == null || securityProtocol == null || callback == null) {
11336 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11337 if (callback != null) {
11338 try {
11339 callback.onAuthenticationFailure(
11340 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11341 } catch (RemoteException exception) {
11342 log("Fail to notify onAuthenticationFailure due to " + exception);
11343 }
11344 return;
11345 }
11346 }
11347
11348 final long token = Binder.clearCallingIdentity();
11349 try {
11350 getGbaManager(subId).bootstrapAuthenticationRequest(
11351 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011352 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011353 } finally {
11354 Binder.restoreCallingIdentity(token);
11355 }
11356 }
11357
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011358 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011359 * Attempts to set the radio power state for all phones for thermal reason.
11360 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011361 * requested radio power state will actually be set. See {@link
11362 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11363 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011364 * @param enable {@code true} if trying to turn radio on.
11365 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11366 * false}.
11367 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011368 private boolean setRadioPowerForThermal(boolean enable) {
11369 boolean isPhoneAvailable = false;
11370 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11371 Phone phone = PhoneFactory.getPhone(i);
11372 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011373 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011374 isPhoneAvailable = true;
11375 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011376 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011377
11378 // return true if successfully informed the phone object about the thermal radio power
11379 // request.
11380 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011381 }
11382
11383 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011384 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011385 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11386 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11387 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11388 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11389 throw new IllegalArgumentException("modem does not support data throttling");
11390 }
11391
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011392 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11393 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011394 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011395 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11396 }
11397
Sarah Chinecc78c42022-03-31 21:16:48 -070011398 setDataEnabledForReason(
11399 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011400
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011401 if (isDataThrottlingSupported) {
11402 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011403 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011404 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11405 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11406 } else if (thermalMitigationResult
11407 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011408 log("Modem likely does not support data throttling on secondary carrier. Data " +
11409 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11410 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011411 }
11412 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011413 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011414
11415 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011416 }
11417
Jack Nudelman644b91a2021-03-12 14:09:48 -080011418 private static List<String> getThermalMitigationAllowlist(Context context) {
11419 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11420 for (String pckg : context.getResources()
11421 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11422 sThermalMitigationAllowlistedPackages.add(pckg);
11423 }
11424 }
11425
11426 return sThermalMitigationAllowlistedPackages;
11427 }
11428
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011429 private boolean isAnyPhoneInEmergencyState() {
11430 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11431 if (tm.isInEmergencyCall()) {
11432 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11433 return true;
11434 }
11435 for (Phone phone : PhoneFactory.getPhones()) {
11436 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11437 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011438 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11439 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011440 return true;
11441 }
11442 }
11443
11444 return false;
11445 }
11446
Jack Nudelman644b91a2021-03-12 14:09:48 -080011447 /**
11448 * Used by shell commands to add an authorized package name for thermal mitigation.
11449 * @param packageName name of package to be allowlisted
11450 * @param context
11451 */
11452 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11453 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11454 sThermalMitigationAllowlistedPackages.add(packageName);
11455 }
11456
11457 /**
11458 * Used by shell commands to remove an authorized package name for thermal mitigation.
11459 * @param packageName name of package to remove from allowlist
11460 * @param context
11461 */
11462 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11463 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11464 sThermalMitigationAllowlistedPackages.remove(packageName);
11465 }
11466
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011467 /**
11468 * Thermal mitigation request to control functionalities at modem.
11469 *
11470 * @param subId the id of the subscription.
11471 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011472 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011473 *
11474 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11475 */
11476 @Override
11477 @ThermalMitigationResult
11478 public int sendThermalMitigationRequest(
11479 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011480 ThermalMitigationRequest thermalMitigationRequest,
11481 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011482 enforceModifyPermission();
11483
Jack Nudelman644b91a2021-03-12 14:09:48 -080011484 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011485
11486 enforceTelephonyFeatureWithException(callingPackage,
11487 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11488
Jack Nudelman644b91a2021-03-12 14:09:48 -080011489 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11490 .contains(callingPackage)) {
11491 throw new SecurityException("Calling package must be configured in the device config. "
11492 + "calling package: " + callingPackage);
11493 }
11494
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011495 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11496 final long identity = Binder.clearCallingIdentity();
11497
11498 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11499 try {
11500 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11501 switch (thermalMitigationAction) {
11502 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11503 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011504 handleDataThrottlingRequest(subId,
11505 thermalMitigationRequest.getDataThrottlingRequest(),
11506 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011507 break;
11508 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11509 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11510 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11511 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11512 }
11513
11514 // Ensure that radio is on. If not able to power on due to phone being
11515 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011516 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011517 thermalMitigationResult =
11518 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11519 break;
11520 }
11521
11522 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011523 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011524 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11525 break;
11526 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11527 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11528 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11529 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11530 }
11531
11532 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11533 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011534 Phone phone = getPhone(subId);
11535 if (phone == null) {
11536 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011537 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011538 break;
11539 }
11540
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011541 TelephonyConnectionService service =
11542 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011543 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011544 Log.e(LOG_TAG, "An emergency call is pending");
11545 thermalMitigationResult =
11546 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11547 break;
11548 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011549 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011550 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011551 break;
11552 }
11553 } else {
11554 thermalMitigationResult =
11555 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11556 break;
11557 }
11558
11559 // Turn radio off. If not able to power off due to phone being unavailable,
11560 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011561 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011562 thermalMitigationResult =
11563 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11564 break;
11565 }
11566 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011567 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011568 break;
11569 default:
11570 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11571 + "not exist. Requested action: " + thermalMitigationAction);
11572 }
11573 } catch (IllegalArgumentException e) {
11574 throw e;
11575 } catch (Exception e) {
11576 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11577 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11578 } finally {
11579 Binder.restoreCallingIdentity(identity);
11580 }
11581
11582 if (DBG) {
11583 log("thermalMitigationRequest returning with thermalMitigationResult: "
11584 + thermalMitigationResult);
11585 }
11586
11587 return thermalMitigationResult;
11588 }
Hui Wang641e81c2020-10-12 12:14:23 -070011589
11590 /**
11591 * Set the GbaService Package Name that Telephony will bind to.
11592 *
11593 * @param subId The sim that the GbaService is associated with.
11594 * @param packageName The name of the package to be replaced with.
11595 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11596 */
11597 @Override
11598 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11599 enforceModifyPermission();
11600
11601 final long identity = Binder.clearCallingIdentity();
11602 try {
11603 return getGbaManager(subId).overrideServicePackage(packageName);
11604 } finally {
11605 Binder.restoreCallingIdentity(identity);
11606 }
11607 }
11608
11609 /**
11610 * Return the package name of the currently bound GbaService.
11611 *
11612 * @param subId The sim that the GbaService is associated with.
11613 * @return the package name of the GbaService configuration, null if GBA is not supported.
11614 */
11615 @Override
11616 public String getBoundGbaService(int subId) {
11617 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11618
11619 final long identity = Binder.clearCallingIdentity();
11620 try {
11621 return getGbaManager(subId).getServicePackage();
11622 } finally {
11623 Binder.restoreCallingIdentity(identity);
11624 }
11625 }
11626
11627 /**
11628 * Set the release time for telephony to unbind GbaService.
11629 *
11630 * @param subId The sim that the GbaService is associated with.
11631 * @param interval The release time to unbind GbaService by millisecond.
11632 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11633 */
11634 @Override
11635 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11636 enforceModifyPermission();
11637
11638 final long identity = Binder.clearCallingIdentity();
11639 try {
11640 return getGbaManager(subId).overrideReleaseTime(interval);
11641 } finally {
11642 Binder.restoreCallingIdentity(identity);
11643 }
11644 }
11645
11646 /**
11647 * Return the release time for telephony to unbind GbaService.
11648 *
11649 * @param subId The sim that the GbaService is associated with.
11650 * @return The release time to unbind GbaService by millisecond.
11651 */
11652 @Override
11653 public int getGbaReleaseTime(int subId) {
11654 enforceReadPrivilegedPermission("getGbaReleaseTime");
11655
11656 final long identity = Binder.clearCallingIdentity();
11657 try {
11658 return getGbaManager(subId).getReleaseTime();
11659 } finally {
11660 Binder.restoreCallingIdentity(identity);
11661 }
11662 }
11663
11664 private GbaManager getGbaManager(int subId) {
11665 GbaManager instance = GbaManager.getInstance(subId);
11666 if (instance == null) {
11667 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11668 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11669 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11670 }
11671 return instance;
11672 }
Hui Wang761a6682020-10-31 05:12:53 +000011673
11674 /**
11675 * indicate whether the device and the carrier can support
11676 * RCS VoLTE single registration.
11677 */
11678 @Override
11679 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011680 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11681 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11682 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11683 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011684
11685 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11686 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11687 }
11688
11689 final long identity = Binder.clearCallingIdentity();
11690 try {
11691 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11692 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011693 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11694 if (isCapable != null) {
11695 return isCapable;
11696 }
Hui Wang761a6682020-10-31 05:12:53 +000011697 }
Hui Wang67af90e2021-06-04 16:57:15 -070011698 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11699 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011700 } finally {
11701 Binder.restoreCallingIdentity(identity);
11702 }
11703 }
11704
11705 /**
11706 * Register RCS provisioning callback.
11707 */
11708 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011709 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011710 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011711 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011712 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011713 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11714 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011715
11716 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11717 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11718 }
joonhunshin4ac60942023-11-15 15:23:39 +000011719 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11720 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11721 Binder.getCallingUserHandle())) {
11722 if (!isImsAvailableOnDevice()) {
11723 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11724 "IMS not available on device.");
11725 }
11726 } else {
11727 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11728 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011729 }
11730
11731 final long identity = Binder.clearCallingIdentity();
11732 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011733 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011734 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011735 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11736 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011737 }
Hui Wang761a6682020-10-31 05:12:53 +000011738 } finally {
11739 Binder.restoreCallingIdentity(identity);
11740 }
11741 }
11742
11743 /**
11744 * Unregister RCS provisioning callback.
11745 */
11746 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011747 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011748 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011749 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011750 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011751 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11752 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011753
11754 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11755 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11756 }
joonhunshin4ac60942023-11-15 15:23:39 +000011757
11758 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11759 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11760 Binder.getCallingUserHandle())) {
11761 if (!isImsAvailableOnDevice()) {
11762 // operation failed silently
11763 Rlog.w(LOG_TAG, "IMS not available on device.");
11764 return;
11765 }
11766 } else {
11767 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11768 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11769 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011770 }
11771
11772 final long identity = Binder.clearCallingIdentity();
11773 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011774 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011775 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011776 } finally {
11777 Binder.restoreCallingIdentity(identity);
11778 }
11779 }
11780
11781 /**
11782 * trigger RCS reconfiguration.
11783 */
11784 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011785 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11786 "triggerRcsReconfiguration",
11787 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011788
11789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11790 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11791 }
joonhunshin4ac60942023-11-15 15:23:39 +000011792 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11793 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11794 Binder.getCallingUserHandle())) {
11795 if (!isImsAvailableOnDevice()) {
11796 // ProvisioningManager can not handle ServiceSpecificException.
11797 // Throw the IllegalStateException and annotate ProvisioningManager.
11798 throw new IllegalStateException("IMS not available on device.");
11799 }
11800 } else {
11801 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11802 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011803 }
11804
11805 final long identity = Binder.clearCallingIdentity();
11806 try {
11807 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11808 } finally {
11809 Binder.restoreCallingIdentity(identity);
11810 }
11811 }
11812
11813 /**
11814 * Provide the client configuration parameters of the RCS application.
11815 */
11816 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011817 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11818 "setRcsClientConfiguration",
11819 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011820
11821 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11822 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11823 }
joonhunshin4ac60942023-11-15 15:23:39 +000011824 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11825 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11826 Binder.getCallingUserHandle())) {
11827 if (!isImsAvailableOnDevice()) {
11828 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11829 "IMS not available on device.");
11830 }
11831 } else {
11832 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11833 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011834 }
11835
11836 final long identity = Binder.clearCallingIdentity();
11837
11838 try {
11839 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11840 if (configBinder == null) {
11841 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011842 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11843 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011844 } else {
11845 configBinder.setRcsClientConfiguration(rcc);
11846 }
joonhunshin3e154242021-09-17 06:33:39 +000011847
11848 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11849 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011850 } catch (RemoteException e) {
11851 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011852 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11853 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011854 } finally {
11855 Binder.restoreCallingIdentity(identity);
11856 }
11857 }
11858
11859 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011860 * Enables or disables the test mode for RCS VoLTE single registration.
11861 */
11862 @Override
11863 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11864 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11865 "setRcsSingleRegistrationTestModeEnabled");
11866
11867 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11868 }
11869
11870 /**
11871 * Gets the test mode for RCS VoLTE single registration.
11872 */
11873 @Override
11874 public boolean getRcsSingleRegistrationTestModeEnabled() {
11875 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11876 "getRcsSingleRegistrationTestModeEnabled");
11877
11878 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11879 }
11880
11881 /**
Hui Wang761a6682020-10-31 05:12:53 +000011882 * Overrides the config of RCS VoLTE single registration enabled for the device.
11883 */
11884 @Override
11885 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11886 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11887 "setDeviceSingleRegistrationEnabledOverride");
11888 enforceModifyPermission();
11889
11890 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11891 : Boolean.parseBoolean(enabledStr);
11892 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011893 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011894 }
11895
11896 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011897 * Sends a device to device communication message. Only usable via shell.
11898 * @param message message to send.
11899 * @param value message value.
11900 */
11901 @Override
11902 public void sendDeviceToDeviceMessage(int message, int value) {
11903 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011904 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011905 enforceModifyPermission();
11906
11907 final long identity = Binder.clearCallingIdentity();
11908 try {
11909 TelephonyConnectionService service =
11910 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11911 if (service == null) {
11912 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11913 return;
11914 }
11915 service.sendTestDeviceToDeviceMessage(message, value);
11916 } finally {
11917 Binder.restoreCallingIdentity(identity);
11918 }
11919 }
11920
Tyler Gunnbabbda02021-02-10 11:05:02 -080011921 /**
11922 * Sets the specified device to device transport active.
11923 * @param transport The transport to set active.
11924 */
11925 @Override
11926 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11927 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11928 "setActiveDeviceToDeviceTransport");
11929 enforceModifyPermission();
11930
11931 final long identity = Binder.clearCallingIdentity();
11932 try {
11933 TelephonyConnectionService service =
11934 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11935 if (service == null) {
11936 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11937 return;
11938 }
11939 service.setActiveDeviceToDeviceTransport(transport);
11940 } finally {
11941 Binder.restoreCallingIdentity(identity);
11942 }
11943 }
Tyler Gunn92479152021-01-20 16:30:10 -080011944
Tyler Gunnd4339262021-05-03 14:46:49 -070011945 @Override
11946 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11947 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11948 "setDeviceToDeviceForceEnabled");
11949
11950 final long identity = Binder.clearCallingIdentity();
11951 try {
11952 Arrays.stream(PhoneFactory.getPhones()).forEach(
11953 p -> {
11954 Phone thePhone = p.getImsPhone();
11955 if (thePhone != null && thePhone instanceof ImsPhone) {
11956 ImsPhone imsPhone = (ImsPhone) thePhone;
11957 CallTracker tracker = imsPhone.getCallTracker();
11958 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11959 ImsPhoneCallTracker imsPhoneCallTracker =
11960 (ImsPhoneCallTracker) tracker;
11961 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11962 }
11963 }
11964 }
11965 );
11966 } finally {
11967 Binder.restoreCallingIdentity(identity);
11968 }
11969 }
11970
Tyler Gunn92479152021-01-20 16:30:10 -080011971 /**
Hui Wang761a6682020-10-31 05:12:53 +000011972 * Gets the config of RCS VoLTE single registration enabled for the device.
11973 */
11974 @Override
11975 public boolean getDeviceSingleRegistrationEnabled() {
11976 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11977 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11978 }
11979
11980 /**
11981 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11982 */
11983 @Override
11984 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11985 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11986 "setCarrierSingleRegistrationEnabledOverride");
11987 enforceModifyPermission();
11988
11989 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11990 : Boolean.parseBoolean(enabledStr);
11991 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11992 subId, enabled);
11993 }
11994
11995 /**
11996 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11997 */
11998 @Override
11999 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12000 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12001 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12002 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012003
12004 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012005 * Overrides the ims feature validation result
12006 */
12007 @Override
12008 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12009 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12010 "setImsFeatureValidationOverride");
12011
12012 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12013 : Boolean.parseBoolean(enabledStr);
12014 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12015 subId, enabled);
12016 }
12017
12018 /**
12019 * Gets the ims feature validation override value
12020 */
12021 @Override
12022 public boolean getImsFeatureValidationOverride(int subId) {
12023 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12024 "getImsFeatureValidationOverride");
12025 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12026 }
12027
12028 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012029 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12030 * their mobile plan.
12031 */
12032 @Override
12033 public String getMobileProvisioningUrl() {
12034 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12035 final long identity = Binder.clearCallingIdentity();
12036 try {
12037 return getDefaultPhone().getMobileProvisioningUrl();
12038 } finally {
12039 Binder.restoreCallingIdentity(identity);
12040 }
12041 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012042
James.cf Linbcdf8b32021-01-14 16:44:13 +080012043 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012044 * Get the EAB contact from the EAB database.
12045 */
12046 @Override
12047 public String getContactFromEab(String contact) {
12048 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12049 enforceModifyPermission();
12050 final long identity = Binder.clearCallingIdentity();
12051 try {
12052 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12053 } finally {
12054 Binder.restoreCallingIdentity(identity);
12055 }
12056 }
12057
12058 /**
Calvin Pana1434322021-07-01 19:27:01 +080012059 * Get the EAB capability from the EAB database.
12060 */
12061 @Override
12062 public String getCapabilityFromEab(String contact) {
12063 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12064 enforceModifyPermission();
12065 final long identity = Binder.clearCallingIdentity();
12066 try {
12067 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12068 } finally {
12069 Binder.restoreCallingIdentity(identity);
12070 }
12071 }
12072
12073 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012074 * Remove the EAB contacts from the EAB database.
12075 */
12076 @Override
12077 public int removeContactFromEab(int subId, String contacts) {
12078 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12079 enforceModifyPermission();
12080 final long identity = Binder.clearCallingIdentity();
12081 try {
12082 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12083 } finally {
12084 Binder.restoreCallingIdentity(identity);
12085 }
12086 }
12087
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012088 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012089 public boolean getDeviceUceEnabled() {
12090 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12091 final long identity = Binder.clearCallingIdentity();
12092 try {
12093 return mApp.getDeviceUceEnabled();
12094 } finally {
12095 Binder.restoreCallingIdentity(identity);
12096 }
12097 }
12098
12099 @Override
12100 public void setDeviceUceEnabled(boolean isEnabled) {
12101 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12102 final long identity = Binder.clearCallingIdentity();
12103 try {
12104 mApp.setDeviceUceEnabled(isEnabled);
12105 } finally {
12106 Binder.restoreCallingIdentity(identity);
12107 }
12108 }
12109
Brad Ebinger14d467f2021-02-12 06:18:28 +000012110 /**
12111 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12112 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12113 */
12114 // Used for SHELL command only right now.
12115 @Override
12116 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12117 List<String> featureTags) {
12118 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12119 "addUceRegistrationOverrideShell");
12120 final long identity = Binder.clearCallingIdentity();
12121 try {
12122 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12123 new ArraySet<>(featureTags));
12124 } catch (ImsException e) {
12125 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12126 } finally {
12127 Binder.restoreCallingIdentity(identity);
12128 }
12129 }
12130
12131 /**
12132 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12133 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12134 */
12135 // Used for SHELL command only right now.
12136 @Override
12137 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12138 List<String> featureTags) {
12139 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12140 "removeUceRegistrationOverrideShell");
12141 final long identity = Binder.clearCallingIdentity();
12142 try {
12143 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12144 new ArraySet<>(featureTags));
12145 } catch (ImsException e) {
12146 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12147 } finally {
12148 Binder.restoreCallingIdentity(identity);
12149 }
12150 }
12151
12152 /**
12153 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12154 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12155 */
12156 // Used for SHELL command only right now.
12157 @Override
12158 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12159 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12160 "clearUceRegistrationOverrideShell");
12161 final long identity = Binder.clearCallingIdentity();
12162 try {
12163 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12164 } catch (ImsException e) {
12165 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12166 } finally {
12167 Binder.restoreCallingIdentity(identity);
12168 }
12169 }
12170
12171 /**
12172 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12173 */
12174 // Used for SHELL command only right now.
12175 @Override
12176 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12177 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12178 "getLatestRcsContactUceCapabilityShell");
12179 final long identity = Binder.clearCallingIdentity();
12180 try {
12181 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12182 } catch (ImsException e) {
12183 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12184 } finally {
12185 Binder.restoreCallingIdentity(identity);
12186 }
12187 }
12188
12189 /**
12190 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12191 * device does not have an active PUBLISH.
12192 */
12193 // Used for SHELL command only right now.
12194 @Override
12195 public String getLastUcePidfXmlShell(int subId) {
12196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12197 final long identity = Binder.clearCallingIdentity();
12198 try {
12199 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12200 } catch (ImsException e) {
12201 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12202 } finally {
12203 Binder.restoreCallingIdentity(identity);
12204 }
12205 }
12206
James.cf Line8713a42021-04-29 16:04:26 +080012207 /**
12208 * Remove UCE requests cannot be sent to the network status.
12209 */
12210 // Used for SHELL command only right now.
12211 @Override
12212 public boolean removeUceRequestDisallowedStatus(int subId) {
12213 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12214 final long identity = Binder.clearCallingIdentity();
12215 try {
12216 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12217 } catch (ImsException e) {
12218 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12219 } finally {
12220 Binder.restoreCallingIdentity(identity);
12221 }
12222 }
12223
James.cf Lin18bb9002021-05-25 01:37:38 +080012224 /**
12225 * Remove UCE requests cannot be sent to the network status.
12226 */
12227 // Used for SHELL command only.
12228 @Override
12229 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12230 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12231 final long identity = Binder.clearCallingIdentity();
12232 try {
12233 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12234 } catch (ImsException e) {
12235 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12236 } finally {
12237 Binder.restoreCallingIdentity(identity);
12238 }
12239 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012240
James.cf Lin4b784aa2021-01-31 03:25:15 +080012241 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012242 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12243 String callingPackage) {
12244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12245 mApp, subId, "setSignalStrengthUpdateRequest");
12246
joonhunshin4ac60942023-11-15 15:23:39 +000012247 enforceTelephonyFeatureWithException(callingPackage,
12248 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12249
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012250 final int callingUid = Binder.getCallingUid();
12251 // Verify that tha callingPackage belongs to the calling UID
12252 mApp.getSystemService(AppOpsManager.class)
12253 .checkPackage(callingUid, callingPackage);
12254
Rambo Wang3607f502021-02-01 21:51:40 -080012255 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012256
12257 final long identity = Binder.clearCallingIdentity();
12258 try {
12259 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12260 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12261
12262 if (result instanceof IllegalStateException) {
12263 throw (IllegalStateException) result;
12264 }
12265 } finally {
12266 Binder.restoreCallingIdentity(identity);
12267 }
12268 }
12269
12270 @Override
12271 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12272 String callingPackage) {
12273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12274 mApp, subId, "clearSignalStrengthUpdateRequest");
12275
joonhunshin4ac60942023-11-15 15:23:39 +000012276 enforceTelephonyFeatureWithException(callingPackage,
12277 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12278
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012279 final int callingUid = Binder.getCallingUid();
12280 // Verify that tha callingPackage belongs to the calling UID
12281 mApp.getSystemService(AppOpsManager.class)
12282 .checkPackage(callingUid, callingPackage);
12283
12284 final long identity = Binder.clearCallingIdentity();
12285 try {
12286 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12287 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12288
12289 if (result instanceof IllegalStateException) {
12290 throw (IllegalStateException) result;
12291 }
12292 } finally {
12293 Binder.restoreCallingIdentity(identity);
12294 }
12295 }
12296
Rambo Wang3607f502021-02-01 21:51:40 -080012297 private static void validateSignalStrengthUpdateRequest(Context context,
12298 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012299 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12300 // phone/system process do not have further restriction on request
12301 return;
12302 }
12303
12304 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012305 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012306 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012307 context.enforceCallingOrSelfPermission(
12308 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12309 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012310 }
12311
12312 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012313 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012314 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012315 || info.isEnabled()) {
12316 throw new IllegalArgumentException(
12317 "Only system can set hide fields in SignalThresholdInfo");
12318 }
12319
12320 // Thresholds length for each RAN need in range. This has been validated in
12321 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12322 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12323 final int[] thresholds = info.getThresholds();
12324 Objects.requireNonNull(thresholds);
12325 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12326 || thresholds.length
12327 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12328 throw new IllegalArgumentException(
12329 "thresholds length is out of range: " + thresholds.length);
12330 }
12331 }
12332 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012333
12334 /**
12335 * Gets the current phone capability.
12336 *
12337 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12338 * @return the PhoneCapability which describes the data connection capability of modem.
12339 * It's used to evaluate possible phone config change, for example from single
12340 * SIM device to multi-SIM device.
12341 */
12342 @Override
12343 public PhoneCapability getPhoneCapability() {
12344 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012345
12346 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12347 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12348
SongFerngWang8236caa2021-01-17 21:51:44 +080012349 final long identity = Binder.clearCallingIdentity();
12350 try {
12351 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12352 } finally {
12353 Binder.restoreCallingIdentity(identity);
12354 }
12355 }
Michele Berionne5e411512020-11-13 02:36:59 +000012356
12357 /**
12358 * Prepare TelephonyManager for an unattended reboot. The reboot is
12359 * required to be done shortly after the API is invoked.
12360 */
12361 @Override
12362 @TelephonyManager.PrepareUnattendedRebootResult
12363 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012364 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012365 enforceRebootPermission();
12366
joonhunshin4ac60942023-11-15 15:23:39 +000012367 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12368 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12369
Michele Berionne5e411512020-11-13 02:36:59 +000012370 final long identity = Binder.clearCallingIdentity();
12371 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012372 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012373 } finally {
12374 Binder.restoreCallingIdentity(identity);
12375 }
12376 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012377
12378 /**
12379 * Request to get the current slicing configuration including URSP rules and
12380 * NSSAIs (configured, allowed and rejected).
12381 *
12382 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12383 */
12384 @Override
12385 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012386 TelephonyPermissions
12387 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12388 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012389
joonhunshin4ac60942023-11-15 15:23:39 +000012390 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12391 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12392 "getSlicingConfig");
12393
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012394 final long identity = Binder.clearCallingIdentity();
12395 try {
12396 Phone phone = getDefaultPhone();
12397 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12398 } finally {
12399 Binder.restoreCallingIdentity(identity);
12400 }
12401 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012402
12403 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012404 * Check whether the given premium capability is available for purchase from the carrier.
12405 *
12406 * @param capability The premium capability to check.
12407 * @param subId The subId to check the premium capability for.
12408 *
12409 * @return Whether the given premium capability is available to purchase.
12410 */
12411 @Override
12412 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12413 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12414 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12415 log("Premium capability "
12416 + TelephonyManager.convertPremiumCapabilityToString(capability)
12417 + " is not available for purchase due to missing permissions.");
12418 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12419 + "permission READ_BASIC_PHONE_STATE.");
12420 }
12421
joonhunshin4ac60942023-11-15 15:23:39 +000012422 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12423 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12424
Sarah Chin2ec39f62022-08-31 17:03:26 -070012425 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012426 if (phone == null) {
12427 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12428 return false;
12429 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012430 final long identity = Binder.clearCallingIdentity();
12431 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012432 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012433 .isPremiumCapabilityAvailableForPurchase(capability);
12434 } finally {
12435 Binder.restoreCallingIdentity(identity);
12436 }
12437 }
12438
12439 /**
12440 * Purchase the given premium capability from the carrier.
12441 *
12442 * @param capability The premium capability to purchase.
12443 * @param callback The result of the purchase request.
12444 * @param subId The subId to purchase the premium capability for.
12445 */
12446 @Override
12447 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12448 log("purchasePremiumCapability: capability="
12449 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12450 + getCurrentPackageName());
12451
12452 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12453 mApp, "purchasePremiumCapability")) {
12454 log("purchasePremiumCapability "
12455 + TelephonyManager.convertPremiumCapabilityToString(capability)
12456 + " failed due to missing permissions.");
12457 throw new SecurityException("purchasePremiumCapability requires permission "
12458 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012459 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12460 mApp, "purchasePremiumCapability")) {
12461 log("purchasePremiumCapability "
12462 + TelephonyManager.convertPremiumCapabilityToString(capability)
12463 + " failed due to missing permissions.");
12464 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012465 }
12466
joonhunshin4ac60942023-11-15 15:23:39 +000012467 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12468 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12469
Sarah Chin2ec39f62022-08-31 17:03:26 -070012470 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012471 if (phone == null) {
12472 try {
12473 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12474 callback.accept(result);
12475 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12476 } catch (RemoteException e) {
12477 String logStr = "Purchase premium capability "
12478 + TelephonyManager.convertPremiumCapabilityToString(capability)
12479 + " failed due to RemoteException handling null phone: " + e;
12480 if (DBG) log(logStr);
12481 AnomalyReporter.reportAnomaly(
12482 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12483 }
12484 return;
12485 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012486
12487 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012488 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012489 callingProcess = mApp.getPackageManager().getApplicationInfo(
12490 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012491 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012492 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012493 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012494
12495 boolean isVisible = false;
12496 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12497 if (am != null) {
12498 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12499 if (processes != null) {
12500 for (ActivityManager.RunningAppProcessInfo process : processes) {
12501 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012502 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012503 if (process.processName.equals(callingProcess) && process.importance
12504 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12505 isVisible = true;
12506 break;
12507 }
12508 }
12509 }
12510 }
12511
12512 if (!isVisible) {
12513 try {
12514 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12515 callback.accept(result);
12516 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12517 } catch (RemoteException e) {
12518 String logStr = "Purchase premium capability "
12519 + TelephonyManager.convertPremiumCapabilityToString(capability)
12520 + " failed due to RemoteException handling background application: " + e;
12521 if (DBG) log(logStr);
12522 AnomalyReporter.reportAnomaly(
12523 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12524 }
12525 return;
12526 }
12527
Sarah Chin71b3a852022-09-28 15:54:19 -070012528 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012529 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012530 }
12531
12532 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012533 * Register an IMS connection state callback
12534 */
12535 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012536 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12537 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012538 if (feature == ImsFeature.FEATURE_MMTEL) {
12539 // ImsMmTelManager
12540 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12541 TelephonyPermissions
12542 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12543 mApp, subId, "registerImsStateCallback");
12544 } else if (feature == ImsFeature.FEATURE_RCS) {
12545 // ImsRcsManager or SipDelegateManager
12546 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12547 Binder.getCallingUid(), "registerImsStateCallback",
12548 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12549 Manifest.permission.READ_PRECISE_PHONE_STATE,
12550 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12551 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12552 }
12553
12554 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12555 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12556 "IMS not available on device.");
12557 }
12558
12559 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12560 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12561 }
12562
12563 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12564 if (controller == null) {
12565 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12566 "IMS not available on device.");
12567 }
12568
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012569 if (callingPackage == null) {
12570 callingPackage = getCurrentPackageName();
12571 }
12572
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012573 final long token = Binder.clearCallingIdentity();
12574 try {
12575 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012576 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012577 } catch (ImsException e) {
12578 throw new ServiceSpecificException(e.getCode());
12579 } finally {
12580 Binder.restoreCallingIdentity(token);
12581 }
12582 }
12583
12584 /**
12585 * Unregister an IMS connection state callback
12586 */
12587 @Override
12588 public void unregisterImsStateCallback(IImsStateCallback cb) {
12589 final long token = Binder.clearCallingIdentity();
12590 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12591 if (controller == null) {
12592 return;
12593 }
12594 try {
12595 controller.unregisterImsStateCallback(cb);
12596 } finally {
12597 Binder.restoreCallingIdentity(token);
12598 }
12599 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012600
12601 /**
12602 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12603 *
12604 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012605 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012606 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012607 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012608 * If there is current registered network this value will be same as the registered cell
12609 * identity. If the device goes out of service the previous cell identity is cached and
12610 * will be returned. If the cache age of the Cell identity is more than 24 hours
12611 * it will be cleared and null will be returned.
12612 *
12613 */
12614 @Override
12615 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12616 String callingFeatureId) {
12617 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12618 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12619 LocationAccessPolicy.checkLocationPermission(mApp,
12620 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12621 .setCallingPackage(callingPackage)
12622 .setCallingFeatureId(callingFeatureId)
12623 .setCallingPid(Binder.getCallingPid())
12624 .setCallingUid(Binder.getCallingUid())
12625 .setMethod("getLastKnownCellIdentity")
12626 .setLogAsInfo(true)
12627 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12628 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12629 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12630 .build());
12631
12632 boolean hasFinePermission =
12633 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12634 if (!hasFinePermission
12635 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12636 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012637 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012638 }
12639
12640 final long identity = Binder.clearCallingIdentity();
12641 try {
Ling Mac28f0212023-03-24 16:07:15 -070012642 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012643 if (sst == null) return null;
12644 return sst.getLastKnownCellIdentity();
12645 } finally {
12646 Binder.restoreCallingIdentity(identity);
12647 }
12648 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012649
jimsun3b9ccac2021-10-26 15:01:23 +080012650 /**
12651 * Sets the modem service class Name that Telephony will bind to.
12652 *
12653 * @param serviceName The class name of the modem service.
12654 * @return true if the operation is succeed, otherwise false.
12655 */
12656 public boolean setModemService(String serviceName) {
12657 Log.d(LOG_TAG, "setModemService - " + serviceName);
12658 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012660 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12661 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012662 return mPhoneConfigurationManager.setModemService(serviceName);
12663 }
12664
12665 /**
12666 * Return the class name of the currently bounded modem service.
12667 *
12668 * @return the class name of the modem service.
12669 */
12670 public String getModemService() {
12671 String result;
12672 Log.d(LOG_TAG, "getModemService");
12673 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12674 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012675 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012676 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12677 "getModemService");
12678 result = mPhoneConfigurationManager.getModemService();
12679 Log.d(LOG_TAG, "result = " + result);
12680 return result;
12681 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012682
Hakjun Choi3ee81112023-12-19 15:40:58 +000012683 /**
12684 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12685 * including carrier config, entitlement server, and config update.
12686 *
12687 * @param subId subId The subscription ID of the carrier.
12688 *
12689 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12690 * be returned.
12691 *
12692 * @throws SecurityException if the caller doesn't have the required permission.
12693 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012694 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12695 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012696 final long identity = Binder.clearCallingIdentity();
12697 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012698 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012699 } finally {
12700 Binder.restoreCallingIdentity(identity);
12701 }
12702 }
12703
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012704 @Override
12705 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12706 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12707 mApp.enforceCallingOrSelfPermission(
12708 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12709 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12710
12711 final long identity = Binder.clearCallingIdentity();
12712 try {
12713 Phone phone = getPhone(subId);
12714 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012715 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12716 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012717 phone.setVoiceServiceStateOverride(hasService);
12718 } finally {
12719 Binder.restoreCallingIdentity(identity);
12720 }
12721 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012722
12723 /**
12724 * set removable eSIM as default eUICC.
12725 *
12726 * @hide
12727 */
12728 @Override
12729 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12730 enforceModifyPermission();
12731 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12732
12733 final long identity = Binder.clearCallingIdentity();
12734 try {
12735 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12736 } finally {
12737 Binder.restoreCallingIdentity(identity);
12738 }
12739 }
12740
12741 /**
12742 * Returns whether the removable eSIM is default eUICC or not.
12743 *
12744 * @hide
12745 */
12746 @Override
12747 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12748 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12750
12751 final long identity = Binder.clearCallingIdentity();
12752 try {
12753 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12754 } finally {
12755 Binder.restoreCallingIdentity(identity);
12756 }
12757 }
12758
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012759 /**
12760 * Get the component name of the default app to direct respond-via-message intent for the
12761 * user associated with this subscription, update the cache if there is no respond-via-message
12762 * application currently configured for this user.
12763 * @return component name of the app and class to direct Respond Via Message intent to, or
12764 * {@code null} if the functionality is not supported.
12765 * @hide
12766 */
12767 @Override
12768 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12769 boolean updateIfNeeded) {
12770 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012771
joonhunshin4ac60942023-11-15 15:23:39 +000012772 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12773 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12774 "getDefaultRespondViaMessageApplication");
12775
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012776 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12777
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012778 UserHandle userHandle = null;
12779 final long identity = Binder.clearCallingIdentity();
12780 try {
12781 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12782 } finally {
12783 Binder.restoreCallingIdentity(identity);
12784 }
12785 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12786 updateIfNeeded, userHandle);
12787 }
Jack Yuf5badd92022-12-08 00:50:53 -080012788
12789 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012790 * Set whether the device is able to connect with null ciphering or integrity
12791 * algorithms. This is a global setting and will apply to all active subscriptions
12792 * and all new subscriptions after this.
12793 *
12794 * @param enabled when true, null cipher and integrity algorithms are allowed.
12795 * @hide
12796 */
12797 @Override
12798 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12799 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12800 enforceModifyPermission();
12801 checkForNullCipherAndIntegritySupport();
12802
12803 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12804 // for listening to these preference changes and applying them immediately.
12805 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12806 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12807 editor.apply();
12808
12809 for (Phone phone: PhoneFactory.getPhones()) {
12810 phone.handleNullCipherEnabledChange();
12811 }
12812 }
12813
12814
12815 /**
12816 * Get whether the device is able to connect with null ciphering or integrity
12817 * algorithms. Note that this retrieves the phone-global preference and not
12818 * the state of the radio.
12819 *
12820 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12821 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12822 * version for this feature.
12823 * @hide
12824 */
12825 @Override
12826 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12827 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12828 enforceReadPermission();
12829 checkForNullCipherAndIntegritySupport();
12830 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12831 }
12832
12833 private void checkForNullCipherAndIntegritySupport() {
12834 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12835 throw new UnsupportedOperationException(
12836 "Null cipher and integrity operations require HAL 2.1 or above");
12837 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012838 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12839 throw new UnsupportedOperationException(
12840 "Null cipher and integrity operations unsupported by modem");
12841 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012842 }
12843
Gil Cukierman06403e12023-11-29 16:33:03 +000012844 private void checkForIdentifierDisclosureNotificationSupport() {
12845 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12846 throw new UnsupportedOperationException(
12847 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12848 + "above");
12849 }
12850 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12851 throw new UnsupportedOperationException(
12852 "Cellular identifier disclosure transparency operations unsupported by modem");
12853 }
12854 }
12855
Michael Groover826b71d2023-12-21 22:08:06 -060012856 private void checkForNullCipherNotificationSupport() {
12857 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12858 throw new UnsupportedOperationException(
12859 "Null cipher notification operations require HAL 2.2 or above");
12860 }
12861 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12862 throw new UnsupportedOperationException(
12863 "Null cipher notification operations unsupported by modem");
12864 }
12865 }
12866
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012867 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012868 * Get the SIM state for the slot index.
12869 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12870 *
12871 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12872 */
12873 @Override
12874 @SimState
12875 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012876 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12877 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12878
Jack Yuf5badd92022-12-08 00:50:53 -080012879 IccCardConstants.State simState;
12880 if (slotIndex < 0) {
12881 simState = IccCardConstants.State.UNKNOWN;
12882 } else {
12883 Phone phone = null;
12884 try {
12885 phone = PhoneFactory.getPhone(slotIndex);
12886 } catch (IllegalStateException e) {
12887 // ignore
12888 }
12889 if (phone == null) {
12890 simState = IccCardConstants.State.UNKNOWN;
12891 } else {
12892 IccCard icc = phone.getIccCard();
12893 if (icc == null) {
12894 simState = IccCardConstants.State.UNKNOWN;
12895 } else {
12896 simState = icc.getState();
12897 }
12898 }
12899 }
12900 return simState.ordinal();
12901 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012902
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012903 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12904 boolean enableLogcat,
12905 long logcatStartTimestampMillis, boolean enableTelecomDump,
12906 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012907 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012908 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12909 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12910 ecdDataBuilder
12911 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12912 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012913 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012914 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012915 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012916 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12917 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012918 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12919 Executors.newCachedThreadPool(), db,
12920 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012921 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012922 }
12923
12924 /**
12925 * Request telephony to persist state for debugging emergency call failures.
12926 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012927 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012928 * @param enableLogcat whether to collect logcat output
12929 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12930 * @param enableTelecomDump whether to collect telecom dumpsys
12931 * @param enableTelephonyDump whether to collect telephony dumpsys
12932 */
12933 @Override
12934 @RequiresPermission(android.Manifest.permission.DUMP)
12935 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12936 long logcatStartTimestampMillis, boolean enableTelecomDump,
12937 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012938 // Verify that the caller has READ_DROPBOX_DATA permission.
12939 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12940 && Flags.enableReadDropboxPermission()) {
12941 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12942 "persistEmergencyCallDiagnosticData");
12943 } else {
12944 // Otherwise, enforce legacy permission.
12945 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12946 "persistEmergencyCallDiagnosticData");
12947 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012948 final long identity = Binder.clearCallingIdentity();
12949 try {
12950 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12951 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12952
12953 } finally {
12954 Binder.restoreCallingIdentity(identity);
12955 }
12956 }
12957
Hui Wang9b5793a2022-12-05 14:38:06 -060012958 /**
12959 * Get current cell broadcast ranges.
12960 */
12961 @Override
12962 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12963 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12964 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12965 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012966
12967 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12968 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12969
Hui Wang9b5793a2022-12-05 14:38:06 -060012970 final long identity = Binder.clearCallingIdentity();
12971 try {
12972 return getPhone(subId).getCellBroadcastIdRanges();
12973 } finally {
12974 Binder.restoreCallingIdentity(identity);
12975 }
12976 }
12977
12978 /**
12979 * Set reception of cell broadcast messages with the list of the given ranges
12980 *
12981 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12982 */
12983 @Override
12984 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12985 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12986 @Nullable IIntegerConsumer callback) {
12987 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12988 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012989
12990 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12991 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12992
Hui Wang9b5793a2022-12-05 14:38:06 -060012993 final long identity = Binder.clearCallingIdentity();
12994 try {
12995 Phone phone = getPhoneFromSubId(subId);
12996 if (DBG) {
12997 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12998 }
12999 phone.setCellBroadcastIdRanges(ranges, result -> {
13000 if (callback != null) {
13001 try {
13002 callback.accept(result);
13003 } catch (RemoteException e) {
13004 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13005 }
13006 }
13007 });
13008 } finally {
13009 Binder.restoreCallingIdentity(identity);
13010 }
13011 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013012
13013 /**
13014 * Returns whether the device supports the domain selection service.
13015 *
13016 * @return {@code true} if the device supports the domain selection service.
13017 */
13018 @Override
13019 public boolean isDomainSelectionSupported() {
13020 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13021 "isDomainSelectionSupported");
13022
13023 final long identity = Binder.clearCallingIdentity();
13024 try {
13025 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13026 } finally {
13027 Binder.restoreCallingIdentity(identity);
13028 }
13029 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013030
13031 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013032 * Returns whether the AOSP domain selection service is supported.
13033 *
13034 * @return {@code true} if the AOSP domain selection service is supported,
13035 * {@code false} otherwise.
13036 */
13037 @Override
13038 public boolean isAospDomainSelectionService() {
13039 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13040 "isAospDomainSelectionService");
13041
13042 final long identity = Binder.clearCallingIdentity();
13043 try {
13044 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13045 String dssComponentName = mApp.getResources().getString(
13046 R.string.config_domain_selection_service_component_name);
13047 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13048 TelephonyDomainSelectionService.class.getName());
13049 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13050 + ", aosp=" + componentName.flattenToString());
13051 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13052 }
13053 } finally {
13054 Binder.restoreCallingIdentity(identity);
13055 }
13056 return false;
13057 }
13058
13059 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013060 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13061 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13062 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013063 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013064 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013065 * @param enableSatellite {@code true} to enable the satellite modem and
13066 * {@code false} to disable.
13067 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013068 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013069 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013070 *
13071 * @throws SecurityException if the caller doesn't have the required permission.
13072 */
13073 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013074 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013075 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013076 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013077 if (enableSatellite) {
13078 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13079 @Override
13080 protected void onReceiveResult(int resultCode, Bundle resultData) {
13081 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13082 + ", resultData=" + resultData);
13083 boolean isAllowed = false;
13084 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13085 callback::accept);
13086 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13087 if (resultData != null
13088 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13089 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13090 } else {
13091 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13092 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013093 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013094 result.accept(resultCode);
13095 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013096 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013097 if (isAllowed) {
13098 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013099 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013100 } else {
13101 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13102 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013103 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013104 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013105 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013106 subId, resultReceiver);
13107 } else {
13108 // No need to check if satellite is allowed at current location when disabling satellite
13109 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013110 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013111 }
Sarah Chin503828c2023-02-01 23:54:20 -080013112 }
13113
13114 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013115 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013116 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013117 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013118 * @param result The result receiver that returns whether the satellite modem is enabled
13119 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013120 *
13121 * @throws SecurityException if the caller doesn't have the required permission.
13122 */
13123 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013124 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13125 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013126 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013127 }
13128
13129 /**
Sarah Chin43457982023-02-15 17:50:38 -080013130 * Request to get whether the satellite service demo mode is enabled.
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 demo mode is enabled
13135 * 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
Sarah Chinabf081b2023-03-09 23:00:57 -080013140 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13141 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13142 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013143 }
13144
13145 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013146 * Request to get whether the satellite service is enabled with emergency mode.
13147 *
13148 * @param subId The subId of the subscription to check whether the satellite demo mode
13149 * is enabled for.
13150 * @param result The result receiver that returns whether the satellite emergency mode is
13151 * enabled if the request is successful or an error code if the request failed.
13152 *
13153 * @throws SecurityException if the caller doesn't have the required permission.
13154 */
13155 @Override
13156 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13157 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13158 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13159 }
13160
13161 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013162 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013163 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013164 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013165 * @param result The result receiver that returns whether the satellite service is supported on
13166 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013167 */
13168 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013169 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013170 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013171 }
13172
13173 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013174 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013175 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013176 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013177 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13178 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013179 *
13180 * @throws SecurityException if the caller doesn't have required permission.
13181 */
13182 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013183 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13184 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013185 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013186 }
13187
13188 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013189 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013190 * This can be called by the pointing UI when the user starts pointing to the satellite.
13191 * Modem should continue to report the pointing input as the device or satellite moves.
13192 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013193 * @param subId The subId of the subscription to start satellite transmission updates for.
13194 * @param resultCallback The callback to get the result of the request.
13195 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013196 *
13197 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013198 */
13199 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013200 public void startSatelliteTransmissionUpdates(int subId,
13201 @NonNull IIntegerConsumer resultCallback,
13202 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13203 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13204 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013205 }
13206
13207 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013208 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013209 * This can be called by the pointing UI when the user stops pointing to the satellite.
13210 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013211 * @param subId The subId of the subscription to stop satellite transmission updates for.
13212 * @param resultCallback The callback to get the result of the request.
13213 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13214 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013215 *
13216 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013217 */
13218 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013219 public void stopSatelliteTransmissionUpdates(int subId,
13220 @NonNull IIntegerConsumer resultCallback,
13221 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13222 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13223 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013224 }
13225
13226 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013227 * Register the subscription with a satellite provider.
13228 * This is needed to register the subscription if the provider allows dynamic registration.
13229 *
13230 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013231 * @param token The token to be used as a unique identifier for provisioning with satellite
13232 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013233 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013234 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013235 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013236 * @return The signal transport used by the caller to cancel the provision request,
13237 * or {@code null} if the request failed.
13238 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013239 * @throws SecurityException if the caller doesn't have the required permission.
13240 */
13241 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013242 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013243 @NonNull String token, @NonNull byte[] provisionData,
13244 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013245 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013246 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13247 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013248 }
13249
13250 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013251 * Unregister the device/subscription with the satellite provider.
13252 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013253 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013254 * should report as deprovisioned.
13255 *
13256 * @param subId The subId of the subscription to be deprovisioned.
13257 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013258 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013259 *
13260 * @throws SecurityException if the caller doesn't have the required permission.
13261 */
13262 @Override
13263 public void deprovisionSatelliteService(int subId,
13264 @NonNull String token, @NonNull IIntegerConsumer callback) {
13265 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013266 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013267 }
13268
13269 /**
Sarah Chin43457982023-02-15 17:50:38 -080013270 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013271 *
Sarah Chin43457982023-02-15 17:50:38 -080013272 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013273 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013274 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013275 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013276 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013277 * @throws SecurityException if the caller doesn't have the required permission.
13278 */
13279 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013280 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13281 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013282 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013283 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013284 }
13285
13286 /**
Sarah Chin43457982023-02-15 17:50:38 -080013287 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013288 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013289 *
Sarah Chin43457982023-02-15 17:50:38 -080013290 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013291 * @param callback The callback that was passed to
13292 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013293 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013294 * @throws SecurityException if the caller doesn't have the required permission.
13295 */
13296 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013297 public void unregisterForSatelliteProvisionStateChanged(
13298 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013299 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013300 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013301 }
13302
13303 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013304 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013305 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013306 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013307 * @param result The result receiver that returns whether the device is provisioned with a
13308 * satellite provider if the request is successful or an error code if the
13309 * request failed.
13310 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013311 * @throws SecurityException if the caller doesn't have the required permission.
13312 */
13313 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013314 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13315 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013316 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013317 }
13318
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013319 /**
Sarah Chin43457982023-02-15 17:50:38 -080013320 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013321 *
Sarah Chin43457982023-02-15 17:50:38 -080013322 * @param subId The subId of the subscription to register for satellite modem state changed.
13323 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013324 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013325 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013326 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013327 * @throws SecurityException if the caller doesn't have the required permission.
13328 */
13329 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013330 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013331 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013332 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013333 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013334 }
13335
13336 /**
Sarah Chin43457982023-02-15 17:50:38 -080013337 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013338 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013339 *
Sarah Chin43457982023-02-15 17:50:38 -080013340 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013341 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013342 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013343 *
13344 * @throws SecurityException if the caller doesn't have the required permission.
13345 */
13346 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013347 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013348 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013349 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13350 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013351 }
13352
13353 /**
13354 * Register to receive incoming datagrams over satellite.
13355 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013356 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013357 * @param callback The callback to handle incoming datagrams over satellite.
13358 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013359 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013360 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013361 * @throws SecurityException if the caller doesn't have the required permission.
13362 */
13363 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013364 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013365 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013366 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13367 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013368 }
13369
13370 /**
13371 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013372 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013373 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013374 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13375 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013376 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013377 *
13378 * @throws SecurityException if the caller doesn't have the required permission.
13379 */
13380 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013381 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013382 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013383 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13384 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013385 }
13386
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013387 /**
13388 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013389 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013390 * This method requests modem to check if there are any pending datagrams to be received over
13391 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013392 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013393 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013394 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013395 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013396 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013397 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013398 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013399 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13400 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13401 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013402 }
13403
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013404 /**
13405 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013406 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013407 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13408 * input to this method. Datagram received here will be passed down to modem without any
13409 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013410 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013411 * @param subId The subId of the subscription to send satellite datagrams for.
13412 * @param datagramType datagram type indicating whether the datagram is of type
13413 * SOS_SMS or LOCATION_SHARING.
13414 * @param datagram encoded gateway datagram which is encrypted by the caller.
13415 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013416 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13417 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013418 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013419 *
13420 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013421 */
13422 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013423 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013424 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13425 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013426 enforceSatelliteCommunicationPermission("sendDatagram");
13427 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13428 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013429 }
13430
Sarah Chindf715ec2023-02-13 13:46:24 -080013431 /**
13432 * Request to get whether satellite communication is allowed for the current location.
13433 *
13434 * @param subId The subId of the subscription to check whether satellite communication is
13435 * allowed for the current location for.
13436 * @param result The result receiver that returns whether satellite communication is allowed
13437 * for the current location if the request is successful or an error code
13438 * if the request failed.
13439 *
13440 * @throws SecurityException if the caller doesn't have the required permission.
13441 */
13442 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013443 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013444 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013445 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13446 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13447 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013448 }
13449
13450 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013451 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013452 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013453 * @param subId The subId to get the time after which the satellite will be visible for.
13454 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013455 * be visible if the request is successful or an error code if the request failed.
13456 *
13457 * @throws SecurityException if the caller doesn't have the required permission.
13458 */
13459 @Override
13460 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13461 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013462 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013463 }
13464
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013465 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013466 * Inform that Device is aligned to satellite for demo mode.
13467 *
13468 * @param subId The subId to get the time after which the satellite will be visible for.
13469 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13470 * {@code false} Device fails to align with the satellite for demo mode.
13471 *
13472 * @throws SecurityException if the caller doesn't have required permission.
13473 */
13474 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13475
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013476 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013477 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013478 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013479 }
13480
13481 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013482 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13483 * by modem.
13484 *
13485 * @param subId The subId of the subscription to request for.
13486 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013487 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013488 * operation.
13489 *
13490 * @throws SecurityException if the caller doesn't have required permission.
13491 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013492 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013493 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13494 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013495 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013496 final long identity = Binder.clearCallingIdentity();
13497 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013498 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013499 } finally {
13500 Binder.restoreCallingIdentity(identity);
13501 }
13502 }
13503
13504 /**
13505 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13506 * by modem.
13507 *
13508 * @param subId The subId of the subscription to request for.
13509 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013510 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013511 * operation.
13512 *
13513 * @throws SecurityException if the caller doesn't have required permission.
13514 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013515 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013516 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13517 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013518 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013519 final long identity = Binder.clearCallingIdentity();
13520 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013521 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013522 } finally {
13523 Binder.restoreCallingIdentity(identity);
13524 }
13525 }
13526
13527 /**
13528 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013529 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013530 *
13531 * @param subId The subId of the subscription to request for.
13532 *
13533 * @return Integer array of reasons for disallowing satellite communication.
13534 *
13535 * @throws SecurityException if the caller doesn't have the required permission.
13536 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013537 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013538 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013539 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013540 final long identity = Binder.clearCallingIdentity();
13541 try {
13542 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013543 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013544 return reasonSet.stream().mapToInt(i->i).toArray();
13545 } finally {
13546 Binder.restoreCallingIdentity(identity);
13547 }
13548 }
13549
13550 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013551 * Request to get the signal strength of the satellite connection.
13552 *
13553 * @param subId The subId of the subscription to request for.
13554 * @param result Result receiver to get the error code of the request and the current signal
13555 * strength of the satellite connection.
13556 *
13557 * @throws SecurityException if the caller doesn't have required permission.
13558 */
13559 @Override
13560 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13561 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13562 final long identity = Binder.clearCallingIdentity();
13563 try {
13564 mSatelliteController.requestNtnSignalStrength(subId, result);
13565 } finally {
13566 Binder.restoreCallingIdentity(identity);
13567 }
13568 }
13569
13570 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013571 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13572 * is not successful, a {@link ServiceSpecificException} that contains
13573 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013574 *
13575 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013576 * @param callback The callback to handle the NTN signal strength changed event. If the
13577 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13578 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13579 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13580 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013581 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013582 * @throws SecurityException If the caller doesn't have the required permission.
13583 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013584 */
13585 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013586 public void registerForNtnSignalStrengthChanged(int subId,
13587 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013588 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13589 final long identity = Binder.clearCallingIdentity();
13590 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013591 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013592 } finally {
13593 Binder.restoreCallingIdentity(identity);
13594 }
13595 }
13596
13597 /**
13598 * Unregisters for NTN signal strength changed from satellite modem.
13599 * If callback was not registered before, the request will be ignored.
13600 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013601 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13602 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013603 * @param callback The callback that was passed to
13604 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13605 *
13606 * @throws SecurityException if the caller doesn't have the required permission.
13607 */
13608 @Override
13609 public void unregisterForNtnSignalStrengthChanged(
13610 int subId, @NonNull INtnSignalStrengthCallback callback) {
13611 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13612 final long identity = Binder.clearCallingIdentity();
13613 try {
13614 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13615 } finally {
13616 Binder.restoreCallingIdentity(identity);
13617 }
13618 }
13619
13620 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013621 * Registers for satellite capabilities change event from the satellite service.
13622 *
13623 * @param subId The subId of the subscription to request for.
13624 * @param callback The callback to handle the satellite capabilities changed event.
13625 *
13626 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13627 *
13628 * @throws SecurityException if the caller doesn't have required permission.
13629 */
13630 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013631 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013632 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013633 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013634 final long identity = Binder.clearCallingIdentity();
13635 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013636 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013637 } finally {
13638 Binder.restoreCallingIdentity(identity);
13639 }
13640 }
13641
13642 /**
13643 * Unregisters for satellite capabilities change event from the satellite service.
13644 * If callback was not registered before, the request will be ignored.
13645 *
13646 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13647 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013648 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013649 *
13650 * @throws SecurityException if the caller doesn't have required permission.
13651 */
13652 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013653 public void unregisterForCapabilitiesChanged(int subId,
13654 @NonNull ISatelliteCapabilitiesCallback callback) {
13655 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013656 final long identity = Binder.clearCallingIdentity();
13657 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013658 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013659 } finally {
13660 Binder.restoreCallingIdentity(identity);
13661 }
13662 }
13663
13664 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013665 * Registers for the satellite supported state changed.
13666 *
13667 * @param subId The subId of the subscription to register for supported state changed.
13668 * @param callback The callback to handle the satellite supported state changed event.
13669 *
13670 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13671 *
13672 * @throws SecurityException if the caller doesn't have the required permission.
13673 */
13674 @Override
13675 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13676 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13677 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13678 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13679 }
13680
13681 /**
13682 * Unregisters for the satellite supported state changed.
13683 * If callback was not registered before, the request will be ignored.
13684 *
13685 * @param subId The subId of the subscription to unregister for supported state changed.
13686 * @param callback The callback that was passed to
13687 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13688 *
13689 * @throws SecurityException if the caller doesn't have the required permission.
13690 */
13691 @Override
13692 public void unregisterForSatelliteSupportedStateChanged(
13693 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13694 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13695 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13696 }
13697
13698 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013699 * This API can be used by only CTS to update satellite vendor service package name.
13700 *
13701 * @param servicePackageName The package name of the satellite vendor service.
13702 * @return {@code true} if the satellite vendor service is set successfully,
13703 * {@code false} otherwise.
13704 */
13705 public boolean setSatelliteServicePackageName(String servicePackageName) {
13706 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13707 TelephonyPermissions.enforceShellOnly(
13708 Binder.getCallingUid(), "setSatelliteServicePackageName");
13709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13710 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13711 "setSatelliteServicePackageName");
13712 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13713 }
13714
13715 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013716 * This API can be used by only CTS to update satellite gateway service package name.
13717 *
13718 * @param servicePackageName The package name of the satellite gateway service.
13719 * @return {@code true} if the satellite gateway service is set successfully,
13720 * {@code false} otherwise.
13721 */
13722 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13723 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13724 TelephonyPermissions.enforceShellOnly(
13725 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13727 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13728 "setSatelliteGatewayServicePackageName");
13729 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13730 }
13731
13732 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013733 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13734 *
13735 * @param packageName The package name of the satellite pointing UI app.
13736 * @param className The class name of the satellite pointing UI app.
13737 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13738 * {@code false} otherwise.
13739 */
13740 public boolean setSatellitePointingUiClassName(
13741 @Nullable String packageName, @Nullable String className) {
13742 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13743 + ", className=" + className);
13744 TelephonyPermissions.enforceShellOnly(
13745 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13747 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13748 "setSatelliteGatewayServicePackageName");
13749 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13750 }
13751
13752 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013753 * This API can be used by only CTS to update the timeout duration in milliseconds that
13754 * satellite should stay at listening mode to wait for the next incoming page before disabling
13755 * listening mode.
13756 *
13757 * @param timeoutMillis The timeout duration in millisecond.
13758 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13759 */
13760 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13761 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13762 TelephonyPermissions.enforceShellOnly(
13763 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13765 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13766 "setSatelliteListeningTimeoutDuration");
13767 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13768 }
13769
13770 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013771 * This API can be used by only CTS to override the timeout durations used by the
13772 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013773 *
13774 * @param timeoutMillis The timeout duration in millisecond.
13775 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13776 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013777 public boolean setDatagramControllerTimeoutDuration(
13778 boolean reset, int timeoutType, long timeoutMillis) {
13779 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13780 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013781 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013782 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13784 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013785 "setDatagramControllerTimeoutDuration");
13786 return mSatelliteController.setDatagramControllerTimeoutDuration(
13787 reset, timeoutType, timeoutMillis);
13788 }
13789
13790 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013791 * This API can be used by only CTS to override the boolean configs used by the
13792 * DatagramController module.
13793 *
13794 * @param enable Whether to enable or disable boolean config.
13795 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13796 */
13797 public boolean setDatagramControllerBooleanConfig(
13798 boolean reset, int booleanType, boolean enable) {
13799 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13800 + ", reset=" + reset + ", enable=" + enable);
13801 TelephonyPermissions.enforceShellOnly(
13802 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13804 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13805 "ssetDatagramControllerBooleanConfig");
13806 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13807 }
13808
13809
13810 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013811 * This API can be used by only CTS to override the timeout durations used by the
13812 * SatelliteController module.
13813 *
13814 * @param timeoutMillis The timeout duration in millisecond.
13815 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13816 */
13817 public boolean setSatelliteControllerTimeoutDuration(
13818 boolean reset, int timeoutType, long timeoutMillis) {
13819 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13820 + reset + ", timeoutMillis=" + timeoutMillis);
13821 TelephonyPermissions.enforceShellOnly(
13822 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13824 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13825 "setSatelliteControllerTimeoutDuration");
13826 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13827 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013828 }
13829
13830 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013831 * This API can be used in only testing to override connectivity status in monitoring emergency
13832 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13833 *
13834 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13835 * of the following values to enable the override:
13836 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13837 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13838 * To disable the override, use -1 for handoverType.
13839 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13840 * delaySeconds after the emergency call starts.
13841 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13842 */
13843 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13844 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13845 TelephonyPermissions.enforceShellOnly(
13846 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13848 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13849 "setEmergencyCallToSatelliteHandoverType");
13850 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13851 handoverType, delaySeconds);
13852 }
13853
13854 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013855 * This API can be used in only testing to override oem-enabled satellite provision status.
13856 *
13857 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13858 * otherwise.
13859 * @param isProvisioned The overriding provision status.
13860 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13861 */
13862 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13863 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13864 + ", isProvisioned=" + isProvisioned);
13865 TelephonyPermissions.enforceShellOnly(
13866 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13868 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13869 "setOemEnabledSatelliteProvisionStatus");
13870 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13871 }
13872
13873 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013874 * This API should be used by only CTS tests to forcefully set telephony country codes.
13875 *
13876 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13877 */
13878 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13879 Map cachedNetworkCountryCodes, String locationCountryCode,
13880 long locationCountryCodeTimestampNanos) {
13881 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13882 + String.join(", ", currentNetworkCountryCodes)
13883 + ", locationCountryCode=" + locationCountryCode
13884 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13885 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13886 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13887 TelephonyPermissions.enforceShellOnly(
13888 Binder.getCallingUid(), "setCachedLocationCountryCode");
13889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13890 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13891 "setCachedLocationCountryCode");
13892 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13893 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13894 locationCountryCodeTimestampNanos);
13895 }
13896
13897 /**
13898 * This API should be used by only CTS tests to override the overlay configs of satellite
13899 * access controller.
13900 *
13901 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13902 * otherwise.
13903 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13904 */
13905 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13906 String s2CellFile, long locationFreshDurationNanos,
13907 List<String> satelliteCountryCodes) {
13908 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13909 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13910 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13911 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13912 ? String.join(", ", satelliteCountryCodes) : null));
13913 TelephonyPermissions.enforceShellOnly(
13914 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13916 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13917 "setSatelliteAccessControlOverlayConfigs");
13918 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13919 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13920 }
13921
13922 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013923 * This API can be used by only CTS to override the cached value for the device overlay config
13924 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13925 * outgoing satellite datagrams should be sent to modem in demo mode.
13926 *
13927 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13928 * satellite modem or not.
13929 *
13930 * @return {@code true} if the operation is successful, {@code false} otherwise.
13931 */
13932 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13933 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13934 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13935 + "disabled");
13936 return false;
13937 }
13938 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13939 TelephonyPermissions.enforceShellOnly(
13940 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13942 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13943 "setShouldSendDatagramToModemInDemoMode");
13944 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13945 shouldSendToModemInDemoMode);
13946 }
13947
13948 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000013949 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
13950 *
13951 * @param state a state indicates whether satellite access allowed state should be cached and
13952 * the allowed state.
13953 * @return {@code true} if the setting is successful, {@code false} otherwise.
13954 */
13955 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
13956 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13957 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13958 + "oemEnabledSatelliteFlag is disabled");
13959 return false;
13960 }
13961
13962 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13963 + "state=" + state);
13964 TelephonyPermissions.enforceShellOnly(
13965 Binder.getCallingUid(),
13966 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
13967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13968 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13969 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
13970 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
13971 state);
13972 }
13973
13974 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013975 * Sets the service defined in ComponentName to be bound.
13976 *
13977 * This should only be used for testing.
13978 * @return {@code true} if the DomainSelectionService to bind to was set,
13979 * {@code false} otherwise.
13980 */
13981 @Override
13982 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13983 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13984
13985 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13986 "setDomainSelectionServiceOverride");
13987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13988 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13989
13990 final long identity = Binder.clearCallingIdentity();
13991 try {
13992 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13993 return DomainSelectionResolver.getInstance()
13994 .setDomainSelectionServiceOverride(componentName);
13995 }
13996 } finally {
13997 Binder.restoreCallingIdentity(identity);
13998 }
13999 return false;
14000 }
14001
14002 /**
14003 * Clears the DomainSelectionService override.
14004 *
14005 * This should only be used for testing.
14006 * @return {@code true} if the DomainSelectionService override was cleared,
14007 * {@code false} otherwise.
14008 */
14009 @Override
14010 public boolean clearDomainSelectionServiceOverride() {
14011 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14012
14013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14014 "clearDomainSelectionServiceOverride");
14015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14016 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14017
14018 final long identity = Binder.clearCallingIdentity();
14019 try {
14020 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14021 return DomainSelectionResolver.getInstance()
14022 .clearDomainSelectionServiceOverride();
14023 }
14024 } finally {
14025 Binder.restoreCallingIdentity(identity);
14026 }
14027 return false;
14028 }
14029
14030 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014031 * Enable or disable notifications sent for cellular identifier disclosure events.
14032 *
14033 * Disclosure events are defined as instances where a device has sent a cellular identifier
14034 * on the Non-access stratum (NAS) before a security context is established. As a result the
14035 * identifier is sent in the clear, which has privacy implications for the user.
14036 *
14037 * @param enable if notifications about disclosure events should be enabled
14038 * @throws SecurityException if the caller does not have the required privileges
14039 * @throws UnsupportedOperationException if the modem does not support this feature.
14040 */
14041 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014042 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014043 enforceModifyPermission();
14044 checkForIdentifierDisclosureNotificationSupport();
14045
14046 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14047 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14048 editor.apply();
14049
14050 // Each phone instance is responsible for updating its respective modem immediately
14051 // after we've made a preference change.
14052 for (Phone phone : PhoneFactory.getPhones()) {
14053 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14054 }
14055 }
14056
14057 /**
14058 * Get whether or not cellular identifier disclosure notifications are enabled.
14059 *
14060 * @throws SecurityException if the caller does not have the required privileges
14061 * @throws UnsupportedOperationException if the modem does not support this feature.
14062 */
14063 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014064 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014065 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14066 checkForIdentifierDisclosureNotificationSupport();
14067 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14068 }
14069
14070 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014071 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14072 * are in use by the cellular modem.
14073 *
14074 * @throws IllegalStateException if the Telephony process is not currently available
14075 * @throws SecurityException if the caller does not have the required privileges
14076 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14077 * and integrity algorithms in use
14078 * @hide
14079 */
14080 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014081 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014082 enforceModifyPermission();
14083 checkForNullCipherNotificationSupport();
14084
14085 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14086 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14087 editor.apply();
14088
14089 // Each phone instance is responsible for updating its respective modem immediately
14090 // after a preference change.
14091 for (Phone phone : PhoneFactory.getPhones()) {
14092 phone.handleNullCipherNotificationPreferenceChanged();
14093 }
14094 }
14095
14096 /**
14097 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14098 * cellular modem.
14099 *
14100 * @throws IllegalStateException if the Telephony process is not currently available
14101 * @throws SecurityException if the caller does not have the required privileges
14102 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14103 * and integrity algorithms in use
14104 * @hide
14105 */
14106 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14107 public boolean isNullCipherNotificationsEnabled() {
14108 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14109 checkForNullCipherNotificationSupport();
14110 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14111 }
14112
14113 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014114 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14115 *
14116 * <p>This method behaves in one of the following ways:
14117 * <ul>
14118 * <li>return true : if the calling package has the appop permission {@link
14119 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14120 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14121 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14122 * Owner device identifier access check, or the calling package has carrier privileges</>
14123 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14124 * </ul>
14125 */
14126 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14127 String callingPackage, @Nullable String callingFeatureId, String message) {
14128 for (Phone phone : PhoneFactory.getPhones()) {
14129 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14130 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14131 return true;
14132 }
14133 }
14134 return false;
14135 }
arunvoddud7401012022-12-15 16:08:12 +000014136
14137 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014138 * @return The subscription manager service instance.
14139 */
14140 public SubscriptionManagerService getSubscriptionManagerService() {
14141 return SubscriptionManagerService.getInstance();
14142 }
14143
14144 /**
arunvoddud7401012022-12-15 16:08:12 +000014145 * Class binds the consumer[callback] and carrierId.
14146 */
14147 private static class CallerCallbackInfo {
14148 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014149 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014150
Steve Statia28b7cb32024-03-11 23:58:50 +000014151 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014152 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014153 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014154 }
14155
14156 public Consumer<Integer> getConsumer() {
14157 return mConsumer;
14158 }
14159
Steve Statia28b7cb32024-03-11 23:58:50 +000014160 public Set<Integer> getCarrierIds() {
14161 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014162 }
14163 }
joonhunshin4ac60942023-11-15 15:23:39 +000014164
14165 /*
14166 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14167 * But the context that is passed in is unused if the phone app is already alive.
14168 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14169 */
14170 @VisibleForTesting
14171 public void setPackageManager(PackageManager packageManager) {
14172 mPackageManager = packageManager;
14173 }
14174
14175 /*
Nate Myren453c3472024-03-13 11:28:11 -070014176 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14177 * But the context that is passed in is unused if the phone app is already alive.
14178 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14179 */
14180 @VisibleForTesting
14181 public void setAppOpsManager(AppOpsManager appOps) {
14182 mAppOps = appOps;
14183 }
14184
14185 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014186 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14187 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14188 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14189 */
14190 @VisibleForTesting
14191 public void setFeatureFlags(FeatureFlags featureFlags) {
14192 mFeatureFlags = featureFlags;
14193 }
14194
14195 /**
14196 * Make sure the device has required telephony feature
14197 *
14198 * @throws UnsupportedOperationException if the device does not have required telephony feature
14199 */
14200 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14201 @NonNull String telephonyFeature, @NonNull String methodName) {
14202 if (callingPackage == null || mPackageManager == null) {
14203 return;
14204 }
14205
14206 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14207 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014208 Binder.getCallingUserHandle())
14209 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14210 // Skip to check associated telephony feature,
14211 // if compatibility change is not enabled for the current process or
14212 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014213 return;
14214 }
14215
14216 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14217 throw new UnsupportedOperationException(
14218 methodName + " is unsupported without " + telephonyFeature);
14219 }
14220 }
youngtaecha5d483d52024-04-29 17:05:45 +000014221
14222 /**
14223 * Registers for the satellite communication allowed state changed.
14224 *
14225 * @param subId The subId of the subscription to register for the satellite communication
14226 * allowed state changed.
14227 * @param callback The callback to handle the satellite communication allowed
14228 * state changed event.
14229 *
14230 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14231 *
14232 * @throws SecurityException if the caller doesn't have the required permission.
14233 */
14234 @Override
14235 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14236 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14237 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14238 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14239 subId, callback);
14240 }
14241
14242 /**
14243 * Unregisters for the satellite communication allowed state changed.
14244 * If callback was not registered before, the request will be ignored.
14245 *
14246 * @param subId The subId of the subscription to unregister for the satellite communication
14247 * allowed state changed.
14248 * @param callback The callback that was passed to
14249 * {@link #registerForCommunicationAllowedStateChanged(int,
14250 * ISatelliteCommunicationAllowedStateCallback)}. *
14251 * @throws SecurityException if the caller doesn't have the required permission.
14252 */
14253 @Override
14254 public void unregisterForCommunicationAllowedStateChanged(
14255 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14256 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14257 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14258 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014259
14260 /**
14261 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14262 *
14263 * @param subId The subId of the subscription to the satellite session stats for.
14264 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14265 * if the request is successful or an error code if the request failed.
14266 *
14267 * @throws SecurityException if the caller doesn't have required permission.
14268 */
14269 @Override
14270 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14271 enforceModifyPermission();
14272 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
14273 mSatelliteController.requestSatelliteSessionStats(subId, result);
14274 }
Jack Yufa8ed012023-02-11 15:42:28 -080014275}