blob: 4bd6be0557beaa1d724a8b33bb7bf77e10c063cd [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
joonhunshin4ac60942023-11-15 15:23:39 +000019import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS;
20import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION;
Hall Liud892bec2018-11-30 14:51:45 -080021import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Nate Myrenae97d192023-06-09 15:22:31 -070022import static android.permission.flags.Flags.opEnableMobileDataByUser;
joonhunshin4ac60942023-11-15 15:23:39 +000023import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000024import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080025import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080026import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED;
27import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED;
Thomas Nguyena8062672024-02-05 14:18:19 -080028import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080029import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
Hall Liud892bec2018-11-30 14:51:45 -080030
Shuo Qianccbaf742021-02-22 18:32:21 -080031import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
32import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070033import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070034import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000035import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070036
Brad Ebinger34c09a52021-02-17 23:23:21 +000037import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080038import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080039import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070040import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000041import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080042import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080044import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070045import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000046import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080047import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000048import android.compat.annotation.ChangeId;
49import android.compat.annotation.EnabledSince;
Anthony Alridge70ba5572023-05-02 12:14:14 +000050import android.content.ActivityNotFoundException;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070051import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070052import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.content.Context;
54import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070055import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070056import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070057import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.net.Uri;
59import android.os.AsyncResult;
60import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080061import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import android.os.Bundle;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080063import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070065import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080066import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080067import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.os.Looper;
69import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070070import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080071import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070072import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080074import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080075import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070076import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070077import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080078import android.os.SystemClock;
joonhunshinf624b2a2024-04-18 04:42:12 +000079import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070081import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070083import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070084import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080085import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070086import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000087import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090088import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080089import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080090import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070091import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080092import android.telephony.AccessNetworkConstants;
93import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070094import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070095import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080096import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070097import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080098import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070099import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -0800100import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -0600101import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -0700102import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -0800103import android.telephony.CellIdentityCdma;
104import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -0700106import android.telephony.CellInfoGsm;
107import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700108import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800109import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700110import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700111import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700112import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800113import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700114import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800115import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700116import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800117import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800118import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700119import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800120import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800122import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800123import android.telephony.SignalStrengthUpdateRequest;
124import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800125import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800127import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700128import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700129import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800130import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800131import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800132import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800133import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000134import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000135import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000136import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700137import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700138import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800139import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800140import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700141import android.telephony.gba.GbaAuthRequest;
142import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700143import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800144import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000145import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000146import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700147import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000148import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700149import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800150import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700151import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800152import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700153import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000154import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700155import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800156import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800157import android.telephony.ims.stub.ImsRegistrationImplBase;
Hakjun Choifa3e6172023-09-22 03:56:34 +0000158import android.telephony.satellite.INtnSignalStrengthCallback;
Hakjun Choi8d96a562023-10-26 15:01:40 +0000159import android.telephony.satellite.ISatelliteCapabilitiesCallback;
youngtaecha5d483d52024-04-29 17:05:45 +0000160import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800161import android.telephony.satellite.ISatelliteDatagramCallback;
Hakjun Choid4a52a22023-12-13 09:48:24 +0000162import android.telephony.satellite.ISatelliteModemStateCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800163import android.telephony.satellite.ISatelliteProvisionStateCallback;
Hakjun Choif92ac752024-03-18 19:34:29 +0000164import android.telephony.satellite.ISatelliteSupportedStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800165import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Hakjun Choi4c3668a2023-12-05 11:55:36 +0000166import android.telephony.satellite.NtnSignalStrength;
167import android.telephony.satellite.NtnSignalStrengthCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800168import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000169import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800170import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800171import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800172import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700175import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800177import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800178
Andrew Lee312e8172014-10-23 17:01:36 -0700179import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800180import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800181import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800182import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800183import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700185import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700186import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800187import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800188import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700189import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700190import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800191import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700192import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800193import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800194import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000197import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700198import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800199import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800201import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800202import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800203import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700204import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700205import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700206import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700208import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800209import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700210import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700211import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700212import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700213import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800214import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800215import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700216import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000217import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700218import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700219import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800220import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800221import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800222import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700223import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000224import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800225import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700226import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700227import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800228import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700229import com.android.internal.telephony.imsphone.ImsPhone;
230import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000231import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800232import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000233import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800234import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
235import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700236import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700237import com.android.internal.telephony.uicc.IccIoResult;
238import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700240import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800241import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000243import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800244import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000245import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800246import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000247import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700248import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700249import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800250import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800251import com.android.phone.callcomposer.CallComposerPictureManager;
252import com.android.phone.callcomposer.CallComposerPictureTransfer;
253import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800254import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000255import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700256import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700257import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000258import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700259import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800260import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700261import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700262import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800263import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800264import com.android.services.telephony.TelecomAccountRegistry;
265import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000266import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800267import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800268
Hall Liu82694d52020-12-11 18:22:04 -0800269import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700270import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800271import java.io.IOException;
272import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700273import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800275import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000276import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800277import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800278import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800279import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800280import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100281import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800282import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700283import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800284import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800285import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700286import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800287import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800288import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800289import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
291/**
292 * Implementation of the ITelephony interface.
293 */
Santos Cordon117fee72014-05-16 17:56:12 -0700294public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 private static final String LOG_TAG = "PhoneInterfaceManager";
296 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
297 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800298 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299
300 // Message codes used with mMainThreadHandler
301 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700302 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
303 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700304 private static final int CMD_OPEN_CHANNEL = 9;
305 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
306 private static final int CMD_CLOSE_CHANNEL = 11;
307 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800308 private static final int CMD_NV_READ_ITEM = 13;
309 private static final int EVENT_NV_READ_ITEM_DONE = 14;
310 private static final int CMD_NV_WRITE_ITEM = 15;
311 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
312 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
313 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700314 private static final int CMD_RESET_MODEM_CONFIG = 19;
315 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800316 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
317 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800318 private static final int CMD_SEND_ENVELOPE = 25;
319 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700320 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
321 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
322 private static final int CMD_EXCHANGE_SIM_IO = 31;
323 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800324 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
325 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700326 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
327 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700328 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
329 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700330 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
331 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
332 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
333 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700334 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
335 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
336 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
337 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700338 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800339 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
340 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000341 private static final int CMD_SWITCH_SLOTS = 50;
342 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700343 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
344 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
345 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
346 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
347 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
348 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
349 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
350 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700351 private static final int CMD_GET_ALL_CELL_INFO = 60;
352 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
353 private static final int CMD_GET_CELL_LOCATION = 62;
354 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700355 private static final int CMD_MODEM_REBOOT = 64;
356 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700357 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
358 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800359 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
360 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700361 private static final int CMD_GET_MODEM_STATUS = 70;
362 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700363 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
364 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700365 private static final int CMD_ERASE_MODEM_CONFIG = 74;
366 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800367 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
368 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
369 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
370 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800371 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
372 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800374 private static final int CMD_GET_CALL_FORWARDING = 83;
375 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
376 private static final int CMD_SET_CALL_FORWARDING = 85;
377 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
378 private static final int CMD_GET_CALL_WAITING = 87;
379 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
380 private static final int CMD_SET_CALL_WAITING = 89;
381 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700382 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
383 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
384 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
385 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700386 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
387 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800388 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
389 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800390 private static final int CMD_SET_DATA_THROTTLING = 99;
391 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800392 private static final int CMD_SET_SIM_POWER = 101;
393 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800394 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
395 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
396 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
397 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800398 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
399 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000400 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800401 private static final int CMD_GET_SLICING_CONFIG = 110;
402 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800403 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700404 private static final int CMD_ENABLE_VONR = 113;
405 private static final int EVENT_ENABLE_VONR_DONE = 114;
406 private static final int CMD_IS_VONR_ENABLED = 115;
407 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700408 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
409 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000410
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800411 // Parameters of select command.
412 private static final int SELECT_COMMAND = 0xA4;
413 private static final int SELECT_P1 = 0x04;
414 private static final int SELECT_P2 = 0;
415 private static final int SELECT_P3 = 0x10;
416
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000417 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
418 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000419 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
420 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600421 // Null cipher notification support was added in IRadioNetwork 2.2
422 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 /** The singleton instance. */
425 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800426 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427
Sarah Chin4beb2b72023-02-14 14:47:54 -0800428 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000429 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800430 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800431 private final CallManager mCM;
432 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000433
434 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800435 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800436 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800437 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final SharedPreferences mTelephonySharedPreferences;
439 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800440 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700441 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000442 private PackageManager mPackageManager;
joonhunshinf624b2a2024-04-18 04:42:12 +0000443 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Peter Wangdafb9ac2020-01-15 14:13:38 -0800445 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800446 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800447 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800448 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800449
Derek Tan97ebb422014-09-05 16:55:38 -0700450 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
451 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800452 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800453 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700454
Michelecea4cf22018-12-21 15:00:11 -0800455 // String to store multi SIM allowed
456 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
457
Derek Tan740e1672017-06-27 14:56:27 -0700458 // The AID of ISD-R.
459 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
460
yinxub1bed742017-04-17 11:45:04 -0700461 private NetworkScanRequestTracker mNetworkScanRequestTracker;
462
David Kelly5e06a7f2018-03-12 14:10:59 +0000463 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
464 private static final int MANUFACTURER_CODE_LENGTH = 8;
465
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800466 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800467 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800468
Sarah Chin2ec39f62022-08-31 17:03:26 -0700469 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
470 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
471
Derek Tan89e89d42014-07-08 17:00:10 -0700472 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700473 * Experiment flag to enable erase modem config on reset network, default value is false
474 */
475 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
476 "reset_network_erase_modem_config_enabled";
477
Rambo Wang0f050d82021-02-12 11:43:36 -0800478 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800479
Gary Jian76280a42022-12-07 16:18:33 +0800480 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
481
sandeepjsb6c87872021-09-27 15:34:44 +0000482 /**
483 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
484 * one ICCID active at the same time.
485 * Apps should use below API signatures if targeting SDK is T and beyond.
486 *
487 * @hide
488 */
489 @ChangeId
490 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
491 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800492
Naina Nallurid63128d2019-09-17 14:10:30 -0700493 /**
Chen Xu540470b2021-12-14 17:15:47 -0800494 * Apps targeting on Android T and beyond will get exception whenever icc close channel
495 * operation fails.
496 */
497 @ChangeId
498 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
499 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
500
501 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700502 * A request object to use for transmitting data to an ICC.
503 */
504 private static final class IccAPDUArgument {
505 public int channel, cla, command, p1, p2, p3;
506 public String data;
507
508 public IccAPDUArgument(int channel, int cla, int command,
509 int p1, int p2, int p3, String data) {
510 this.channel = channel;
511 this.cla = cla;
512 this.command = command;
513 this.p1 = p1;
514 this.p2 = p2;
515 this.p3 = p3;
516 this.data = data;
517 }
518 }
519
520 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700521 * A request object to use for transmitting data to an ICC.
522 */
523 private static final class ManualNetworkSelectionArgument {
524 public OperatorInfo operatorInfo;
525 public boolean persistSelection;
526
527 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
528 this.operatorInfo = operatorInfo;
529 this.persistSelection = persistSelection;
530 }
531 }
532
Sarah Chin71b3a852022-09-28 15:54:19 -0700533 private static final class PurchasePremiumCapabilityArgument {
534 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700535 public @NonNull IIntegerConsumer callback;
536
537 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800538 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700539 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700540 this.callback = callback;
541 }
542 }
543
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700544 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
546 * request after sending. The main thread will notify the request when it is complete.
547 */
548 private static final class MainThreadRequest {
549 /** The argument to use for the request */
550 public Object argument;
551 /** The result of the request that is run on the main thread */
552 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800553 // The subscriber id that this request applies to. Defaults to
554 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
555 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556
Nathan Harold92bed182018-10-12 18:16:49 -0700557 // In cases where subId is unavailable, the caller needs to specify the phone.
558 public Phone phone;
559
vagdeviaf9a5b92018-08-15 16:01:53 -0700560 public WorkSource workSource;
561
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700562 public MainThreadRequest(Object argument) {
563 this.argument = argument;
564 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800565
Nathan Harold92bed182018-10-12 18:16:49 -0700566 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
567 this.argument = argument;
568 if (phone != null) {
569 this.phone = phone;
570 }
571 this.workSource = workSource;
572 }
573
vagdeviaf9a5b92018-08-15 16:01:53 -0700574 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800575 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800576 if (subId != null) {
577 this.subId = subId;
578 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700579 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 }
582
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800583 private static final class IncomingThirdPartyCallArgs {
584 public final ComponentName component;
585 public final String callId;
586 public final String callerDisplayName;
587
588 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
589 String callerDisplayName) {
590 this.component = component;
591 this.callId = callId;
592 this.callerDisplayName = callerDisplayName;
593 }
594 }
595
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700596 /**
597 * A handler that processes messages on the main thread in the phone process. Since many
598 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
599 * inbound binder threads to the main thread in the phone process. The Binder thread
600 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
601 * on, which will be notified when the operation completes and will contain the result of the
602 * request.
603 *
604 * <p>If a MainThreadRequest object is provided in the msg.obj field,
605 * note that request.result must be set to something non-null for the calling thread to
606 * unblock.
607 */
608 private final class MainThreadHandler extends Handler {
609 @Override
610 public void handleMessage(Message msg) {
611 MainThreadRequest request;
612 Message onCompleted;
613 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000614 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800616 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617
618 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 case CMD_HANDLE_USSD_REQUEST: {
620 request = (MainThreadRequest) msg.obj;
621 final Phone phone = getPhoneFromRequest(request);
622 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800623 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700625
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 if (!isUssdApiAllowed(request.subId)) {
627 // Carrier does not support use of this API, return failure.
628 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
629 UssdResponse response = new UssdResponse(ussdRequest, null);
630 Bundle returnData = new Bundle();
631 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
632 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700633
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 request.result = true;
635 notifyRequester(request);
636 return;
637 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700638
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 try {
640 request.result = phone != null
641 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
642 } catch (CallStateException cse) {
643 request.result = false;
644 }
645 // Wake up the requesting thread
646 notifyRequester(request);
647 break;
pkanwar32d516d2016-10-14 19:37:38 -0700648 }
649
Yorke Lee716f67e2015-06-17 15:39:16 -0700650 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700651 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700652 final Phone phone = getPhoneFromRequest(request);
653 request.result = phone != null ?
654 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
655 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700656 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700658 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700660
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000664 uiccPort = getUiccPortFromRequest(request);
665 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700669 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800671 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000672 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800673 iccArgument.channel, iccArgument.cla, iccArgument.command,
674 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
675 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
682 if (ar.exception == null && ar.result != null) {
683 request.result = ar.result;
684 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800685 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 if (ar.result == null) {
687 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800688 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800690 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 } else {
692 loge("iccTransmitApduLogicalChannel: Unknown exception");
693 }
694 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 break;
697
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
699 request = (MainThreadRequest) msg.obj;
700 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000701 uiccPort = getUiccPortFromRequest(request);
702 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800704 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 } else {
707 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800708 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000709 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800710 iccArgument.cla, iccArgument.command, iccArgument.p1,
711 iccArgument.p2,
712 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700713 }
714 break;
715
716 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
717 ar = (AsyncResult) msg.obj;
718 request = (MainThreadRequest) ar.userObj;
719 if (ar.exception == null && ar.result != null) {
720 request.result = ar.result;
721 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800722 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 if (ar.result == null) {
724 loge("iccTransmitApduBasicChannel: Empty response");
725 } else if (ar.exception instanceof CommandException) {
726 loge("iccTransmitApduBasicChannel: CommandException: " +
727 ar.exception);
728 } else {
729 loge("iccTransmitApduBasicChannel: Unknown exception");
730 }
731 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 break;
734
735 case CMD_EXCHANGE_SIM_IO:
736 request = (MainThreadRequest) msg.obj;
737 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000738 uiccPort = getUiccPortFromRequest(request);
739 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800741 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 } else {
744 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
745 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000746 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700747 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
748 iccArgument.data, onCompleted);
749 }
750 break;
751
752 case EVENT_EXCHANGE_SIM_IO_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 if (ar.exception == null && ar.result != null) {
756 request.result = ar.result;
757 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800758 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700759 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700761 break;
762
Derek Tan4d5e5c12014-02-04 11:54:58 -0800763 case CMD_SEND_ENVELOPE:
764 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000765 uiccPort = getUiccPortFromRequest(request);
766 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700767 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800768 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700770 } else {
771 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800772 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700773 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800774 break;
775
776 case EVENT_SEND_ENVELOPE_DONE:
777 ar = (AsyncResult) msg.obj;
778 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700779 if (ar.exception == null && ar.result != null) {
780 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800781 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800782 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700783 if (ar.result == null) {
784 loge("sendEnvelopeWithStatus: Empty response");
785 } else if (ar.exception instanceof CommandException) {
786 loge("sendEnvelopeWithStatus: CommandException: " +
787 ar.exception);
788 } else {
789 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
790 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800791 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700792 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800793 break;
794
Shishir Agrawal566b7612013-10-28 14:41:00 -0700795 case CMD_OPEN_CHANNEL:
796 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000797 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800798 IccLogicalChannelRequest openChannelRequest =
799 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000800 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700801 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800802 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800803 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700804 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700805 } else {
806 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800807 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
808 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700809 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700810 break;
811
812 case EVENT_OPEN_CHANNEL_DONE:
813 ar = (AsyncResult) msg.obj;
814 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700815 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700816 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700817 int[] result = (int[]) ar.result;
818 int channelId = result[0];
819 byte[] selectResponse = null;
820 if (result.length > 1) {
821 selectResponse = new byte[result.length - 1];
822 for (int i = 1; i < result.length; ++i) {
823 selectResponse[i - 1] = (byte) result[i];
824 }
825 }
826 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800827 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800828
829 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700830 if (uiccPort == null) {
831 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
832 } else {
833 IccLogicalChannelRequest channelRequest =
834 (IccLogicalChannelRequest) request.argument;
835 channelRequest.channel = channelId;
836 uiccPort.onLogicalChannelOpened(channelRequest);
837 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700838 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 if (ar.result == null) {
840 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700842 if (ar.exception != null) {
843 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
844 }
845
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700846 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700847 if (ar.exception instanceof CommandException) {
848 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800849 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700850 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700851 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700852 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700853 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700854 }
855 }
856 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800857 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700858 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700859 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700860 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700861 break;
862
863 case CMD_CLOSE_CHANNEL:
864 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000865 uiccPort = getUiccPortFromRequest(request);
866 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700867 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800868 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800869 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800870 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700871 } else {
872 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000873 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700874 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700875 break;
876
877 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null) {
881 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800882 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700883 if (uiccPort == null) {
884 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
885 } else {
886 final int channelId = (Integer) request.argument;
887 uiccPort.onLogicalChannelClosed(channelId);
888 }
Chen Xu540470b2021-12-14 17:15:47 -0800889 } else {
890 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800891 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800892 if (ar.exception instanceof CommandException) {
893 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
894 CommandException.Error error =
895 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800896 if (error == CommandException.Error.INVALID_ARGUMENTS) {
897 // should only throw exceptions from the binder threads.
898 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800899 "iccCloseLogicalChannel: invalid argument ");
900 }
901 } else {
902 loge("iccCloseLogicalChannel: Unknown exception");
903 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800904 request.result = (exception != null) ? exception :
905 new IllegalStateException(
906 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800907 }
908 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800909 break;
910
911 case CMD_NV_READ_ITEM:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800914 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
915 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800916 break;
917
918 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800921 if (ar.exception == null && ar.result != null) {
922 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700923 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800924 request.result = "";
925 if (ar.result == null) {
926 loge("nvReadItem: Empty response");
927 } else if (ar.exception instanceof CommandException) {
928 loge("nvReadItem: CommandException: " +
929 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700930 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800931 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700932 }
933 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700934 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700935 break;
936
Jake Hambye994d462014-02-03 13:10:13 -0800937 case CMD_NV_WRITE_ITEM:
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
940 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800941 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700942 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800943 break;
944
945 case EVENT_NV_WRITE_ITEM_DONE:
946 handleNullReturnEvent(msg, "nvWriteItem");
947 break;
948
949 case CMD_NV_WRITE_CDMA_PRL:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800952 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800953 break;
954
955 case EVENT_NV_WRITE_CDMA_PRL_DONE:
956 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
957 break;
958
chen xu6dac5ab2018-10-26 17:39:23 -0700959 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800960 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700961 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800962 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800963 break;
964
chen xu6dac5ab2018-10-26 17:39:23 -0700965 case EVENT_RESET_MODEM_CONFIG_DONE:
966 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800967 break;
968
Sooraj Sasindran37444802020-08-11 10:40:43 -0700969 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
972 request);
973 Phone phone = getPhoneFromRequest(request);
974 if (phone != null) {
975 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
976 } else {
977 loge("isNRDualConnectivityEnabled: No phone object");
978 request.result = false;
979 notifyRequester(request);
980 }
981 break;
982 }
983
984 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception == null && ar.result != null) {
988 request.result = ar.result;
989 } else {
990 // request.result must be set to something non-null
991 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700992 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700993 request.result = ar.result;
994 } else {
995 request.result = false;
996 }
997 if (ar.result == null) {
998 loge("isNRDualConnectivityEnabled: Empty response");
999 } else if (ar.exception instanceof CommandException) {
1000 loge("isNRDualConnectivityEnabled: CommandException: "
1001 + ar.exception);
1002 } else {
1003 loge("isNRDualConnectivityEnabled: Unknown exception");
1004 }
1005 }
1006 notifyRequester(request);
1007 break;
1008
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001009 case CMD_IS_VONR_ENABLED: {
1010 request = (MainThreadRequest) msg.obj;
1011 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1012 request);
1013 Phone phone = getPhoneFromRequest(request);
1014 if (phone != null) {
1015 phone.isVoNrEnabled(onCompleted, request.workSource);
1016 } else {
1017 loge("isVoNrEnabled: No phone object");
1018 request.result = false;
1019 notifyRequester(request);
1020 }
1021 break;
1022 }
1023
1024 case EVENT_IS_VONR_ENABLED_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception == null && ar.result != null) {
1028 request.result = ar.result;
1029 } else {
1030 // request.result must be set to something non-null
1031 // for the calling thread to unblock
1032 if (ar.result != null) {
1033 request.result = ar.result;
1034 } else {
1035 request.result = false;
1036 }
1037 if (ar.result == null) {
1038 loge("isVoNrEnabled: Empty response");
1039 } else if (ar.exception instanceof CommandException) {
1040 loge("isVoNrEnabled: CommandException: "
1041 + ar.exception);
1042 } else {
1043 loge("isVoNrEnabled: Unknown exception");
1044 }
1045 }
1046 notifyRequester(request);
1047 break;
1048
Sooraj Sasindran37444802020-08-11 10:40:43 -07001049 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1052 Phone phone = getPhoneFromRequest(request);
1053 if (phone != null) {
1054 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1055 request.workSource);
1056 } else {
1057 loge("enableNrDualConnectivity: No phone object");
1058 request.result =
1059 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1060 notifyRequester(request);
1061 }
1062 break;
1063 }
1064
1065 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 if (ar.exception == null) {
1069 request.result =
1070 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1071 } else {
1072 request.result =
1073 TelephonyManager
1074 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1075 if (ar.exception instanceof CommandException) {
1076 CommandException.Error error =
1077 ((CommandException) (ar.exception)).getCommandError();
1078 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1079 request.result =
1080 TelephonyManager
1081 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001082 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1083 request.result =
1084 TelephonyManager
1085 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001086 }
1087 loge("enableNrDualConnectivity" + ": CommandException: "
1088 + ar.exception);
1089 } else {
1090 loge("enableNrDualConnectivity" + ": Unknown exception");
1091 }
1092 }
1093 notifyRequester(request);
1094 break;
1095 }
1096
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001097 case CMD_ENABLE_VONR: {
1098 request = (MainThreadRequest) msg.obj;
1099 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1100 Phone phone = getPhoneFromRequest(request);
1101 if (phone != null) {
1102 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1103 request.workSource);
1104 } else {
1105 loge("setVoNrEnabled: No phone object");
1106 request.result =
1107 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1108 notifyRequester(request);
1109 }
1110 break;
1111 }
1112
1113 case EVENT_ENABLE_VONR_DONE: {
1114 ar = (AsyncResult) msg.obj;
1115 request = (MainThreadRequest) ar.userObj;
1116 if (ar.exception == null) {
1117 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1118 } else {
1119 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1120 if (ar.exception instanceof CommandException) {
1121 CommandException.Error error =
1122 ((CommandException) (ar.exception)).getCommandError();
1123 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1124 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1125 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1126 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1127 } else {
1128 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1129 }
1130 loge("setVoNrEnabled" + ": CommandException: "
1131 + ar.exception);
1132 } else {
1133 loge("setVoNrEnabled" + ": Unknown exception");
1134 }
1135 }
1136 notifyRequester(request);
1137 break;
1138 }
1139
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1143 request);
1144 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001145 break;
1146
SongFerngWang3ef3e072020-12-21 16:41:52 +08001147 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001148 ar = (AsyncResult) msg.obj;
1149 request = (MainThreadRequest) ar.userObj;
1150 if (ar.exception == null && ar.result != null) {
1151 request.result = ar.result; // Integer
1152 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301153 // request.result must be set to something non-null
1154 // for the calling thread to unblock
1155 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001157 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001159 loge("getAllowedNetworkTypesBitmask: CommandException: "
1160 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001162 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001163 }
1164 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001165 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001166 break;
1167
SongFerngWang3ef3e072020-12-21 16:41:52 +08001168 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001169 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001170 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1171 request);
1172 Pair<Integer, Long> reasonWithNetworkTypes =
1173 (Pair<Integer, Long>) request.argument;
1174 getPhoneFromRequest(request).setAllowedNetworkTypes(
1175 reasonWithNetworkTypes.first,
1176 reasonWithNetworkTypes.second,
1177 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001178 break;
1179
SongFerngWang3ef3e072020-12-21 16:41:52 +08001180 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1181 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001182 break;
1183
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001184 case CMD_SET_VOICEMAIL_NUMBER:
1185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1187 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001188 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1189 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001190 break;
1191
1192 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1193 handleNullReturnEvent(msg, "setVoicemailNumber");
1194 break;
1195
Stuart Scott54788802015-03-30 13:18:01 -07001196 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1197 request = (MainThreadRequest) msg.obj;
1198 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1199 request);
1200 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1201 break;
1202
1203 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1204 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1205 break;
1206
Shishir Agrawal302c8692015-06-19 13:49:39 -07001207 case CMD_PERFORM_NETWORK_SCAN:
1208 request = (MainThreadRequest) msg.obj;
1209 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1210 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1211 break;
1212
Hall Liu27d24262020-09-18 19:04:59 -07001213 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001214 request = (MainThreadRequest) msg.obj;
1215 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001216 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1217 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1218 request.argument;
1219 int callForwardingReason = args.first;
1220 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001221 break;
Hall Liu27d24262020-09-18 19:04:59 -07001222 }
1223 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001224 ar = (AsyncResult) msg.obj;
1225 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001226 TelephonyManager.CallForwardingInfoCallback callback =
1227 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1228 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001229 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001230 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001231 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1232 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1233 // Service Class is a bit mask per 3gpp 27.007. Search for
1234 // any service for voice call.
1235 if ((callForwardInfo.serviceClass
1236 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001237 callForwardingInfo = new CallForwardingInfo(
1238 callForwardInfo.status
1239 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001240 callForwardInfo.reason,
1241 callForwardInfo.number,
1242 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001243 break;
1244 }
1245 }
1246 // Didn't find a call forward info for voice call.
1247 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001248 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1249 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001250 }
Hall Liu27d24262020-09-18 19:04:59 -07001251 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001252 } else {
1253 if (ar.result == null) {
1254 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1255 }
1256 if (ar.exception != null) {
1257 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1258 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001259 int errorCode = TelephonyManager
1260 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001261 if (ar.exception instanceof CommandException) {
1262 CommandException.Error error =
1263 ((CommandException) (ar.exception)).getCommandError();
1264 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001265 errorCode = TelephonyManager
1266 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001267 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001268 errorCode = TelephonyManager
1269 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001270 }
1271 }
Hall Liu27d24262020-09-18 19:04:59 -07001272 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001273 }
Shuo Qian4a594052020-01-23 11:59:30 -08001274 break;
Hall Liu27d24262020-09-18 19:04:59 -07001275 }
Shuo Qian4a594052020-01-23 11:59:30 -08001276
Hall Liu27d24262020-09-18 19:04:59 -07001277 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001278 request = (MainThreadRequest) msg.obj;
1279 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001280 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001281 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001282 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1283 request.argument).first;
1284 request.phone.setCallForwardingOption(
1285 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001286 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001287 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001288 callForwardingInfoToSet.getReason(),
1289 callForwardingInfoToSet.getNumber(),
1290 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1291 break;
Hall Liu27d24262020-09-18 19:04:59 -07001292 }
Shuo Qian4a594052020-01-23 11:59:30 -08001293
Hall Liu27d24262020-09-18 19:04:59 -07001294 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001295 ar = (AsyncResult) msg.obj;
1296 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001297 Consumer<Integer> callback =
1298 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1299 request.argument).second;
1300 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001301 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001302 int errorCode = TelephonyManager.CallForwardingInfoCallback
1303 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001304 if (ar.exception instanceof CommandException) {
1305 CommandException.Error error =
1306 ((CommandException) (ar.exception)).getCommandError();
1307 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001308 errorCode = TelephonyManager.CallForwardingInfoCallback
1309 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001310 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001311 errorCode = TelephonyManager.CallForwardingInfoCallback
1312 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001313 }
1314 }
1315 callback.accept(errorCode);
1316 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001317 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001318 }
Shuo Qian4a594052020-01-23 11:59:30 -08001319 break;
Hall Liu27d24262020-09-18 19:04:59 -07001320 }
Shuo Qian4a594052020-01-23 11:59:30 -08001321
Hall Liu27d24262020-09-18 19:04:59 -07001322 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001323 request = (MainThreadRequest) msg.obj;
1324 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1325 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1326 break;
Hall Liu27d24262020-09-18 19:04:59 -07001327 }
Shuo Qian4a594052020-01-23 11:59:30 -08001328
Hall Liu27d24262020-09-18 19:04:59 -07001329 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001332 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001334 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001335 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001336 // Service Class is a bit mask per 3gpp 27.007.
1337 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001338 if (callForwardResults.length > 1
1339 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001340 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001341 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001342 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1343 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001344 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001345 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001346 }
1347 } else {
1348 if (ar.result == null) {
1349 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1350 }
1351 if (ar.exception != null) {
1352 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1353 }
1354 if (ar.exception instanceof CommandException) {
1355 CommandException.Error error =
1356 ((CommandException) (ar.exception)).getCommandError();
1357 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001358 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001359 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001360 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1361 callWaitingStatus =
1362 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001363 }
1364 }
1365 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001366 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001367 break;
Hall Liu27d24262020-09-18 19:04:59 -07001368 }
Shuo Qian4a594052020-01-23 11:59:30 -08001369
Hall Liu27d24262020-09-18 19:04:59 -07001370 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001371 request = (MainThreadRequest) msg.obj;
1372 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001373 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1374 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001375 break;
Hall Liu27d24262020-09-18 19:04:59 -07001376 }
Shuo Qian4a594052020-01-23 11:59:30 -08001377
Hall Liu27d24262020-09-18 19:04:59 -07001378 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001379 ar = (AsyncResult) msg.obj;
1380 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001381 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1382 Consumer<Integer> callback =
1383 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1384 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001385 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001386 if (ar.exception instanceof CommandException) {
1387 CommandException.Error error =
1388 ((CommandException) (ar.exception)).getCommandError();
1389 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1390 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001391 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1392 callback.accept(
1393 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001394 } else {
1395 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1396 }
1397 } else {
1398 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1399 }
1400 } else {
1401 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1402 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001403 }
Shuo Qian4a594052020-01-23 11:59:30 -08001404 break;
Hall Liu27d24262020-09-18 19:04:59 -07001405 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001406 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
1409 CellNetworkScanResult cellScanResult;
1410 if (ar.exception == null && ar.result != null) {
1411 cellScanResult = new CellNetworkScanResult(
1412 CellNetworkScanResult.STATUS_SUCCESS,
1413 (List<OperatorInfo>) ar.result);
1414 } else {
1415 if (ar.result == null) {
1416 loge("getCellNetworkScanResults: Empty response");
1417 }
1418 if (ar.exception != null) {
1419 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1420 }
1421 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1422 if (ar.exception instanceof CommandException) {
1423 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001424 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001425 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1426 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1427 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1428 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1429 }
1430 }
1431 cellScanResult = new CellNetworkScanResult(errorCode, null);
1432 }
1433 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001434 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001435 break;
1436
1437 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1438 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001439 ManualNetworkSelectionArgument selArg =
1440 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001441 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1442 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001443 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1444 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001445 break;
1446
1447 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null) {
1451 request.result = true;
1452 } else {
1453 request.result = false;
1454 loge("setNetworkSelectionModeManual " + ar.exception);
1455 }
1456 notifyRequester(request);
1457 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001458 break;
1459
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001460 case CMD_GET_MODEM_ACTIVITY_INFO:
1461 request = (MainThreadRequest) msg.obj;
1462 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001463 if (defaultPhone != null) {
1464 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 } else {
1466 ResultReceiver result = (ResultReceiver) request.argument;
1467 Bundle bundle = new Bundle();
1468 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001469 new ModemActivityInfo(0, 0, 0,
1470 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001471 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001472 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001473 break;
1474
Hall Liud0f208c2020-10-14 16:54:44 -07001475 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001476 ar = (AsyncResult) msg.obj;
1477 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001478 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001479 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001480 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001481 if (mLastModemActivityInfo == null) {
1482 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1483 mLastModemActivitySpecificInfo[0] =
1484 new ActivityStatsTechSpecificInfo(
1485 0,
1486 0,
1487 new int[ModemActivityInfo.getNumTxPowerLevels()],
1488 0);
1489 mLastModemActivityInfo =
1490 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1491 }
1492
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001493 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001494 // Update the last modem activity info and the result of the request.
1495 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1496 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001497 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001498 } else {
1499 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001500 }
Kai Shi917fdc62022-11-28 14:01:02 -08001501 // This is needed to decouple ret from mLastModemActivityInfo
1502 // We don't want to return mLastModemActivityInfo which is updated
1503 // inside mergeModemActivityInfo()
1504 ret = new ModemActivityInfo(
1505 mLastModemActivityInfo.getTimestampMillis(),
1506 mLastModemActivityInfo.getSleepTimeMillis(),
1507 mLastModemActivityInfo.getIdleTimeMillis(),
1508 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001509
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 } else {
1511 if (ar.result == null) {
1512 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001513 error = TelephonyManager.ModemActivityInfoException
1514 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001515 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001516 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001517 error = TelephonyManager.ModemActivityInfoException
1518 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001519 } else {
1520 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001521 error = TelephonyManager.ModemActivityInfoException
1522 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001523 }
1524 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001525 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001526 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001527 bundle.putParcelable(
1528 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001529 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001530 } else {
1531 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1532 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001533 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001534 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001535 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001536 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001537
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001538 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001539 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001540 CarrierRestrictionRules argument =
1541 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001542 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001543 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001545 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001546
1547 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 if (ar.exception == null && ar.result != null) {
1551 request.result = ar.result;
1552 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001553 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1554 if (ar.exception instanceof CommandException) {
1555 loge("setAllowedCarriers: CommandException: " + ar.exception);
1556 CommandException.Error error =
1557 ((CommandException) (ar.exception)).getCommandError();
1558 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1559 request.result =
1560 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1561 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001562 } else {
1563 loge("setAllowedCarriers: Unknown exception");
1564 }
1565 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001566 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001567 break;
1568
1569 case CMD_GET_ALLOWED_CARRIERS:
1570 request = (MainThreadRequest) msg.obj;
1571 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001572 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001573 break;
1574
1575 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1576 ar = (AsyncResult) msg.obj;
1577 request = (MainThreadRequest) ar.userObj;
1578 if (ar.exception == null && ar.result != null) {
1579 request.result = ar.result;
1580 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001581 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001582 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001583 if (ar.result == null) {
1584 loge("getAllowedCarriers: Empty response");
1585 } else if (ar.exception instanceof CommandException) {
1586 loge("getAllowedCarriers: CommandException: " +
1587 ar.exception);
1588 } else {
1589 loge("getAllowedCarriers: Unknown exception");
1590 }
1591 }
arunvoddud7401012022-12-15 16:08:12 +00001592 if (request.argument != null) {
1593 // This is for the implementation of carrierRestrictionStatus.
1594 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1595 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001596 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001597 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1598 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1599 CarrierRestrictionRules carrierRestrictionRules =
1600 (CarrierRestrictionRules) ar.result;
1601 int carrierId = -1;
1602 try {
1603 CarrierIdentifier carrierIdentifier =
1604 carrierRestrictionRules.getAllowedCarriers().get(0);
1605 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1606 carrierIdentifier);
1607 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1608 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1609 }
1610 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001611 int restrictedStatus =
1612 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1613 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1614 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001615 lockStatus = TelephonyManager
1616 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001617 }
1618 } else {
1619 Rlog.e(LOG_TAG,
1620 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1621 }
1622 callback.accept(lockStatus);
1623 } else {
1624 // This is for the implementation of getAllowedCarriers.
1625 notifyRequester(request);
1626 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001627 break;
1628
Nathan Haroldb3014052017-01-25 15:57:32 -08001629 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1630 ar = (AsyncResult) msg.obj;
1631 request = (MainThreadRequest) ar.userObj;
1632 if (ar.exception == null && ar.result != null) {
1633 request.result = ar.result;
1634 } else {
1635 request.result = new IllegalArgumentException(
1636 "Failed to retrieve Forbidden Plmns");
1637 if (ar.result == null) {
1638 loge("getForbiddenPlmns: Empty response");
1639 } else {
1640 loge("getForbiddenPlmns: Unknown exception");
1641 }
1642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001643 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001644 break;
1645
1646 case CMD_GET_FORBIDDEN_PLMNS:
1647 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001648 uiccPort = getUiccPortFromRequest(request);
1649 if (uiccPort == null) {
1650 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001651 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001652 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001653 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001654 break;
1655 }
1656 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001657 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001658 if (uiccApp == null) {
1659 loge("getForbiddenPlmns() no app with specified type -- "
1660 + appType);
1661 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001662 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001663 break;
1664 } else {
1665 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1666 + " specified type -- " + appType);
1667 }
1668 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1669 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001670 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001671 break;
1672
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001673 case CMD_SWITCH_SLOTS:
1674 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001675 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001676 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001677 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001678 break;
1679
1680 case EVENT_SWITCH_SLOTS_DONE:
1681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001684 notifyRequester(request);
1685 break;
1686 case CMD_GET_NETWORK_SELECTION_MODE:
1687 request = (MainThreadRequest) msg.obj;
1688 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1689 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1690 break;
1691
1692 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1693 ar = (AsyncResult) msg.obj;
1694 request = (MainThreadRequest) ar.userObj;
1695 if (ar.exception != null) {
1696 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1697 } else {
1698 int mode = ((int[]) ar.result)[0];
1699 if (mode == 0) {
1700 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1701 } else {
1702 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1703 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001705 notifyRequester(request);
1706 break;
1707 case CMD_GET_CDMA_ROAMING_MODE:
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1710 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1711 break;
1712 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 if (ar.exception != null) {
1716 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1717 } else {
1718 request.result = ((int[]) ar.result)[0];
1719 }
1720 notifyRequester(request);
1721 break;
1722 case CMD_SET_CDMA_ROAMING_MODE:
1723 request = (MainThreadRequest) msg.obj;
1724 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1725 int mode = (int) request.argument;
1726 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1727 break;
1728 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731 request.result = ar.exception == null;
1732 notifyRequester(request);
1733 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001734 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1735 request = (MainThreadRequest) msg.obj;
1736 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1737 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1738 break;
1739 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1740 ar = (AsyncResult) msg.obj;
1741 request = (MainThreadRequest) ar.userObj;
1742 if (ar.exception != null) {
1743 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1744 } else {
1745 request.result = ((int[]) ar.result)[0];
1746 }
1747 notifyRequester(request);
1748 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001749 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1750 request = (MainThreadRequest) msg.obj;
1751 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1752 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001753 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1754 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001755 break;
1756 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
1759 request.result = ar.exception == null;
1760 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001761 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001762 case CMD_GET_ALL_CELL_INFO:
1763 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001764 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001765 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001766 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001767 case EVENT_GET_ALL_CELL_INFO_DONE:
1768 ar = (AsyncResult) msg.obj;
1769 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001770 // If a timeout occurs, the response will be null
1771 request.result = (ar.exception == null && ar.result != null)
1772 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001773 synchronized (request) {
1774 request.notifyAll();
1775 }
1776 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001777 case CMD_REQUEST_CELL_INFO_UPDATE:
1778 request = (MainThreadRequest) msg.obj;
1779 request.phone.requestCellInfoUpdate(request.workSource,
1780 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1781 break;
1782 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1783 ar = (AsyncResult) msg.obj;
1784 request = (MainThreadRequest) ar.userObj;
1785 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1786 try {
1787 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001788 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001789 cb.onError(
1790 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1791 ar.exception.getClass().getName(),
1792 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001793 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001794 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001795 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001796 } else {
1797 // use the result as returned
1798 cb.onCellInfo((List<CellInfo>) ar.result);
1799 }
1800 } catch (RemoteException re) {
1801 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1802 }
1803 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001804 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 request = (MainThreadRequest) msg.obj;
1806 WorkSource ws = (WorkSource) request.argument;
1807 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001808 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001809 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001810 }
1811 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001812 ar = (AsyncResult) msg.obj;
1813 request = (MainThreadRequest) ar.userObj;
1814 if (ar.exception == null) {
1815 request.result = ar.result;
1816 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001817 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001818 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001819 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001820 }
1821
1822 synchronized (request) {
1823 request.notifyAll();
1824 }
1825 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001826 }
chen xu6dac5ab2018-10-26 17:39:23 -07001827 case CMD_MODEM_REBOOT:
1828 request = (MainThreadRequest) msg.obj;
1829 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001830 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001831 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001832 case EVENT_CMD_MODEM_REBOOT_DONE:
1833 handleNullReturnEvent(msg, "rebootModem");
1834 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001835 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001836 request = (MainThreadRequest) msg.obj;
1837 boolean enable = (boolean) request.argument;
1838 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001839 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001840 PhoneConfigurationManager.getInstance()
1841 .enablePhone(request.phone, enable, onCompleted);
1842 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001843 }
Michele Berionne5e411512020-11-13 02:36:59 +00001844 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001845 ar = (AsyncResult) msg.obj;
1846 request = (MainThreadRequest) ar.userObj;
1847 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001848 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001849 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001850 if ((boolean) request.result) {
1851 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1852 updateModemStateMetrics();
1853 } else {
1854 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1855 + ar.exception);
1856 }
1857 notifyRequester(request);
1858 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001859 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001860 case CMD_GET_MODEM_STATUS:
1861 request = (MainThreadRequest) msg.obj;
1862 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1863 PhoneConfigurationManager.getInstance()
1864 .getPhoneStatusFromModem(request.phone, onCompleted);
1865 break;
1866 case EVENT_GET_MODEM_STATUS_DONE:
1867 ar = (AsyncResult) msg.obj;
1868 request = (MainThreadRequest) ar.userObj;
1869 int id = request.phone.getPhoneId();
1870 if (ar.exception == null && ar.result != null) {
1871 request.result = ar.result;
1872 //update the cache as modem status has changed
1873 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1874 (boolean) request.result);
1875 } else {
1876 // Return true if modem status cannot be retrieved. For most cases,
1877 // modem status is on. And for older version modems, GET_MODEM_STATUS
1878 // and disable modem are not supported. Modem is always on.
1879 // TODO: this should be fixed in R to support a third
1880 // status UNKNOWN b/131631629
1881 request.result = true;
1882 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1883 + ar.exception);
1884 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001885 notifyRequester(request);
1886 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001887 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1888 request = (MainThreadRequest) msg.obj;
1889 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1890 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1891 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1892 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1893 break;
1894 }
1895 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1896 ar = (AsyncResult) msg.obj;
1897 request = (MainThreadRequest) ar.userObj;
1898 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1899 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1900 args.second.accept(ar.exception == null);
1901 notifyRequester(request);
1902 break;
1903 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001904 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1905 request = (MainThreadRequest) msg.obj;
1906 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1907 Phone phone = getPhoneFromRequest(request);
1908 if (phone != null) {
1909 phone.getSystemSelectionChannels(onCompleted);
1910 } else {
1911 loge("getSystemSelectionChannels: No phone object");
1912 request.result = new ArrayList<RadioAccessSpecifier>();
1913 notifyRequester(request);
1914 }
1915 break;
1916 }
1917 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1918 ar = (AsyncResult) msg.obj;
1919 request = (MainThreadRequest) ar.userObj;
1920 if (ar.exception == null && ar.result != null) {
1921 request.result = ar.result;
1922 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001923 request.result = new IllegalStateException(
1924 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001925 if (ar.result == null) {
1926 loge("getSystemSelectionChannels: Empty response");
1927 } else {
1928 loge("getSystemSelectionChannels: Unknown exception");
1929 }
1930 }
1931 notifyRequester(request);
1932 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001933 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1934 ar = (AsyncResult) msg.obj;
1935 request = (MainThreadRequest) ar.userObj;
1936 if (ar.exception == null && ar.result != null) {
1937 request.result = ar.result;
1938 } else {
1939 request.result = -1;
1940 loge("Failed to set Forbidden Plmns");
1941 if (ar.result == null) {
1942 loge("setForbidenPlmns: Empty response");
1943 } else if (ar.exception != null) {
1944 loge("setForbiddenPlmns: Exception: " + ar.exception);
1945 request.result = -1;
1946 } else {
1947 loge("setForbiddenPlmns: Unknown exception");
1948 }
1949 }
1950 notifyRequester(request);
1951 break;
1952 case CMD_SET_FORBIDDEN_PLMNS:
1953 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001954 uiccPort = getUiccPortFromRequest(request);
1955 if (uiccPort == null) {
1956 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001957 request.result = -1;
1958 notifyRequester(request);
1959 break;
1960 }
1961 Pair<Integer, List<String>> setFplmnsArgs =
1962 (Pair<Integer, List<String>>) request.argument;
1963 appType = setFplmnsArgs.first;
1964 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001965 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001966 if (uiccApp == null) {
1967 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1968 request.result = -1;
1969 loge("Failed to get UICC App");
1970 notifyRequester(request);
1971 } else {
1972 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1973 ((SIMRecords) uiccApp.getIccRecords())
1974 .setForbiddenPlmns(onCompleted, fplmns);
1975 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001976 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001977 case CMD_ERASE_MODEM_CONFIG:
1978 request = (MainThreadRequest) msg.obj;
1979 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1980 defaultPhone.eraseModemConfig(onCompleted);
1981 break;
1982 case EVENT_ERASE_MODEM_CONFIG_DONE:
1983 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001984 break;
zoey chene02881a2019-12-30 16:11:23 +08001985
Kai Shif70f46f2021-03-03 13:59:46 -08001986 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1987 request = (MainThreadRequest) msg.obj;
1988 request.result = defaultPhone.eraseDataInSharedPreferences();
1989 notifyRequester(request);
1990 break;
1991
zoey chene02881a2019-12-30 16:11:23 +08001992 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1993 request = (MainThreadRequest) msg.obj;
1994 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1995 Pair<String, String> changed = (Pair<String, String>) request.argument;
1996 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1997 changed.first, changed.second, onCompleted);
1998 break;
1999 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2000 ar = (AsyncResult) msg.obj;
2001 request = (MainThreadRequest) ar.userObj;
2002 if (ar.exception == null) {
2003 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002004 // If the operation is successful, update the PIN storage
2005 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2006 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002007 UiccController.getInstance().getPinStorage()
2008 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002009 } else {
2010 request.result = msg.arg1;
2011 }
2012 notifyRequester(request);
2013 break;
2014
Michele Berionne5e411512020-11-13 02:36:59 +00002015 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002016 request = (MainThreadRequest) msg.obj;
2017 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2018 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2019 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2020 enabled.first, enabled.second, onCompleted);
2021 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002022 }
zoey chene02881a2019-12-30 16:11:23 +08002023 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2024 ar = (AsyncResult) msg.obj;
2025 request = (MainThreadRequest) ar.userObj;
2026 if (ar.exception == null) {
2027 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002028 // If the operation is successful, update the PIN storage
2029 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2030 int phoneId = getPhoneFromRequest(request).getPhoneId();
2031 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002032 UiccController.getInstance().getPinStorage()
2033 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002034 } else {
2035 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2036 }
zoey chene02881a2019-12-30 16:11:23 +08002037 } else {
2038 request.result = msg.arg1;
2039 }
Michele Berionne5e411512020-11-13 02:36:59 +00002040
2041
zoey chene02881a2019-12-30 16:11:23 +08002042 notifyRequester(request);
2043 break;
2044
Peter Wangdafb9ac2020-01-15 14:13:38 -08002045 case MSG_NOTIFY_USER_ACTIVITY:
2046 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002047 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002048 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2049 getDefaultPhone().getContext().sendBroadcastAsUser(
2050 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2051 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002052
2053 case CMD_SET_DATA_THROTTLING: {
2054 request = (MainThreadRequest) msg.obj;
2055 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2056 DataThrottlingRequest dataThrottlingRequest =
2057 (DataThrottlingRequest) request.argument;
2058 Phone phone = getPhoneFromRequest(request);
2059 if (phone != null) {
2060 phone.setDataThrottling(onCompleted,
2061 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2062 dataThrottlingRequest.getCompletionDurationMillis());
2063 } else {
2064 loge("setDataThrottling: No phone object");
2065 request.result =
2066 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2067 notifyRequester(request);
2068 }
2069
2070 break;
2071 }
2072 case EVENT_SET_DATA_THROTTLING_DONE:
2073 ar = (AsyncResult) msg.obj;
2074 request = (MainThreadRequest) ar.userObj;
2075
2076 if (ar.exception == null) {
2077 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2078 } else if (ar.exception instanceof CommandException) {
2079 loge("setDataThrottling: CommandException: " + ar.exception);
2080 CommandException.Error error =
2081 ((CommandException) (ar.exception)).getCommandError();
2082
2083 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2084 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002085 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002086 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2087 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002088 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2089 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002090 } else {
2091 request.result =
2092 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2093 }
2094 } else {
2095 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2096 }
2097 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2098 notifyRequester(request);
2099 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002100
2101 case CMD_SET_SIM_POWER: {
2102 request = (MainThreadRequest) msg.obj;
2103 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2104 request = (MainThreadRequest) msg.obj;
2105 int stateToSet =
2106 ((Pair<Integer, IIntegerConsumer>)
2107 request.argument).first;
2108 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2109 break;
2110 }
2111 case EVENT_SET_SIM_POWER_DONE: {
2112 ar = (AsyncResult) msg.obj;
2113 request = (MainThreadRequest) ar.userObj;
2114 IIntegerConsumer callback =
2115 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2116 if (ar.exception != null) {
2117 loge("setSimPower exception: " + ar.exception);
2118 int errorCode = TelephonyManager.CallForwardingInfoCallback
2119 .RESULT_ERROR_UNKNOWN;
2120 if (ar.exception instanceof CommandException) {
2121 CommandException.Error error =
2122 ((CommandException) (ar.exception)).getCommandError();
2123 if (error == CommandException.Error.SIM_ERR) {
2124 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2125 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2126 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2127 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2128 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2129 } else {
2130 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2131 }
2132 }
2133 try {
2134 callback.accept(errorCode);
2135 } catch (RemoteException e) {
2136 // Ignore if the remote process is no longer available to call back.
2137 Log.w(LOG_TAG, "setSimPower: callback not available.");
2138 }
2139 } else {
2140 try {
2141 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2142 } catch (RemoteException e) {
2143 // Ignore if the remote process is no longer available to call back.
2144 Log.w(LOG_TAG, "setSimPower: callback not available.");
2145 }
2146 }
2147 break;
2148 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002149 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2150 request = (MainThreadRequest) msg.obj;
2151
2152 final Phone phone = getPhoneFromRequest(request);
2153 if (phone == null || phone.getServiceStateTracker() == null) {
2154 request.result = new IllegalStateException("Phone or SST is null");
2155 notifyRequester(request);
2156 break;
2157 }
2158
2159 Pair<Integer, SignalStrengthUpdateRequest> pair =
2160 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2161 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2162 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002163 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002164 request.subId, pair.first /*callingUid*/,
2165 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002166 break;
2167 }
2168 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2169 ar = (AsyncResult) msg.obj;
2170 request = (MainThreadRequest) ar.userObj;
2171 // request.result will be the exception of ar if present, true otherwise.
2172 // Be cautious not to leave result null which will wait() forever
2173 request.result = ar.exception != null ? ar.exception : true;
2174 notifyRequester(request);
2175 break;
2176 }
2177 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2178 request = (MainThreadRequest) msg.obj;
2179
2180 Phone phone = getPhoneFromRequest(request);
2181 if (phone == null || phone.getServiceStateTracker() == null) {
2182 request.result = new IllegalStateException("Phone or SST is null");
2183 notifyRequester(request);
2184 break;
2185 }
2186
2187 Pair<Integer, SignalStrengthUpdateRequest> pair =
2188 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2189 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2190 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002191 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002192 request.subId, pair.first /*callingUid*/,
2193 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002194 break;
2195 }
2196 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2197 ar = (AsyncResult) msg.obj;
2198 request = (MainThreadRequest) ar.userObj;
2199 request.result = ar.exception != null ? ar.exception : true;
2200 notifyRequester(request);
2201 break;
2202 }
Jordan Liu109698e2020-11-24 14:50:34 -08002203
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002204 case CMD_GET_SLICING_CONFIG: {
2205 request = (MainThreadRequest) msg.obj;
2206 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2207 request.phone.getSlicingConfig(onCompleted);
2208 break;
2209 }
2210 case EVENT_GET_SLICING_CONFIG_DONE: {
2211 ar = (AsyncResult) msg.obj;
2212 request = (MainThreadRequest) ar.userObj;
2213 ResultReceiver result = (ResultReceiver) request.argument;
2214
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002215 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002216 Bundle bundle = new Bundle();
2217 int resultCode = 0;
2218 if (ar.exception != null) {
2219 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2220 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002221 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002222 } else if (ar.result == null) {
2223 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002224 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002225 } else {
2226 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002227 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2228 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002229 }
2230
2231 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002232 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002233 }
2234 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2235 result.send(resultCode, bundle);
2236 notifyRequester(request);
2237 break;
2238 }
2239
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241 request = (MainThreadRequest) msg.obj;
2242 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 PurchasePremiumCapabilityArgument arg =
2244 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002245 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2246 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002247 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002248 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002249
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251 ar = (AsyncResult) msg.obj;
2252 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002253 PurchasePremiumCapabilityArgument arg =
2254 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002255 try {
2256 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002257 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002258 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002259 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002260 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002261 + TelephonyManager.convertPurchaseResultToString(result));
2262 } catch (RemoteException e) {
2263 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002264 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002265 + " failed: " + e;
2266 if (DBG) log(logStr);
2267 AnomalyReporter.reportAnomaly(
2268 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2269 }
2270 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002271 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002272
Michele Berionne5e411512020-11-13 02:36:59 +00002273 case CMD_PREPARE_UNATTENDED_REBOOT:
2274 request = (MainThreadRequest) msg.obj;
2275 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002276 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002277 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002278 notifyRequester(request);
2279 break;
2280
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 default:
2282 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2283 break;
2284 }
2285 }
Jake Hambye994d462014-02-03 13:10:13 -08002286
Pengquan Menga1bb6272018-09-06 09:59:22 -07002287 private void notifyRequester(MainThreadRequest request) {
2288 synchronized (request) {
2289 request.notifyAll();
2290 }
2291 }
2292
Jake Hambye994d462014-02-03 13:10:13 -08002293 private void handleNullReturnEvent(Message msg, String command) {
2294 AsyncResult ar = (AsyncResult) msg.obj;
2295 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2296 if (ar.exception == null) {
2297 request.result = true;
2298 } else {
2299 request.result = false;
2300 if (ar.exception instanceof CommandException) {
2301 loge(command + ": CommandException: " + ar.exception);
2302 } else {
2303 loge(command + ": Unknown exception");
2304 }
2305 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002306 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 }
2309
2310 /**
2311 * Posts the specified command to be executed on the main thread,
2312 * waits for the request to complete, and returns the result.
2313 * @see #sendRequestAsync
2314 */
2315 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002316 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2317 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002318 }
2319
2320 /**
2321 * Posts the specified command to be executed on the main thread,
2322 * waits for the request to complete, and returns the result.
2323 * @see #sendRequestAsync
2324 */
2325 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2326 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002327 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002328 }
2329
2330 /**
2331 * Posts the specified command to be executed on the main thread,
2332 * waits for the request to complete, and returns the result.
2333 * @see #sendRequestAsync
2334 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002335 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002336 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2337 }
2338
2339 /**
2340 * Posts the specified command to be executed on the main thread,
2341 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2342 * if not timeout or null otherwise.
2343 * @see #sendRequestAsync
2344 */
2345 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2346 long timeoutInMs) {
2347 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002348 }
2349
2350 /**
2351 * Posts the specified command to be executed on the main thread,
2352 * waits for the request to complete, and returns the result.
2353 * @see #sendRequestAsync
2354 */
Nathan Harold92bed182018-10-12 18:16:49 -07002355 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002356 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002357 }
2358
2359 /**
2360 * Posts the specified command to be executed on the main thread,
2361 * waits for the request to complete, and returns the result.
2362 * @see #sendRequestAsync
2363 */
2364 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002365 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2366 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002367 }
2368
2369 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002370 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2371 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2372 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002373 * @see #sendRequestAsync
2374 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002375 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2376 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2378 throw new RuntimeException("This method will deadlock if called from the main thread.");
2379 }
2380
Nathan Harold92bed182018-10-12 18:16:49 -07002381 MainThreadRequest request = null;
2382 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2383 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2384 } else if (phone != null) {
2385 request = new MainThreadRequest(argument, phone, workSource);
2386 } else {
2387 request = new MainThreadRequest(argument, subId, workSource);
2388 }
2389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 Message msg = mMainThreadHandler.obtainMessage(command, request);
2391 msg.sendToTarget();
2392
Rambo Wang0f050d82021-02-12 11:43:36 -08002393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002395 if (timeoutInMs >= 0) {
2396 // Wait for at least timeoutInMs before returning null request result
2397 long now = SystemClock.elapsedRealtime();
2398 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002399 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002400 try {
2401 request.wait(deadline - now);
2402 } catch (InterruptedException e) {
2403 // Do nothing, go back and check if request is completed or timeout
2404 } finally {
2405 now = SystemClock.elapsedRealtime();
2406 }
2407 }
2408 } else {
2409 // Wait for the request to complete
2410 while (request.result == null) {
2411 try {
2412 request.wait();
2413 } catch (InterruptedException e) {
2414 // Do nothing, go back and wait until the request is complete
2415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 }
2417 }
2418 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002419 if (request.result == null) {
2420 Log.wtf(LOG_TAG,
2421 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 return request.result;
2424 }
2425
2426 /**
2427 * Asynchronous ("fire and forget") version of sendRequest():
2428 * Posts the specified command to be executed on the main thread, and
2429 * returns immediately.
2430 * @see #sendRequest
2431 */
2432 private void sendRequestAsync(int command) {
2433 mMainThreadHandler.sendEmptyMessage(command);
2434 }
2435
2436 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002437 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002438 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002439 */
2440 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002441 sendRequestAsync(command, argument, null, null);
2442 }
2443
2444 /**
2445 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2446 * @see {@link #sendRequest(int,Object)}
2447 */
2448 private void sendRequestAsync(
2449 int command, Object argument, Phone phone, WorkSource workSource) {
2450 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002451 Message msg = mMainThreadHandler.obtainMessage(command, request);
2452 msg.sendToTarget();
2453 }
2454
2455 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 * Initialize the singleton PhoneInterfaceManager instance.
2457 * This is only done once, at startup, from PhoneApp.onCreate().
2458 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002459 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 synchronized (PhoneInterfaceManager.class) {
2461 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002462 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 } else {
2464 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2465 }
2466 return sInstance;
2467 }
2468 }
2469
2470 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002471 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002473 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002474 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002476 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002477 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002478 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2480 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002481 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002482 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002483 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002484 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002485 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002486 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002487 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2488 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002489 mVendorApiLevel = SystemProperties.getInt(
2490 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2491
Tyler Gunn64144d92022-03-17 14:16:41 -07002492 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 publish();
arunvoddud7401012022-12-15 16:08:12 +00002494 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002495
2496 // Create the SatelliteEntitlementController singleton, for using the get the
2497 // entitlementStatus for satellite service.
2498 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 }
2500
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002501 @VisibleForTesting
2502 public SharedPreferences getSharedPreferences() {
2503 return mTelephonySharedPreferences;
2504 }
2505
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002506 /**
2507 * Get the default phone for this device.
2508 */
2509 @VisibleForTesting
2510 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002511 Phone thePhone = getPhone(getDefaultSubscription());
2512 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2513 }
2514
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 private void publish() {
2516 if (DBG) log("publish: " + this);
2517
Peter Wangc035ce42020-01-08 21:00:22 -08002518 TelephonyFrameworkInitializer
2519 .getTelephonyServiceManager()
2520 .getTelephonyServiceRegisterer()
2521 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 }
2523
Stuart Scott584921c2015-01-15 17:10:34 -08002524 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002525 if (request.phone != null) {
2526 return request.phone;
2527 } else {
2528 return getPhoneFromSubId(request.subId);
2529 }
2530 }
2531
2532 private Phone getPhoneFromSubId(int subId) {
2533 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2534 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002535 }
2536
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002537 /**
2538 * Get phone object associated with a subscription.
2539 * Return default phone if phone object associated with subscription is null
2540 * @param subId - subscriptionId
2541 * @return phone object associated with a subscription or default phone if null.
2542 */
Ling Mac28f0212023-03-24 16:07:15 -07002543 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002544 Phone phone = getPhoneFromSubId(subId);
2545 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002546 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002547 phone = getDefaultPhone();
2548 }
2549 return phone;
2550 }
2551
Rambo Wange53e07d2022-05-10 13:01:13 -07002552 @Nullable
2553 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002554 Phone phone = getPhoneFromRequest(request);
2555 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002556 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002557 }
2558
Ling Mac28f0212023-03-24 16:07:15 -07002559 /**
2560 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2561 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2562 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2563 * @return The Phone associated the sub Id
2564 */
2565 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002566 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568
Kai Shif70f46f2021-03-03 13:59:46 -08002569 private void sendEraseModemConfig(@NonNull Phone phone) {
2570 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2571 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2572 }
2573
2574 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2575 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2576 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002577 }
2578
Peter Wang44b186e2020-01-13 23:33:09 -08002579 private boolean isImsAvailableOnDevice() {
2580 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2581 if (pm == null) {
2582 // For some reason package manger is not available.. This will fail internally anyway,
2583 // so do not throw error and allow.
2584 return true;
2585 }
2586 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2587 }
2588
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002590 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2591 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2592
Wink Savilleadd7cc52014-09-08 14:23:09 -07002593 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002594 }
2595
Wink Savilleb564aae2014-10-23 10:18:09 -07002596 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597 if (DBG) log("dial: " + number);
2598 // No permission check needed here: This is just a wrapper around the
2599 // ACTION_DIAL intent, which is available to any app since it puts up
2600 // the UI before it does anything.
2601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 String url = createTelUrl(number);
2605 if (url == null) {
2606 return;
2607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 // PENDING: should we just silently fail if phone is offhook or ringing?
2610 PhoneConstants.State state = mCM.getState(subId);
2611 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2612 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2613 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2614 mApp.startActivity(intent);
2615 }
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619 }
2620
2621 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002622 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002623 }
2624
Wink Savilleb564aae2014-10-23 10:18:09 -07002625 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 if (DBG) log("call: " + number);
2627
2628 // This is just a wrapper around the ACTION_CALL intent, but we still
2629 // need to do a permission check since we're calling startActivity()
2630 // from the context of the phone app.
2631 enforceCallPermission();
2632
Jordan Liu1617b712019-07-10 15:06:26 -07002633 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 != AppOpsManager.MODE_ALLOWED) {
2635 return;
2636 }
2637
joonhunshin4ac60942023-11-15 15:23:39 +00002638 enforceTelephonyFeatureWithException(callingPackage,
2639 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 String url = createTelUrl(number);
2644 if (url == null) {
2645 return;
2646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 boolean isValid = false;
2649 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2650 if (slist != null) {
2651 for (SubscriptionInfo subInfoRecord : slist) {
2652 if (subInfoRecord.getSubscriptionId() == subId) {
2653 isValid = true;
2654 break;
2655 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002656 }
Wink Saville08874612014-08-31 19:19:58 -07002657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 if (!isValid) {
2659 return;
2660 }
Wink Saville08874612014-08-31 19:19:58 -07002661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2663 intent.putExtra(SUBSCRIPTION_KEY, subId);
2664 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2665 mApp.startActivity(intent);
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002669 }
2670
Wink Savilleb564aae2014-10-23 10:18:09 -07002671 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002672 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002673 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2674 }
2675
Wink Savilleb564aae2014-10-23 10:18:09 -07002676 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002678 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2679 }
2680
Wink Savilleb564aae2014-10-23 10:18:09 -07002681 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
joonhunshin4ac60942023-11-15 15:23:39 +00002684 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2685 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2686 "supplyPinReportResultForSubscriber");
2687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 final long identity = Binder.clearCallingIdentity();
2689 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002690 Phone phone = getPhone(subId);
2691 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 checkSimPin.start();
2693 return checkSimPin.unlockSim(null, pin);
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
2696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 }
2698
Wink Savilleb564aae2014-10-23 10:18:09 -07002699 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701
joonhunshin4ac60942023-11-15 15:23:39 +00002702 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2703 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002707 Phone phone = getPhone(subId);
2708 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709 checkSimPuk.start();
2710 return checkSimPuk.unlockSim(puk, pin);
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
2713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
2716 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002717 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 * a synchronous one.
2719 */
2720 private static class UnlockSim extends Thread {
2721
2722 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002723 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724
2725 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002726 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2727 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728
2729 // For replies from SimCard interface
2730 private Handler mHandler;
2731
2732 // For async handler to identify request type
2733 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002734 private static final int SUPPLY_PIN_DELAYED = 101;
2735 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2736 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2737 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738
Michele Berionne5e411512020-11-13 02:36:59 +00002739 UnlockSim(int phoneId, IccCard simCard) {
2740 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 mSimCard = simCard;
2742 }
2743
2744 @Override
2745 public void run() {
2746 Looper.prepare();
2747 synchronized (UnlockSim.this) {
2748 mHandler = new Handler() {
2749 @Override
2750 public void handleMessage(Message msg) {
2751 AsyncResult ar = (AsyncResult) msg.obj;
2752 switch (msg.what) {
2753 case SUPPLY_PIN_COMPLETE:
2754 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2755 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002756 mRetryCount = msg.arg1;
2757 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002758 CommandException.Error error = null;
2759 if (ar.exception instanceof CommandException) {
2760 error = ((CommandException) (ar.exception))
2761 .getCommandError();
2762 }
2763 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002764 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002765 } else if (error == CommandException.Error.ABORTED) {
2766 /* When UiccCardApp dispose, handle message and return
2767 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002768 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002769 } else {
2770 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2771 }
2772 } else {
2773 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002776 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 UnlockSim.this.notifyAll();
2778 }
2779 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002780 case SUPPLY_PIN_DELAYED:
2781 if(!mDone) {
2782 String logStr = "Delay in receiving SIM PIN response ";
2783 if (DBG) log(logStr);
2784 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2785 }
2786 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 }
2788 }
2789 };
2790 UnlockSim.this.notifyAll();
2791 }
2792 Looper.loop();
2793 }
2794
2795 /*
2796 * Use PIN or PUK to unlock SIM card
2797 *
2798 * If PUK is null, unlock SIM card with PIN
2799 *
2800 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302801 *
2802 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2803 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002804 */
Wink Saville9de0f752013-10-22 19:04:03 -07002805 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002806
2807 while (mHandler == null) {
2808 try {
2809 wait();
2810 } catch (InterruptedException e) {
2811 Thread.currentThread().interrupt();
2812 }
2813 }
2814 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2815
2816 if (puk == null) {
2817 mSimCard.supplyPin(pin, callback);
2818 } else {
2819 mSimCard.supplyPuk(puk, pin, callback);
2820 }
2821
2822 while (!mDone) {
2823 try {
2824 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002825 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2826 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 wait();
2828 } catch (InterruptedException e) {
2829 // Restore the interrupted status
2830 Thread.currentThread().interrupt();
2831 }
2832 }
2833 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002834 int[] resultArray = new int[2];
2835 resultArray[0] = mResult;
2836 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002837
2838 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002839 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002840 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302841 // This instance is no longer reused, so quit its thread's looper.
2842 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002843
Wink Saville9de0f752013-10-22 19:04:03 -07002844 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 }
2846 }
2847
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002848 /**
2849 * This method has been removed due to privacy and stability concerns.
2850 */
2851 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002853 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2854 return;
Wink Saville36469e72014-06-11 15:17:00 -07002855 }
2856
Nathan Harold1f889d82020-06-04 17:05:26 -07002857 @Override
2858 public void updateServiceLocationWithPackageName(String callingPackage) {
2859 mApp.getSystemService(AppOpsManager.class)
2860 .checkPackage(Binder.getCallingUid(), callingPackage);
2861
Nathan Haroldf096d982020-11-18 17:18:06 -08002862 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002863 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2864 // Callers targeting S have no business invoking this method.
2865 return;
2866 }
2867
2868 LocationAccessPolicy.LocationPermissionResult locationResult =
2869 LocationAccessPolicy.checkLocationPermission(mApp,
2870 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2871 .setCallingPackage(callingPackage)
2872 .setCallingFeatureId(null)
2873 .setCallingPid(Binder.getCallingPid())
2874 .setCallingUid(Binder.getCallingUid())
2875 .setMethod("updateServiceLocation")
2876 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2877 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2878 .build());
2879 // Apps that lack location permission have no business calling this method;
2880 // however, because no permission was declared in the public API, denials must
2881 // all be "soft".
2882 switch (locationResult) {
2883 case DENIED_HARD: /* fall through */
2884 case DENIED_SOFT:
2885 return;
2886 }
2887
2888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 final long identity = Binder.clearCallingIdentity();
2890 try {
Ling Mac28f0212023-03-24 16:07:15 -07002891 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 } finally {
2893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 }
2896
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002897 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002898 @Override
2899 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002900 return isRadioOnWithFeature(callingPackage, null);
2901 }
2902
2903
2904 @Override
2905 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2906 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2907 callingFeatureId);
2908 }
2909
2910 @Deprecated
2911 @Override
2912 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2913 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002914 }
2915
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002916 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002917 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2918 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002919 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002920 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002921 return false;
2922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923
joonhunshin4ac60942023-11-15 15:23:39 +00002924 enforceTelephonyFeatureWithException(callingPackage,
2925 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 return isRadioOnForSubscriber(subId);
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002933 }
2934
2935 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 final Phone phone = getPhone(subId);
2939 if (phone != null) {
2940 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2941 } else {
2942 return false;
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 }
2948
2949 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002950 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002951 }
Wink Saville36469e72014-06-11 15:17:00 -07002952
Wink Savilleb564aae2014-10-23 10:18:09 -07002953 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955
joonhunshin4ac60942023-11-15 15:23:39 +00002956 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2957 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 final Phone phone = getPhone(subId);
2962 if (phone != null) {
2963 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2964 }
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002967 }
Wink Saville36469e72014-06-11 15:17:00 -07002968 }
2969
2970 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002971 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002972 }
2973
Wink Savilleb564aae2014-10-23 10:18:09 -07002974 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002975 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976
2977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 final Phone phone = getPhone(subId);
2980 if (phone == null) {
2981 return false;
2982 }
2983 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2984 toggleRadioOnOffForSubscriber(subId);
2985 }
2986 return true;
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 }
Wink Saville36469e72014-06-11 15:17:00 -07002991
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002992 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002993 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002994
2995 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2996 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2997
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002998 /*
2999 * If any of the Radios are available, it will need to be
3000 * shutdown. So return true if any Radio is available.
3001 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3005 Phone phone = PhoneFactory.getPhone(i);
3006 if (phone != null && phone.isRadioAvailable()) return true;
3007 }
3008 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3009 return false;
3010 } finally {
3011 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003012 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003013 }
3014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003016 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017 enforceModifyPermission();
3018
joonhunshin4ac60942023-11-15 15:23:39 +00003019 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3020 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3025 logv("Shutting down Phone " + i);
3026 shutdownRadioUsingPhoneId(i);
3027 }
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003030 }
3031 }
3032
3033 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003034 Phone phone = PhoneFactory.getPhone(phoneId);
3035 if (phone != null && phone.isRadioAvailable()) {
3036 phone.shutdownRadio();
3037 }
3038 }
3039
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003040 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042
Ling Ma83dc5ea2023-01-12 15:06:04 -08003043 if (!turnOn) {
3044 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3045 }
3046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3050 if (defaultPhone != null) {
3051 defaultPhone.setRadioPower(turnOn);
3052 return true;
3053 } else {
3054 loge("There's no default phone.");
3055 return false;
3056 }
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003059 }
Wink Saville36469e72014-06-11 15:17:00 -07003060 }
3061
Wink Savilleb564aae2014-10-23 10:18:09 -07003062 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064
Ling Ma83dc5ea2023-01-12 15:06:04 -08003065 if (!turnOn) {
3066 log("setRadioPowerForSubscriber off: subId=" + subId
3067 + ",callingPackage=" + getCurrentPackageName());
3068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 final Phone phone = getPhone(subId);
3072 if (phone != null) {
3073 phone.setRadioPower(turnOn);
3074 return true;
3075 } else {
3076 return false;
3077 }
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081 }
3082
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003083 /**
3084 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3085 * no reason to power it off. When any of the voters want to power it off, it will be turned
3086 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3087 * powering it off, and these radio off votes will be cleared.
3088 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3089 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3090 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3091 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3092 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3093 * check its vote.
3094 *
3095 * @param subId The subscription ID.
3096 * @param reason The reason for powering off radio.
3097 * @return true on success and false on failure.
3098 */
3099 public boolean requestRadioPowerOffForReason(int subId,
3100 @TelephonyManager.RadioPowerReason int reason) {
3101 enforceModifyPermission();
3102
joonhunshin4ac60942023-11-15 15:23:39 +00003103 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3104 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3105
Ling Ma83dc5ea2023-01-12 15:06:04 -08003106 log("requestRadioPowerOffForReason: subId=" + subId
3107 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003108 final long identity = Binder.clearCallingIdentity();
3109 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003110 boolean result = false;
3111 for (Phone phone : PhoneFactory.getPhones()) {
3112 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003113 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003114 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003115 if (!result) {
3116 loge("requestRadioPowerOffForReason: no phone exists");
3117 }
3118 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
3124 /**
3125 * Remove the vote on powering off the radio for a reason, as requested by
3126 * {@link requestRadioPowerOffForReason}.
3127 *
3128 * @param subId The subscription ID.
3129 * @param reason The reason for powering off radio.
3130 * @return true on success and false on failure.
3131 */
3132 public boolean clearRadioPowerOffForReason(int subId,
3133 @TelephonyManager.RadioPowerReason int reason) {
3134 enforceModifyPermission();
3135
joonhunshin4ac60942023-11-15 15:23:39 +00003136 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3137 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3138
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003139 final long identity = Binder.clearCallingIdentity();
3140 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003141 boolean result = false;
3142 for (Phone phone : PhoneFactory.getPhones()) {
3143 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003144 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003145 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003146 if (!result) {
3147 loge("clearRadioPowerOffForReason: no phone exists");
3148 }
3149 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003150 } finally {
3151 Binder.restoreCallingIdentity(identity);
3152 }
3153 }
3154
3155 /**
3156 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3157 *
3158 * @param subId The subscription ID.
3159 * @param callingPackage The package making the call.
3160 * @param callingFeatureId The feature in the package.
3161 * @return List of reasons for powering off radio.
3162 */
3163 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3164 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3165
joonhunshin4ac60942023-11-15 15:23:39 +00003166 enforceTelephonyFeatureWithException(callingPackage,
3167 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3168
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003169 final long identity = Binder.clearCallingIdentity();
3170 List result = new ArrayList();
3171 try {
3172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3173 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3174 return result;
3175 }
3176
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003177 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003178 if (phone != null) {
3179 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003180 } else {
3181 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003182 }
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
3185 }
3186 return result;
3187 }
3188
Wink Saville36469e72014-06-11 15:17:00 -07003189 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003190 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003191 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193
joonhunshin4ac60942023-11-15 15:23:39 +00003194 enforceTelephonyFeatureWithException(callingPackage,
3195 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 final long identity = Binder.clearCallingIdentity();
3198 try {
Jack Yu285100e2022-12-02 22:48:35 -08003199 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final Phone phone = getPhone(subId);
3201 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003202 phone.getDataSettingsManager().setDataEnabled(
3203 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 return true;
3205 } else {
3206 return false;
3207 }
3208 } finally {
3209 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 }
3212
Wink Saville36469e72014-06-11 15:17:00 -07003213 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003214 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003215 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217
joonhunshin4ac60942023-11-15 15:23:39 +00003218 enforceTelephonyFeatureWithException(callingPackage,
3219 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 final long identity = Binder.clearCallingIdentity();
3222 try {
Jack Yu285100e2022-12-02 22:48:35 -08003223 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 final Phone phone = getPhone(subId);
3225 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003226 phone.getDataSettingsManager().setDataEnabled(
3227 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228 return true;
3229 } else {
3230 return false;
3231 }
3232 } finally {
3233 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003235 }
3236
Sanket Padawe356d7632015-06-22 14:03:32 -07003237 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003238 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003239 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3240 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 final Phone phone = getPhone(subId);
3245 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003246 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247 } else {
3248 return false;
3249 }
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 }
3254
3255 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003256 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003257 }
3258
pkanwarae03a6b2016-11-06 20:37:09 -08003259 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003260 enforceCallPermission();
3261
joonhunshin4ac60942023-11-15 15:23:39 +00003262 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3263 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265 final long identity = Binder.clearCallingIdentity();
3266 try {
3267 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3268 return;
3269 }
3270 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3271 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3272 } finally {
3273 Binder.restoreCallingIdentity(identity);
3274 }
pkanwar32d516d2016-10-14 19:37:38 -07003275 };
3276
Wink Savilleb564aae2014-10-23 10:18:09 -07003277 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279
joonhunshin4ac60942023-11-15 15:23:39 +00003280 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3281 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3286 return false;
3287 }
3288 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3289 } finally {
3290 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003292 }
3293
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003294 /**
3295 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3296 * tag on getCallState Binder call.
3297 */
3298 @Deprecated
3299 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003301 if (CompatChanges.isChangeEnabled(
3302 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3303 Binder.getCallingUid())) {
3304 // Do not allow this API to be called on API version 31+, it should only be
3305 // called on old apps using this Binder call directly.
3306 throw new SecurityException("This method can only be used for applications "
3307 + "targeting API version 30 or less.");
3308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309 final long identity = Binder.clearCallingIdentity();
3310 try {
Ling Mac28f0212023-03-24 16:07:15 -07003311 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3312 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
3316 }
3317
3318 @Override
3319 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3320 if (CompatChanges.isChangeEnabled(
3321 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3322 Binder.getCallingUid())) {
3323 // Check READ_PHONE_STATE for API version 31+
3324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3325 featureId, "getCallStateForSubscription")) {
3326 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3327 + "targeting API level 31+.");
3328 }
3329 }
joonhunshin4ac60942023-11-15 15:23:39 +00003330
3331 enforceTelephonyFeatureWithException(callingPackage,
3332 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3333
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3338 PhoneConstantConversions.convertCallState(phone.getState());
3339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003342 }
3343
Sanket Padawe356d7632015-06-22 14:03:32 -07003344 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003345 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003346 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003347 }
3348
3349 @Override
3350 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003351 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3352 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354 final long identity = Binder.clearCallingIdentity();
3355 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003356 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003358 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359 } else {
3360 return PhoneConstantConversions.convertDataState(
3361 PhoneConstants.DataState.DISCONNECTED);
3362 }
3363 } finally {
3364 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003366 }
3367
Sanket Padawe356d7632015-06-22 14:03:32 -07003368 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003369 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003370 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003371 }
3372
3373 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003374 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003375 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3376 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 final long identity = Binder.clearCallingIdentity();
3379 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003380 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003382 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003383 } else {
3384 return TelephonyManager.DATA_ACTIVITY_NONE;
3385 }
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 }
3390
3391 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003392 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003393 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003394 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003395
3396 LocationAccessPolicy.LocationPermissionResult locationResult =
3397 LocationAccessPolicy.checkLocationPermission(mApp,
3398 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3399 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003400 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003401 .setCallingPid(Binder.getCallingPid())
3402 .setCallingUid(Binder.getCallingUid())
3403 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003404 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003405 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3406 .build());
3407 switch (locationResult) {
3408 case DENIED_HARD:
3409 throw new SecurityException("Not allowed to access cell location");
3410 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003411 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3412 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 }
3414
joonhunshin4ac60942023-11-15 15:23:39 +00003415 enforceTelephonyFeatureWithException(callingPackage,
3416 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3417
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003418 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003422 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003423 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
Svetoslav64fad262015-04-14 14:35:21 -07003427 }
3428
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003429 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003430 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003431 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3432 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3433
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003434 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3435 // registered cell info, so return a NULL country instead.
3436 final long identity = Binder.clearCallingIdentity();
3437 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003438 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3439 // Get default phone in this case.
3440 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3441 }
Jack Yu285100e2022-12-02 22:48:35 -08003442 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003444 if (phone == null) return "";
3445 ServiceStateTracker sst = phone.getServiceStateTracker();
3446 if (sst == null) return "";
3447 LocaleTracker lt = sst.getLocaleTracker();
3448 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003449 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003450 } finally {
3451 Binder.restoreCallingIdentity(identity);
3452 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003453 }
3454
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003455 /**
3456 * This method was removed due to potential issues caused by performing partial
3457 * updates of service state, and lack of a credible use case.
3458 *
3459 * This has the ability to break the telephony implementation by disabling notification of
3460 * changes in device connectivity. DO NOT USE THIS!
3461 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003462 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 public void enableLocationUpdates() {
3464 mApp.enforceCallingOrSelfPermission(
3465 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003466 }
3467
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003468 /**
3469 * This method was removed due to potential issues caused by performing partial
3470 * updates of service state, and lack of a credible use case.
3471 *
3472 * This has the ability to break the telephony implementation by disabling notification of
3473 * changes in device connectivity. DO NOT USE THIS!
3474 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003475 @Override
3476 public void disableLocationUpdates() {
3477 mApp.enforceCallingOrSelfPermission(
3478 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003479 }
3480
3481 @Override
3482 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003483 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3484 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003485 try {
3486 mApp.getSystemService(AppOpsManager.class)
3487 .checkPackage(Binder.getCallingUid(), callingPackage);
3488 } catch (SecurityException e) {
3489 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3490 throw e;
3491 }
3492
Nathan Haroldf096d982020-11-18 17:18:06 -08003493 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003494 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3495 throw new SecurityException(
3496 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3497 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003498
Jordan Liu1617b712019-07-10 15:06:26 -07003499 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003500 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3501 return null;
3502 }
Svetoslav64fad262015-04-14 14:35:21 -07003503
joonhunshin4ac60942023-11-15 15:23:39 +00003504 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3505 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3506
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003507 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003509 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003510 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511
Nathan Haroldf180aac2018-06-01 18:43:55 -07003512 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3513 for (CellInfo ci : info) {
3514 if (ci instanceof CellInfoGsm) {
3515 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3516 } else if (ci instanceof CellInfoWcdma) {
3517 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003519 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003520 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 }
3522
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003523 private List<CellInfo> getCachedCellInfo() {
3524 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3525 for (Phone phone : PhoneFactory.getPhones()) {
3526 List<CellInfo> info = phone.getAllCellInfo();
3527 if (info != null) cellInfos.addAll(info);
3528 }
3529 return cellInfos;
3530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003531
3532 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003533 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003534 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003535 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003536
3537 LocationAccessPolicy.LocationPermissionResult locationResult =
3538 LocationAccessPolicy.checkLocationPermission(mApp,
3539 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3540 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003541 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003542 .setCallingPid(Binder.getCallingPid())
3543 .setCallingUid(Binder.getCallingUid())
3544 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003545 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003546 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3547 .build());
3548 switch (locationResult) {
3549 case DENIED_HARD:
3550 throw new SecurityException("Not allowed to access cell info");
3551 case DENIED_SOFT:
3552 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003553 }
3554
Nathan Haroldf096d982020-11-18 17:18:06 -08003555 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003556 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3557 return getCachedCellInfo();
3558 }
3559
joonhunshin4ac60942023-11-15 15:23:39 +00003560 enforceTelephonyFeatureWithException(callingPackage,
3561 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3562
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003563 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003564 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3568 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003569 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003570 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571 if (info != null) cellInfos.addAll(info);
3572 }
3573 return cellInfos;
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003576 }
3577 }
3578
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003579 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003580 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3581 String callingFeatureId) {
3582 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3583 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003584 }
3585
3586 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003587 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3588 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003589 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003590 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003591 }
3592
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003593 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3594 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003596 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003597
3598 LocationAccessPolicy.LocationPermissionResult locationResult =
3599 LocationAccessPolicy.checkLocationPermission(mApp,
3600 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3601 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003602 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003603 .setCallingPid(Binder.getCallingPid())
3604 .setCallingUid(Binder.getCallingUid())
3605 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003606 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3607 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003608 .build());
3609 switch (locationResult) {
3610 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003611 if (TelephonyPermissions
3612 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003613 // Safetynet logging for b/154934934
3614 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3615 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003616 throw new SecurityException("Not allowed to access cell info");
3617 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003618 if (TelephonyPermissions
3619 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003620 // Safetynet logging for b/154934934
3621 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3622 }
Nathan Harold5320c422019-05-09 10:26:08 -07003623 try {
3624 cb.onCellInfo(new ArrayList<CellInfo>());
3625 } catch (RemoteException re) {
3626 // Drop without consequences
3627 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003628 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003629 }
3630
joonhunshin4ac60942023-11-15 15:23:39 +00003631 enforceTelephonyFeatureWithException(callingPackage,
3632 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003633
3634 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003635 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3636
3637 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3638 }
3639
3640 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003641 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003642 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003643 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644
3645 final long identity = Binder.clearCallingIdentity();
3646 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003647 Phone phone = getPhone(subId);
3648 if (phone == null) {
3649 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3650 } else {
3651 phone.setCellInfoListRate(rateInMillis, workSource);
3652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003656 }
3657
Shishir Agrawala9f32182016-04-12 12:00:16 -07003658 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003659 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003660 Phone phone = PhoneFactory.getPhone(slotIndex);
3661 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 return null;
3663 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003664 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003665 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003666 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003667 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003668 return null;
3669 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003670
joonhunshin4ac60942023-11-15 15:23:39 +00003671 enforceTelephonyFeatureWithException(callingPackage,
3672 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 return phone.getImei();
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003680 }
3681
3682 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003683 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3684 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3685 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3686 callingFeatureId, "getPrimaryImei")) {
3687 throw new SecurityException("Caller does not have permission");
3688 }
joonhunshin4ac60942023-11-15 15:23:39 +00003689
3690 enforceTelephonyFeatureWithException(callingPackage,
3691 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3692
arunvoddud5c6ce02022-12-11 06:03:12 +00003693 final long identity = Binder.clearCallingIdentity();
3694 try {
3695 for (Phone phone : PhoneFactory.getPhones()) {
3696 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3697 return phone.getImei();
3698 }
3699 }
3700 throw new UnsupportedOperationException("Operation not supported");
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
3704 }
3705
3706 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003707 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003708 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3709 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3710
David Kelly5e06a7f2018-03-12 14:10:59 +00003711 Phone phone = PhoneFactory.getPhone(slotIndex);
3712 String tac = null;
3713 if (phone != null) {
3714 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003715 try {
3716 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3717 } catch (IndexOutOfBoundsException e) {
3718 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3719 return null;
3720 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003721 }
3722 return tac;
3723 }
3724
3725 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003726 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003727 try {
3728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3729 } catch (SecurityException se) {
3730 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3731 throw new SecurityException("Package " + callingPackage + " does not belong to "
3732 + Binder.getCallingUid());
3733 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003734 Phone phone = PhoneFactory.getPhone(slotIndex);
3735 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003736 return null;
3737 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003738
Jeff Davidson913390f2018-02-23 17:11:49 -08003739 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003740 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003741 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003742 return null;
3743 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744
joonhunshin4ac60942023-11-15 15:23:39 +00003745 enforceTelephonyFeatureWithException(callingPackage,
3746 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 return phone.getMeid();
3751 } finally {
3752 Binder.restoreCallingIdentity(identity);
3753 }
Jack Yu2af8d712017-03-15 17:14:14 -07003754 }
3755
3756 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003757 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003758 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3759 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3760
David Kelly5e06a7f2018-03-12 14:10:59 +00003761 Phone phone = PhoneFactory.getPhone(slotIndex);
3762 String manufacturerCode = null;
3763 if (phone != null) {
3764 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003765 try {
3766 manufacturerCode =
3767 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3768 } catch (IndexOutOfBoundsException e) {
3769 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3770 return null;
3771 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003772 }
3773 return manufacturerCode;
3774 }
3775
3776 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003777 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3778 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003779 Phone phone = PhoneFactory.getPhone(slotIndex);
3780 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003781 return null;
3782 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003783 int subId = phone.getSubId();
3784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003785 mApp, subId, callingPackage, callingFeatureId,
3786 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003787 return null;
3788 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003789
joonhunshin4ac60942023-11-15 15:23:39 +00003790 enforceTelephonyFeatureWithException(callingPackage,
3791 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 return phone.getDeviceSvn();
3796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003799 }
3800
fionaxu43304da2017-11-27 22:51:16 -08003801 @Override
3802 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003803 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3804 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 final Phone phone = getPhone(subId);
3809 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
3812 }
fionaxu43304da2017-11-27 22:51:16 -08003813 }
3814
3815 @Override
3816 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003817 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3818 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 final Phone phone = getPhone(subId);
3823 return phone == null ? null : phone.getCarrierName();
3824 } finally {
3825 Binder.restoreCallingIdentity(identity);
3826 }
fionaxu43304da2017-11-27 22:51:16 -08003827 }
3828
calvinpanffe225e2018-11-01 19:43:06 +08003829 @Override
chen xu0026ca62019-03-06 15:28:50 -08003830 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003831 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3832 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3833
chen xu25637222018-11-04 17:17:00 -08003834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 final Phone phone = getPhone(subId);
3837 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003838 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003839 } finally {
3840 Binder.restoreCallingIdentity(identity);
3841 }
3842 }
3843
3844 @Override
chen xu0026ca62019-03-06 15:28:50 -08003845 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003846 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3847 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3848 "getSubscriptionSpecificCarrierName");
3849
chen xu25637222018-11-04 17:17:00 -08003850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003853 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003854 } finally {
3855 Binder.restoreCallingIdentity(identity);
3856 }
3857 }
3858
chen xu651eec72018-11-11 19:03:44 -08003859 @Override
chen xu864e11c2018-12-06 22:10:03 -08003860 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3861 if (!isSubscriptionMccMnc) {
3862 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3863 }
chen xu651eec72018-11-11 19:03:44 -08003864 final Phone phone = PhoneFactory.getPhone(slotIndex);
3865 if (phone == null) {
3866 return TelephonyManager.UNKNOWN_CARRIER_ID;
3867 }
joonhunshin4ac60942023-11-15 15:23:39 +00003868
3869 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3870 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3871
chen xu651eec72018-11-11 19:03:44 -08003872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
3877 }
3878 }
3879
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003880 //
3881 // Internal helper methods.
3882 //
3883
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003884 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003885 * Make sure the caller is the calling package itself
3886 *
3887 * @throws SecurityException if the caller is not the calling package
3888 */
3889 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3890 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003891 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3892 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003893 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003894 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003895 } catch (PackageManager.NameNotFoundException e) {
3896 // packageUid is -1
3897 }
3898 if (packageUid != callingUid) {
3899 throw new SecurityException(message + ": Package " + callingPackage
3900 + " does not belong to " + callingUid);
3901 }
3902 }
3903
3904 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003905 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3906 *
3907 * @throws SecurityException if the caller does not have the required permission
3908 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003909 @VisibleForTesting
3910 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003911 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3912 }
3913
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003914 /**
arunvoddud7401012022-12-15 16:08:12 +00003915 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003916 *
3917 * @throws SecurityException if the caller does not have the required permission
3918 */
3919 @VisibleForTesting
3920 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003921 enforceReadPermission(null);
3922 }
3923
3924 /**
3925 * Make sure the caller has the READ_PHONE_STATE permissions.
3926 *
3927 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3928 */
3929 @VisibleForTesting
3930 public void enforceReadPermission(String msg) {
3931 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003932 }
3933
Shuo Qian3b6ee772019-11-13 17:43:31 -08003934 private void enforceActiveEmergencySessionPermission() {
3935 mApp.enforceCallingOrSelfPermission(
3936 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3937 }
3938
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003939 /**
3940 * Make sure the caller has the CALL_PHONE permission.
3941 *
3942 * @throws SecurityException if the caller does not have the required permission
3943 */
3944 private void enforceCallPermission() {
3945 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3946 }
3947
paulhu5a773602019-08-23 19:17:33 +08003948 private void enforceSettingsPermission() {
3949 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003950 }
3951
Michele Berionne5e411512020-11-13 02:36:59 +00003952 private void enforceRebootPermission() {
3953 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3954 }
3955
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003956 /**
3957 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3958 * @param message - log message to print.
3959 * @throws SecurityException if the caller does not have the required permission
3960 */
3961 private void enforceSatelliteCommunicationPermission(String message) {
3962 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3963 }
3964
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);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004279
joonhunshin4ac60942023-11-15 15:23:39 +00004280 enforceTelephonyFeatureWithException(callingPackage,
4281 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283 final long identity = Binder.clearCallingIdentity();
4284 try {
4285 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004286 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004290 }
4291
4292 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004293 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4294 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295
joonhunshin4ac60942023-11-15 15:23:39 +00004296 enforceTelephonyFeatureWithException(callingPackage,
4297 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299 final long identity = Binder.clearCallingIdentity();
4300 try {
4301 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004302 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004303 } finally {
4304 Binder.restoreCallingIdentity(identity);
4305 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004306 }
4307
4308 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004309 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4310 String callingPackage, int subId) {
4311 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312
4313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004316 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317 } finally {
4318 Binder.restoreCallingIdentity(identity);
4319 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004320 }
4321
4322 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004323 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004324 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325
4326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004329 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 } finally {
4331 Binder.restoreCallingIdentity(identity);
4332 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004333 }
4334
4335 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004336 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4337 String callingAttributionTag, int subId, String number, int port, String text,
4338 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004339 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004340 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004341 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004342
4343 enforceTelephonyFeatureWithException(callingPackage,
4344 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4345
Amit Mahajandccb3f12019-05-13 13:48:32 -07004346 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004347 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4348 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004349 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004350
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004351 /**
fionaxu0152e512016-11-14 13:36:14 -08004352 * Sets the voice activation state of a given subId.
4353 */
4354 @Override
4355 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4357 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358
joonhunshin4ac60942023-11-15 15:23:39 +00004359 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4360 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004362 final long identity = Binder.clearCallingIdentity();
4363 try {
4364 final Phone phone = getPhone(subId);
4365 if (phone != null) {
4366 phone.setVoiceActivationState(activationState);
4367 } else {
4368 loge("setVoiceActivationState fails with invalid subId: " + subId);
4369 }
4370 } finally {
4371 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004372 }
4373 }
4374
4375 /**
4376 * Sets the data activation state of a given subId.
4377 */
4378 @Override
4379 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4381 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382
joonhunshin4ac60942023-11-15 15:23:39 +00004383 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4384 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386 final long identity = Binder.clearCallingIdentity();
4387 try {
4388 final Phone phone = getPhone(subId);
4389 if (phone != null) {
4390 phone.setDataActivationState(activationState);
4391 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004392 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393 }
4394 } finally {
4395 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004396 }
4397 }
4398
4399 /**
4400 * Returns the voice activation state of a given subId.
4401 */
4402 @Override
4403 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004404 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405
joonhunshin4ac60942023-11-15 15:23:39 +00004406 enforceTelephonyFeatureWithException(callingPackage,
4407 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4408
fionaxu0152e512016-11-14 13:36:14 -08004409 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 final long identity = Binder.clearCallingIdentity();
4411 try {
4412 if (phone != null) {
4413 return phone.getVoiceActivationState();
4414 } else {
4415 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4416 }
4417 } finally {
4418 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004419 }
4420 }
4421
4422 /**
4423 * Returns the data activation state of a given subId.
4424 */
4425 @Override
4426 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004427 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004428
joonhunshin4ac60942023-11-15 15:23:39 +00004429 enforceTelephonyFeatureWithException(callingPackage,
4430 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4431
fionaxu0152e512016-11-14 13:36:14 -08004432 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 final long identity = Binder.clearCallingIdentity();
4434 try {
4435 if (phone != null) {
4436 return phone.getDataActivationState();
4437 } else {
4438 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4439 }
4440 } finally {
4441 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004442 }
4443 }
4444
4445 /**
Wink Saville36469e72014-06-11 15:17:00 -07004446 * Returns the unread count of voicemails for a subId
4447 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004448 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004449 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4450 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004452 mApp, subId, callingPackage, callingFeatureId,
4453 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004454 return 0;
4455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 final long identity = Binder.clearCallingIdentity();
4457 try {
4458 final Phone phone = getPhone(subId);
4459 if (phone != null) {
4460 return phone.getVoiceMessageCount();
4461 } else {
4462 return 0;
4463 }
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004467 }
4468
4469 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004470 * returns true, if the device is in a state where both voice and data
4471 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004472 */
4473 @Override
4474 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004475 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4476 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 final long identity = Binder.clearCallingIdentity();
4479 try {
Ling Mac28f0212023-03-24 16:07:15 -07004480 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004484 }
4485
4486 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004487 * Send the dialer code if called from the current default dialer or the caller has
4488 * carrier privilege.
4489 * @param inputCode The dialer code to send
4490 */
4491 @Override
4492 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004493 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004494 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004495 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4496 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004497 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004498 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004499 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004500 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501
joonhunshin4ac60942023-11-15 15:23:39 +00004502 enforceTelephonyFeatureWithException(callingPackage,
4503 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004505 final long identity = Binder.clearCallingIdentity();
4506 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004507 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
fionaxu235cc5e2017-03-06 22:25:57 -08004511 }
4512
Pengquan Menga1bb6272018-09-06 09:59:22 -07004513 @Override
4514 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004515 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004516 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4517 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004518
4519 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4520 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4521
shilufc958392020-01-20 11:36:01 -08004522 final long identity = Binder.clearCallingIdentity();
4523 try {
4524 if (!isActiveSubscription(subId)) {
4525 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4526 }
4527 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4528 } finally {
4529 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004530 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004531 }
4532
Brad Ebinger35c841c2018-10-01 10:40:55 -07004533 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004534 public boolean isInEmergencySmsMode() {
4535 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004536
4537 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4538 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4539
Brad Ebingerb2b65522019-03-15 13:48:47 -07004540 final long identity = Binder.clearCallingIdentity();
4541 try {
4542 for (Phone phone : PhoneFactory.getPhones()) {
4543 if (phone.isInEmergencySmsMode()) {
4544 return true;
4545 }
4546 }
4547 } finally {
4548 Binder.restoreCallingIdentity(identity);
4549 }
4550 return false;
4551 }
4552
shilu366312e2019-12-17 09:28:10 -08004553 /**
4554 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4555 * @param subId The subscription to use to check the configuration.
4556 * @param c The callback that will be used to send the result.
4557 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004558 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004559 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4560 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004561 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004562 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004563
4564 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4565 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4566 "IMS not available on device.");
4567 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004568 final long token = Binder.clearCallingIdentity();
4569 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004570 int slotId = getSlotIndexOrException(subId);
4571 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004572
4573 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4574 if (controller != null) {
4575 ImsManager imsManager = controller.getImsManager(subId);
4576 if (imsManager != null) {
4577 imsManager.addRegistrationCallbackForSubscription(c, subId);
4578 } else {
4579 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4580 }
4581 } else {
4582 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4583 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004584 } catch (ImsException e) {
4585 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004586 } finally {
4587 Binder.restoreCallingIdentity(token);
4588 }
4589 }
4590
shilu366312e2019-12-17 09:28:10 -08004591 /**
4592 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4593 * @param subId The subscription to use to check the configuration.
4594 * @param c The callback that will be used to send the result.
4595 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004596 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004597 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004598 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004599 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004600 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4601 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4602 }
Meng Wangafbc5852019-09-19 17:37:13 -07004603 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004604
Meng Wangafbc5852019-09-19 17:37:13 -07004605 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004606 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4607 if (controller != null) {
4608 ImsManager imsManager = controller.getImsManager(subId);
4609 if (imsManager != null) {
4610 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4611 } else {
4612 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4613 + "is inactive, ignoring unregister.");
4614 // If the ImsManager is not valid, just return, since the callback
4615 // will already have been removed internally.
4616 }
4617 }
Meng Wangafbc5852019-09-19 17:37:13 -07004618 } finally {
4619 Binder.restoreCallingIdentity(token);
4620 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004621 }
4622
Brad Ebingera34a6c22019-10-22 17:36:18 -07004623 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004624 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4625 * @param subId The subscription to use to check the configuration.
4626 * @param c The callback that will be used to send the result.
4627 */
4628 @Override
4629 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4630 throws RemoteException {
4631 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4632 mApp, subId, "registerImsEmergencyRegistrationCallback");
4633
4634 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4635 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4636 "IMS not available on device.");
4637 }
4638 final long token = Binder.clearCallingIdentity();
4639 try {
4640 int slotId = getSlotIndexOrException(subId);
4641 verifyImsMmTelConfiguredOrThrow(slotId);
4642
4643 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4644 if (controller != null) {
4645 ImsManager imsManager = controller.getImsManager(subId);
4646 if (imsManager != null) {
4647 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4648 } else {
4649 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4650 }
4651 } else {
4652 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4653 }
4654 } catch (ImsException e) {
4655 throw new ServiceSpecificException(e.getCode());
4656 } finally {
4657 Binder.restoreCallingIdentity(token);
4658 }
4659 }
4660
4661 /**
4662 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4663 * @param subId The subscription to use to check the configuration.
4664 * @param c The callback that will be used to send the result.
4665 */
4666 @Override
4667 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4668 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4669 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4670 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4671 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4672 }
4673 final long token = Binder.clearCallingIdentity();
4674
4675 try {
4676 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4677 if (controller != null) {
4678 ImsManager imsManager = controller.getImsManager(subId);
4679 if (imsManager != null) {
4680 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4681 } else {
4682 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4683 + "is inactive, ignoring unregister.");
4684 // If the ImsManager is not valid, just return, since the callback
4685 // will already have been removed internally.
4686 }
4687 }
4688 } finally {
4689 Binder.restoreCallingIdentity(token);
4690 }
4691 }
4692
4693 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004694 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4695 */
4696 @Override
4697 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4698 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4699 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4700 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4701 "IMS not available on device.");
4702 }
4703 final long token = Binder.clearCallingIdentity();
4704 try {
4705 Phone phone = getPhone(subId);
4706 if (phone == null) {
4707 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4708 + subId + "'");
4709 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4710 }
4711 phone.getImsRegistrationState(regState -> {
4712 try {
4713 consumer.accept((regState == null)
4714 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4715 } catch (RemoteException e) {
4716 // Ignore if the remote process is no longer available to call back.
4717 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4718 }
4719 });
4720 } finally {
4721 Binder.restoreCallingIdentity(token);
4722 }
4723 }
4724
4725 /**
4726 * Get the transport type for the IMS service registration state.
4727 */
4728 @Override
4729 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004730 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004731 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004732 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4733 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4734 "IMS not available on device.");
4735 }
4736 final long token = Binder.clearCallingIdentity();
4737 try {
4738 Phone phone = getPhone(subId);
4739 if (phone == null) {
4740 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4741 + subId + "'");
4742 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4743 }
4744 phone.getImsRegistrationTech(regTech -> {
4745 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4746 int regTechConverted = (regTech == null)
4747 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4748 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4749 regTechConverted);
4750 try {
4751 consumer.accept(regTechConverted);
4752 } catch (RemoteException e) {
4753 // Ignore if the remote process is no longer available to call back.
4754 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4755 }
4756 });
4757 } finally {
4758 Binder.restoreCallingIdentity(token);
4759 }
4760 }
4761
shilu366312e2019-12-17 09:28:10 -08004762 /**
4763 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4764 * @param subId The subscription to use to check the configuration.
4765 * @param c The callback that will be used to send the result.
4766 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004767 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004768 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4769 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004770 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004771 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004772 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4773 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4774 "IMS not available on device.");
4775 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004776 final long token = Binder.clearCallingIdentity();
4777 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004778 int slotId = getSlotIndexOrException(subId);
4779 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004780
4781 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4782 if (controller != null) {
4783 ImsManager imsManager = controller.getImsManager(subId);
4784 if (imsManager != null) {
4785 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4786 } else {
4787 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4788 }
4789 } else {
4790 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4791 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004792 } catch (ImsException e) {
4793 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004794 } finally {
4795 Binder.restoreCallingIdentity(token);
4796 }
4797 }
4798
shilu366312e2019-12-17 09:28:10 -08004799 /**
4800 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4801 * @param subId The subscription to use to check the configuration.
4802 * @param c The callback that will be used to send the result.
4803 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004804 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004805 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004806 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004807 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004808 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4809 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4810 }
Meng Wangafbc5852019-09-19 17:37:13 -07004811
4812 final long token = Binder.clearCallingIdentity();
4813 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004814 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4815 if (controller != null) {
4816 ImsManager imsManager = controller.getImsManager(subId);
4817 if (imsManager != null) {
4818 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4819 } else {
4820 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4821 + " is inactive, ignoring unregister.");
4822 // If the ImsManager is not valid, just return, since the callback
4823 // will already have been removed internally.
4824 }
4825 }
Meng Wangafbc5852019-09-19 17:37:13 -07004826 } finally {
4827 Binder.restoreCallingIdentity(token);
4828 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004829 }
4830
4831 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004832 public boolean isCapable(int subId, int capability, int regTech) {
4833 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004834
4835 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4836 FEATURE_TELEPHONY_IMS, "isCapable");
4837
Brad Ebinger35c841c2018-10-01 10:40:55 -07004838 final long token = Binder.clearCallingIdentity();
4839 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004840 int slotId = getSlotIndexOrException(subId);
4841 verifyImsMmTelConfiguredOrThrow(slotId);
4842 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4843 } catch (com.android.ims.ImsException e) {
4844 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4845 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004846 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004847 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4848 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004849 } finally {
4850 Binder.restoreCallingIdentity(token);
4851 }
4852 }
4853
4854 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004855 public boolean isAvailable(int subId, int capability, int regTech) {
4856 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004857
4858 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4859 FEATURE_TELEPHONY_IMS, "isAvailable");
4860
Brad Ebinger35c841c2018-10-01 10:40:55 -07004861 final long token = Binder.clearCallingIdentity();
4862 try {
4863 Phone phone = getPhone(subId);
4864 if (phone == null) return false;
4865 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004866 } catch (com.android.ims.ImsException e) {
4867 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4868 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004869 } finally {
4870 Binder.restoreCallingIdentity(token);
4871 }
4872 }
4873
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004874 /**
4875 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4876 * subscription.
4877 * @param subId The subscription to use to check the configuration.
4878 * @param callback The callback that will be used to send the result.
4879 * @param capability The MmTelFeature capability that will be used to send the result.
4880 * @param transportType The transport type of the MmTelFeature capability.
4881 */
4882 @Override
4883 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4884 int transportType) {
4885 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004886 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4887 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4888 "IMS not available on device.");
4889 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004890 final long token = Binder.clearCallingIdentity();
4891 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004892 int slotId = getSlotIndex(subId);
4893 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4894 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4895 + subId + "'");
4896 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4897 }
4898 verifyImsMmTelConfiguredOrThrow(slotId);
4899 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4900 transportType, aBoolean -> {
4901 try {
4902 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4903 } catch (RemoteException e) {
4904 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4905 + "running. Ignore");
4906 }
4907 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004908 } catch (ImsException e) {
4909 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004910 } finally {
4911 Binder.restoreCallingIdentity(token);
4912 }
4913 }
4914
shilu366312e2019-12-17 09:28:10 -08004915 /**
4916 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4917 * @param subId The subscription to use to check the configuration.
4918 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004919 @Override
4920 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004921 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004922 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004923
joonhunshin4ac60942023-11-15 15:23:39 +00004924 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4925 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4926
Brad Ebinger35c841c2018-10-01 10:40:55 -07004927 final long token = Binder.clearCallingIdentity();
4928 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004929 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004930 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004931 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004932 } catch (ImsException e) {
4933 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004934 } finally {
4935 Binder.restoreCallingIdentity(token);
4936 }
4937 }
4938
4939 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004940 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004942 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004943
4944 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4945 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4946
Brad Ebinger35c841c2018-10-01 10:40:55 -07004947 final long identity = Binder.clearCallingIdentity();
4948 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004949 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004950 // This setting doesn't require an active ImsService connection, so do not verify. The
4951 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004952 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004953 } catch (ImsException e) {
4954 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004955 } finally {
4956 Binder.restoreCallingIdentity(identity);
4957 }
4958 }
4959
shilu366312e2019-12-17 09:28:10 -08004960 /**
4961 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4962 * @param subId The subscription to use to check the configuration.
4963 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004964 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004965 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004966 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004967 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004968
4969 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4970 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4971
Brad Ebinger35c841c2018-10-01 10:40:55 -07004972 final long identity = Binder.clearCallingIdentity();
4973 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004974 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004975 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004976 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004977 } catch (ImsException e) {
4978 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004979 } finally {
4980 Binder.restoreCallingIdentity(identity);
4981 }
4982 }
4983
4984 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004985 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004987 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004988
4989 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4990 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4991
Brad Ebinger35c841c2018-10-01 10:40:55 -07004992 final long identity = Binder.clearCallingIdentity();
4993 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004994 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004995 // This setting doesn't require an active ImsService connection, so do not verify. The
4996 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004997 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004998 } catch (ImsException e) {
4999 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005000 } finally {
5001 Binder.restoreCallingIdentity(identity);
5002 }
5003 }
5004
shilu366312e2019-12-17 09:28:10 -08005005 /**
5006 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5007 * @param subId The subscription to use to check the configuration.
5008 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005009 @Override
5010 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005011 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005012 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005013
5014 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5015 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5016
Brad Ebinger35c841c2018-10-01 10:40:55 -07005017 final long identity = Binder.clearCallingIdentity();
5018 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005019 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005020 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005021 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005022 } catch (ImsException e) {
5023 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
5026 }
5027 }
5028
5029 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005030 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005032 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005033
5034 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5035 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5036
Brad Ebinger35c841c2018-10-01 10:40:55 -07005037 final long identity = Binder.clearCallingIdentity();
5038 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005039 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005040 // This setting doesn't require an active ImsService connection, so do not verify. The
5041 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005042 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005043 } catch (ImsException e) {
5044 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005045 } finally {
5046 Binder.restoreCallingIdentity(identity);
5047 }
5048 }
5049
shilu366312e2019-12-17 09:28:10 -08005050 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005051 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5052 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5053 * @param subId The subscription to use to check the configuration.
5054 */
5055 @Override
5056 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005057 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005058 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005059
5060 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5061 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5062
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005063 final long identity = Binder.clearCallingIdentity();
5064 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005065 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005066 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005067 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005068 } catch (ImsException e) {
5069 throw new ServiceSpecificException(e.getCode());
5070 } finally {
5071 Binder.restoreCallingIdentity(identity);
5072 }
5073 }
5074
5075 /**
5076 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5077 * Requires MODIFY_PHONE_STATE permission.
5078 * @param subId The subscription to use to check the configuration.
5079 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5080 * false otherwise
5081 */
5082 @Override
5083 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5085 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005086
5087 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5088 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5089
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005092 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005093 // This setting doesn't require an active ImsService connection, so do not verify. The
5094 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005095 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005096 } catch (ImsException e) {
5097 throw new ServiceSpecificException(e.getCode());
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
5101 }
5102
5103 /**
shilu366312e2019-12-17 09:28:10 -08005104 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5105 * @param subId The subscription to use to check the configuration.
5106 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005107 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005108
Brad Ebinger35c841c2018-10-01 10:40:55 -07005109 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005110 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005111 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005112
5113 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5114 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5115
Brad Ebinger35c841c2018-10-01 10:40:55 -07005116 final long identity = Binder.clearCallingIdentity();
5117 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005118 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005119 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005120 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005121 } catch (ImsException e) {
5122 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005123 } finally {
5124 Binder.restoreCallingIdentity(identity);
5125 }
5126 }
5127
5128 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005129 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005131 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005132
5133 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5134 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5135
Brad Ebinger35c841c2018-10-01 10:40:55 -07005136 final long identity = Binder.clearCallingIdentity();
5137 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005138 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005139 // This setting doesn't require an active ImsService connection, so do not verify. The
5140 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005141 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005142 } catch (ImsException e) {
5143 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
5147 }
5148
5149 @Override
5150 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5152 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005153
5154 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5155 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5156
Brad Ebinger35c841c2018-10-01 10:40:55 -07005157 final long identity = Binder.clearCallingIdentity();
5158 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005159 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005160 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005161 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005162 } catch (ImsException e) {
5163 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005164 } finally {
5165 Binder.restoreCallingIdentity(identity);
5166 }
5167 }
5168
shilu366312e2019-12-17 09:28:10 -08005169 /**
5170 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5171 * @param subId The subscription to use to check the configuration.
5172 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005173 @Override
5174 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005175 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005176 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005177
5178 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5179 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5180
Brad Ebinger35c841c2018-10-01 10:40:55 -07005181 final long identity = Binder.clearCallingIdentity();
5182 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005183 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005184 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005185 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005186 } catch (ImsException e) {
5187 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005188 } finally {
5189 Binder.restoreCallingIdentity(identity);
5190 }
5191 }
5192
5193 @Override
5194 public void setVoWiFiModeSetting(int subId, int mode) {
5195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5196 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005197
5198 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5199 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5200
Brad Ebinger35c841c2018-10-01 10:40:55 -07005201 final long identity = Binder.clearCallingIdentity();
5202 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005203 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005204 // This setting doesn't require an active ImsService connection, so do not verify. The
5205 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005206 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005207 } catch (ImsException e) {
5208 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
5212 }
5213
5214 @Override
5215 public int getVoWiFiRoamingModeSetting(int subId) {
5216 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005217
5218 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5219 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5220
Brad Ebinger35c841c2018-10-01 10:40:55 -07005221 final long identity = Binder.clearCallingIdentity();
5222 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005223 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005224 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005225 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005226 } catch (ImsException e) {
5227 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
5231 }
5232
5233 @Override
5234 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5236 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005237
5238 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5239 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5240
Brad Ebinger35c841c2018-10-01 10:40:55 -07005241 final long identity = Binder.clearCallingIdentity();
5242 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005243 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005244 // This setting doesn't require an active ImsService connection, so do not verify. The
5245 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005246 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005247 } catch (ImsException e) {
5248 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
5252 }
5253
5254 @Override
5255 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5257 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005258
5259 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5260 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5261
Brad Ebinger35c841c2018-10-01 10:40:55 -07005262 final long identity = Binder.clearCallingIdentity();
5263 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005264 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005265 // This setting doesn't require an active ImsService connection, so do not verify. The
5266 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005267 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005268 } catch (ImsException e) {
5269 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
5273 }
5274
shilu366312e2019-12-17 09:28:10 -08005275 /**
5276 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5277 * @param subId The subscription to use to check the configuration.
5278 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005279 @Override
5280 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005281 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005282 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005283
5284 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5285 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5286
Brad Ebinger35c841c2018-10-01 10:40:55 -07005287 final long identity = Binder.clearCallingIdentity();
5288 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005289 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005290 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005291 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005292 } catch (ImsException e) {
5293 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
5297 }
5298
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005299 @Override
5300 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5301 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005302
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005303 final long identity = Binder.clearCallingIdentity();
5304 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005305 if (!isImsAvailableOnDevice()) {
5306 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5307 "IMS not available on device.");
5308 }
5309 int slotId = getSlotIndexOrException(subId);
5310 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005311
5312 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5313 if (controller != null) {
5314 ImsManager imsManager = controller.getImsManager(subId);
5315 if (imsManager != null) {
5316 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5317 } else {
5318 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5319 }
5320 } else {
5321 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5322 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005323 } catch (ImsException e) {
5324 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
5328 }
5329
5330 @Override
5331 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5332 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005333
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005334 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005335 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5336 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5337 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005338 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005339 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5340 if (controller != null) {
5341 ImsManager imsManager = controller.getImsManager(subId);
5342 if (imsManager != null) {
5343 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5344 } else {
5345 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5346 + " is inactive, ignoring unregister.");
5347 // If the ImsManager is not valid, just return, since the callback will already
5348 // have been removed internally.
5349 }
5350 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
5354 }
5355
joonhunshincffb7fc2021-11-28 07:32:01 +00005356 @Override
5357 public void registerFeatureProvisioningChangedCallback(int subId,
5358 IFeatureProvisioningCallback callback) {
5359 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5360 mApp, subId, "registerFeatureProvisioningChangedCallback");
5361
5362 final long identity = Binder.clearCallingIdentity();
5363 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5364 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5365 }
5366
joonhunshin91bc1952022-04-29 08:47:15 +00005367 try {
5368 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5369 if (controller == null) {
5370 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5371 "Device does not support IMS");
5372 }
5373 controller.addFeatureProvisioningChangedCallback(subId, callback);
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
5376 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005377 }
5378
5379 @Override
5380 public void unregisterFeatureProvisioningChangedCallback(int subId,
5381 IFeatureProvisioningCallback callback) {
5382 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5383 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5384
5385 final long identity = Binder.clearCallingIdentity();
5386 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5387 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5388 }
5389
joonhunshin91bc1952022-04-29 08:47:15 +00005390 try {
5391 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5392 if (controller == null) {
5393 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5394 return;
5395 }
5396 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5397 } finally {
5398 Binder.restoreCallingIdentity(identity);
5399 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005400 }
allenwtsu99c623b2020-01-03 18:24:23 +08005401
5402 private void checkModifyPhoneStatePermission(int subId, String message) {
5403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5404 message);
5405 }
5406
allenwtsu99c623b2020-01-03 18:24:23 +08005407 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005408 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005409 boolean isProvisioned) {
5410 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5411
joonhunshin4ac60942023-11-15 15:23:39 +00005412 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5413 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5414
allenwtsu99c623b2020-01-03 18:24:23 +08005415 final long identity = Binder.clearCallingIdentity();
5416 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005417 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5418 if (controller == null) {
5419 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5420 return;
5421 }
5422 controller.setRcsProvisioningStatusForCapability(
5423 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005424 } finally {
5425 Binder.restoreCallingIdentity(identity);
5426 }
allenwtsu99c623b2020-01-03 18:24:23 +08005427 }
5428
5429
5430 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005431 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5432 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5433 mApp, subId, "getRcsProvisioningStatusForCapability");
5434
joonhunshin4ac60942023-11-15 15:23:39 +00005435 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5436 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5437
allenwtsu99c623b2020-01-03 18:24:23 +08005438 final long identity = Binder.clearCallingIdentity();
5439 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005440 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5441 if (controller == null) {
5442 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5443
5444 // device does not support IMS, this method will return true always.
5445 return true;
5446 }
5447 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005448 } finally {
5449 Binder.restoreCallingIdentity(identity);
5450 }
5451 }
5452
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005453 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005454 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5455 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005456 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005457
joonhunshin4ac60942023-11-15 15:23:39 +00005458 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5459 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5460
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005461 final long identity = Binder.clearCallingIdentity();
5462 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005463 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5464 if (controller == null) {
5465 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5466 return;
5467 }
5468 controller.setImsProvisioningStatusForCapability(
5469 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005470 } finally {
5471 Binder.restoreCallingIdentity(identity);
5472 }
5473 }
5474
5475 @Override
5476 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005477 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5478 mApp, subId, "getProvisioningStatusForCapability");
5479
joonhunshin4ac60942023-11-15 15:23:39 +00005480 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5481 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5482
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005483 final long identity = Binder.clearCallingIdentity();
5484 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005485 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5486 if (controller == null) {
5487 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005488
joonhunshin91bc1952022-04-29 08:47:15 +00005489 // device does not support IMS, this method will return true always.
5490 return true;
5491 }
5492 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
5496 }
5497
5498 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005499 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5500 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5501 mApp, subId, "isProvisioningRequiredForCapability");
5502
joonhunshin4ac60942023-11-15 15:23:39 +00005503 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5504 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5505
joonhunshincffb7fc2021-11-28 07:32:01 +00005506 final long identity = Binder.clearCallingIdentity();
5507 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005508 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5509 if (controller == null) {
5510 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5511
5512 // device does not support IMS, this method will return false
5513 return false;
5514 }
5515 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005516 } finally {
5517 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005518 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005519 }
5520
5521 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005522 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5523 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5524 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005525
joonhunshin4ac60942023-11-15 15:23:39 +00005526 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5527 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5528
joonhunshincffb7fc2021-11-28 07:32:01 +00005529 final long identity = Binder.clearCallingIdentity();
5530 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005531 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5532 if (controller == null) {
5533 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5534
5535 // device does not support IMS, this method will return false
5536 return false;
5537 }
5538 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005542 }
5543
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005544 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005545 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005546 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5547 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5548 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005549 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5550 mApp, subId, "getImsProvisioningInt");
5551
joonhunshin4ac60942023-11-15 15:23:39 +00005552 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5553 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5554
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005558 int slotId = getSlotIndex(subId);
5559 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5560 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5561 + subId + "' for key:" + key);
5562 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5563 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005564
joonhunshin91bc1952022-04-29 08:47:15 +00005565 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5566 if (controller == null) {
5567 loge("getImsProvisioningInt: Device does not support IMS");
5568
5569 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5570 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5571 }
5572 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005573 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5574 return retVal;
5575 }
5576
calvinpanb5a34062021-02-08 19:59:36 +08005577 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005578 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005579 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5580 + subId + "' for key:" + key);
5581 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005582 } finally {
5583 Binder.restoreCallingIdentity(identity);
5584 }
5585 }
5586
5587 @Override
5588 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005589 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5590 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5591 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005592 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5593 mApp, subId, "getImsProvisioningString");
5594
joonhunshin4ac60942023-11-15 15:23:39 +00005595 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5596 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5597
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005601 int slotId = getSlotIndex(subId);
5602 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5603 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5604 + subId + "' for key:" + key);
5605 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5606 }
calvinpanb5a34062021-02-08 19:59:36 +08005607 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005608 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005609 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5610 + subId + "' for key:" + key);
5611 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005612 } finally {
5613 Binder.restoreCallingIdentity(identity);
5614 }
5615 }
5616
5617 @Override
5618 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005619 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5620 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5621 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5623 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005624
joonhunshin4ac60942023-11-15 15:23:39 +00005625 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5626 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5627
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005631 int slotId = getSlotIndex(subId);
5632 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5633 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5634 + subId + "' for key:" + key);
5635 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5636 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005637
joonhunshin91bc1952022-04-29 08:47:15 +00005638 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5639 if (controller == null) {
5640 loge("setImsProvisioningInt: Device does not support IMS");
5641
5642 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5643 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5644 }
5645 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005646 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5647 return retVal;
5648 }
5649
calvinpanb5a34062021-02-08 19:59:36 +08005650 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5651 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005652 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005653 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005654 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005655 } finally {
5656 Binder.restoreCallingIdentity(identity);
5657 }
5658 }
5659
5660 @Override
5661 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005662 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5663 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5664 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5666 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005667
5668 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5669 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5670
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005671 final long identity = Binder.clearCallingIdentity();
5672 try {
5673 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005674 int slotId = getSlotIndex(subId);
5675 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5676 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5677 + subId + "' for key:" + key);
5678 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5679 }
calvinpanb5a34062021-02-08 19:59:36 +08005680 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5681 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005682 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005683 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005684 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
5688 }
5689
Brad Ebinger919631e2021-06-02 17:46:35 -07005690 /**
5691 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5692 * for the given slot ID or no ImsResolver instance has been created.
5693 * @param slotId The slot ID that the IMS service is created for.
5694 * @throws ImsException If there is no ImsService configured for this slot.
5695 */
5696 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5697 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5698 ImsFeature.FEATURE_MMTEL)) {
5699 throw new ImsException("This subscription does not support MMTEL over IMS",
5700 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5701 }
5702 }
5703
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005704 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005705 int slotId = SubscriptionManager.getSlotIndex(subId);
5706 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005707 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5708 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005709 }
5710 return slotId;
5711 }
5712
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005713 private int getSlotIndex(int subId) {
5714 int slotId = SubscriptionManager.getSlotIndex(subId);
5715 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5716 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5717 }
5718 return slotId;
5719 }
5720
Wink Saville36469e72014-06-11 15:17:00 -07005721 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005722 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005723 */
5724 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005725 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5726 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005727 try {
5728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5729 } catch (SecurityException se) {
5730 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5731 throw new SecurityException("Package " + callingPackage + " does not belong to "
5732 + Binder.getCallingUid());
5733 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005734 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005735 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005736 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005737 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005738 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005739 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005740 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005741 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5742 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005743
joonhunshin4ac60942023-11-15 15:23:39 +00005744 enforceTelephonyFeatureWithException(callingPackage,
5745 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 final long identity = Binder.clearCallingIdentity();
5748 try {
5749 final Phone phone = getPhone(subId);
5750 if (phone != null) {
5751 return phone.getServiceState().getDataNetworkType();
5752 } else {
5753 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5754 }
5755 } finally {
5756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005758 }
5759
5760 /**
5761 * Returns the data network type
5762 */
5763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005764 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005765 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005766 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005767 }
5768
5769 /**
5770 * Returns the data network type for a subId
5771 */
5772 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005773 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5774 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005775 String functionName = "getDataNetworkTypeForSubscriber";
5776 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5777 mApp, functionName)) {
5778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5779 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5780 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5781 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005782 }
5783
joonhunshin4ac60942023-11-15 15:23:39 +00005784 enforceTelephonyFeatureWithException(callingPackage,
5785 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 final long identity = Binder.clearCallingIdentity();
5788 try {
5789 final Phone phone = getPhone(subId);
5790 if (phone != null) {
5791 return phone.getServiceState().getDataNetworkType();
5792 } else {
5793 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5794 }
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005798 }
5799
5800 /**
Wink Saville36469e72014-06-11 15:17:00 -07005801 * Returns the Voice network type for a subId
5802 */
5803 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005804 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5805 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005806 String functionName = "getVoiceNetworkTypeForSubscriber";
5807 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5808 mApp, functionName)) {
5809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5810 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5811 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5812 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005813 }
5814
joonhunshin4ac60942023-11-15 15:23:39 +00005815 enforceTelephonyFeatureWithException(callingPackage,
5816 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 final Phone phone = getPhone(subId);
5821 if (phone != null) {
5822 return phone.getServiceState().getVoiceNetworkType();
5823 } else {
5824 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5825 }
5826 } finally {
5827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005829 }
5830
5831 /**
5832 * @return true if a ICC card is present
5833 */
5834 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005835 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005836 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005837 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005838 }
5839
5840 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005841 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005842 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005843 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005844 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005845 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5846 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 final long identity = Binder.clearCallingIdentity();
5849 try {
5850 final Phone phone = PhoneFactory.getPhone(slotIndex);
5851 if (phone != null) {
5852 return phone.getIccCard().hasIccCard();
5853 } else {
5854 return false;
5855 }
5856 } finally {
5857 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005859 }
5860
5861 /**
5862 * Return if the current radio is LTE on CDMA. This
5863 * is a tri-state return value as for a period of time
5864 * the mode may be unknown.
5865 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005866 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005867 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005868 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005869 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005870 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005871 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5872 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5873 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005874 }
5875
Sanket Padawe356d7632015-06-22 14:03:32 -07005876 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005877 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5878 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005879 try {
5880 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5881 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005882 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5883 }
5884
joonhunshin4ac60942023-11-15 15:23:39 +00005885 enforceTelephonyFeatureWithException(callingPackage,
5886 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 final long identity = Binder.clearCallingIdentity();
5889 try {
5890 final Phone phone = getPhone(subId);
5891 if (phone == null) {
5892 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5893 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005894 return TelephonyProperties.lte_on_cdma_device()
5895 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 }
5897 } finally {
5898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005899 }
Wink Saville36469e72014-06-11 15:17:00 -07005900 }
5901
Wink Saville36469e72014-06-11 15:17:00 -07005902 /**
5903 * {@hide}
5904 * Returns Default subId, 0 in the case of single standby.
5905 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005906 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005907 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005908 }
5909
Shishir Agrawala9f32182016-04-12 12:00:16 -07005910 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005911 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005912 }
5913
Wink Savilleb564aae2014-10-23 10:18:09 -07005914 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005915 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005916 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005917
Pengquan Menge92a50d2018-09-21 15:54:48 -07005918 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005919 return getSubscriptionManagerService().isActiveSubId(subId,
5920 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005921 }
5922
Ihab Awadf2177b72013-11-25 13:33:23 -08005923 /**
5924 * @see android.telephony.TelephonyManager.WifiCallingChoices
5925 */
5926 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927 final long identity = Binder.clearCallingIdentity();
5928 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005929 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005930 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5931 getWhenToMakeWifiCallsDefaultPreference());
5932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005935 }
5936
5937 /**
5938 * @see android.telephony.TelephonyManager.WifiCallingChoices
5939 */
5940 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 final long identity = Binder.clearCallingIdentity();
5942 try {
5943 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005944 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5946 } finally {
5947 Binder.restoreCallingIdentity(identity);
5948 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005949 }
5950
Sailesh Nepald1e68152013-12-12 19:08:02 -08005951 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005952 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005953 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005954 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005955
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005956 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5957 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5958 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005959 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005960 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005961 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005962 }
5963 return PhoneFactory.getPhone(phoneId);
5964 }
5965
Shishir Agrawal566b7612013-10-28 14:41:00 -07005966 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005967 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005968 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005969
Rambo Wanga1782702021-11-10 20:15:19 -08005970 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5971 /*message=*/ "iccOpenLogicalChannel");
5972
5973 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5974 // Verify that the callingPackage in the request belongs to the calling UID
5975 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5976
joonhunshin4ac60942023-11-15 15:23:39 +00005977 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5978 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5979
Rambo Wanga1782702021-11-10 20:15:19 -08005980 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005981 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005982
Rambo Wanga1782702021-11-10 20:15:19 -08005983 private Phone getPhoneFromValidIccLogicalChannelRequest(
5984 @NonNull IccLogicalChannelRequest request, String message) {
5985 Phone phone;
5986 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5988 mApp, request.subId, message);
5989 phone = getPhoneFromSubId(request.subId);
5990 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5991 enforceModifyPermission();
5992 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5993 } else {
5994 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005995 }
Rambo Wanga1782702021-11-10 20:15:19 -08005996 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005997 }
5998
5999 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006000 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 final long identity = Binder.clearCallingIdentity();
6002 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006003 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006005 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6006 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006007 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6008 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 loge("The calling package is not allowed to access ISD-R.");
6010 throw new SecurityException(
6011 "The calling package is not allowed to access ISD-R.");
6012 }
Derek Tan740e1672017-06-27 14:56:27 -07006013 }
Derek Tan740e1672017-06-27 14:56:27 -07006014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006016 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6017 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 return response;
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006022 }
6023
6024 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006025 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006026 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6027 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6028
Rambo Wanga1782702021-11-10 20:15:19 -08006029 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6030 /*message=*/"iccCloseLogicalChannel");
6031
6032 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6033
6034 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006035 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006036
Rambo Wanga1782702021-11-10 20:15:19 -08006037 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6038 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006039 // before this feature is enabled, this API should only return false if
6040 // the operation fails instead of throwing runtime exception for
6041 // backward-compatibility.
6042 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6043 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 final long identity = Binder.clearCallingIdentity();
6045 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006046 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006047 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 }
Chen Xue9d737e2022-01-01 23:41:31 -08006049 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006050 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006051 Boolean success = false;
6052 if (result instanceof RuntimeException) {
6053 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006054 if (shouldThrowExceptionOnFailure) {
6055 throw (RuntimeException) result;
6056 } else {
6057 return false;
6058 }
Chen Xue9d737e2022-01-01 23:41:31 -08006059 } else if (result instanceof Boolean) {
6060 success = (Boolean) result;
6061 } else {
6062 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6063 }
Rambo Wanga1782702021-11-10 20:15:19 -08006064 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 return success;
6066 } finally {
6067 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006068 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006069 }
6070
6071 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006072 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006073 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6075 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006076
6077 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6078 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6079
Jordan Liu4c733742019-02-28 12:03:40 -08006080 if (DBG) {
6081 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6082 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6083 + p3 + " data=" + data);
6084 }
6085 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6086 command, p1, p2, p3, data);
6087 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006088
Jordan Liu4c733742019-02-28 12:03:40 -08006089 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006090 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006091 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006092 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006093
6094 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6095 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6096 "iccTransmitApduLogicalChannelBySlot");
6097
Jordan Liu4c733742019-02-28 12:03:40 -08006098 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006099 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006100 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6101 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006102 }
6103 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006104 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6105 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006106 }
6107
6108 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6109 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 final long identity = Binder.clearCallingIdentity();
6111 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006112 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 return "";
6114 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006117 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6118 null /* workSource */);
6119 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 // Append the returned status code to the end of the response payload.
6122 String s = Integer.toHexString(
6123 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6124 if (response.payload != null) {
6125 s = IccUtils.bytesToHexString(response.payload) + s;
6126 }
6127 return s;
6128 } finally {
6129 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006130 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006131 }
Jake Hambye994d462014-02-03 13:10:13 -08006132
Evan Charltonc66da362014-05-16 14:06:40 -07006133 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006134 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6135 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6137 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006139
6140 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6141 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6142
Jordan Liu4c733742019-02-28 12:03:40 -08006143 if (DBG) {
6144 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6145 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6146 }
6147 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6148 cla, command, p1, p2, p3, data);
6149 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006150
Jordan Liu4c733742019-02-28 12:03:40 -08006151 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006152 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006153 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006154 enforceModifyPermission();
6155 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006156
6157 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6158 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6159
Jordan Liu4c733742019-02-28 12:03:40 -08006160 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006161 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006162 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6163 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006164 }
6165
6166 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006167 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6168 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006169 }
6170
6171 // open APDU basic channel assuming the caller has sufficient permissions
6172 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6173 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006174 final long identity = Binder.clearCallingIdentity();
6175 try {
6176 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6177 && TextUtils.equals(ISDR_AID, data)) {
6178 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006179 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6180 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181 if (bestComponent == null
6182 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6183 loge("The calling package is not allowed to select ISD-R.");
6184 throw new SecurityException(
6185 "The calling package is not allowed to select ISD-R.");
6186 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006187 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006190 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6191 null /* workSource */);
6192 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006194 // Append the returned status code to the end of the response payload.
6195 String s = Integer.toHexString(
6196 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6197 if (response.payload != null) {
6198 s = IccUtils.bytesToHexString(response.payload) + s;
6199 }
6200 return s;
6201 } finally {
6202 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006203 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006204 }
6205
6206 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006207 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006208 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6210 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006211
joonhunshin4ac60942023-11-15 15:23:39 +00006212 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6213 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006215 final long identity = Binder.clearCallingIdentity();
6216 try {
6217 if (DBG) {
6218 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6219 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6220 }
6221
6222 IccIoResult response =
6223 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6224 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6225 subId);
6226
6227 if (DBG) {
6228 log("Exchange SIM_IO [R]" + response);
6229 }
6230
6231 byte[] result = null;
6232 int length = 2;
6233 if (response.payload != null) {
6234 length = 2 + response.payload.length;
6235 result = new byte[length];
6236 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6237 } else {
6238 result = new byte[length];
6239 }
6240
6241 result[length - 1] = (byte) response.sw2;
6242 result[length - 2] = (byte) response.sw1;
6243 return result;
6244 } finally {
6245 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006246 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006247 }
6248
Nathan Haroldb3014052017-01-25 15:57:32 -08006249 /**
6250 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6251 * on a particular subscription
6252 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006253 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6254 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006256 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006257 return null;
6258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259
joonhunshin4ac60942023-11-15 15:23:39 +00006260 enforceTelephonyFeatureWithException(callingPackage,
6261 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006263 final long identity = Binder.clearCallingIdentity();
6264 try {
6265 if (appType != TelephonyManager.APPTYPE_USIM
6266 && appType != TelephonyManager.APPTYPE_SIM) {
6267 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6268 return null;
6269 }
6270 Object response = sendRequest(
6271 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6272 if (response instanceof String[]) {
6273 return (String[]) response;
6274 }
yincheng zhao2737e882019-09-06 17:06:54 -07006275 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006277 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278 } finally {
6279 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006280 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006281 }
6282
yincheng zhao2737e882019-09-06 17:06:54 -07006283 /**
6284 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6285 * subscription.
6286 *
6287 * @param subId the id of the subscription.
6288 * @param appType the uicc app type, must be USIM or SIM.
6289 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6290 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006291 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006292 * @return number of fplmns that is successfully written to the SIM.
6293 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006294 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6295 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6297 mApp, subId, "setForbiddenPlmns");
6298
joonhunshin4ac60942023-11-15 15:23:39 +00006299 enforceTelephonyFeatureWithException(callingPackage,
6300 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6301
yincheng zhao2737e882019-09-06 17:06:54 -07006302 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6303 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6304 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6305 }
6306 if (fplmns == null) {
6307 throw new IllegalArgumentException("Fplmn List provided is null");
6308 }
6309 for (String fplmn : fplmns) {
6310 if (!CellIdentity.isValidPlmn(fplmn)) {
6311 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6312 }
6313 }
6314 final long identity = Binder.clearCallingIdentity();
6315 try {
6316 Object response = sendRequest(
6317 CMD_SET_FORBIDDEN_PLMNS,
6318 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6319 subId);
6320 return (int) response;
6321 } finally {
6322 Binder.restoreCallingIdentity(identity);
6323 }
6324 }
6325
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006326 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006327 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6329 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006330
joonhunshin4ac60942023-11-15 15:23:39 +00006331 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6332 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6337 if (response.payload == null) {
6338 return "";
6339 }
Evan Charltonc66da362014-05-16 14:06:40 -07006340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341 // Append the returned status code to the end of the response payload.
6342 String s = Integer.toHexString(
6343 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6344 s = IccUtils.bytesToHexString(response.payload) + s;
6345 return s;
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
Evan Charltonc66da362014-05-16 14:06:40 -07006349 }
6350
Jake Hambye994d462014-02-03 13:10:13 -08006351 /**
6352 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6353 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6354 *
6355 * @param itemID the ID of the item to read
6356 * @return the NV item as a String, or null on error.
6357 */
6358 @Override
6359 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006360 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6362 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363
6364 final long identity = Binder.clearCallingIdentity();
6365 try {
6366 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006367 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6369 return value;
6370 } finally {
6371 Binder.restoreCallingIdentity(identity);
6372 }
Jake Hambye994d462014-02-03 13:10:13 -08006373 }
6374
6375 /**
6376 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6377 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6378 *
6379 * @param itemID the ID of the item to read
6380 * @param itemValue the value to write, as a String
6381 * @return true on success; false on any failure
6382 */
6383 @Override
6384 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006385 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6387 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388
6389 final long identity = Binder.clearCallingIdentity();
6390 try {
6391 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6392 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006393 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6395 return success;
6396 } finally {
6397 Binder.restoreCallingIdentity(identity);
6398 }
Jake Hambye994d462014-02-03 13:10:13 -08006399 }
6400
6401 /**
6402 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6403 * Used for device configuration by some CDMA operators.
6404 *
6405 * @param preferredRoamingList byte array containing the new PRL
6406 * @return true on success; false on any failure
6407 */
6408 @Override
6409 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6411 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412
6413 final long identity = Binder.clearCallingIdentity();
6414 try {
6415 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6416 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6417 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6418 return success;
6419 } finally {
6420 Binder.restoreCallingIdentity(identity);
6421 }
Jake Hambye994d462014-02-03 13:10:13 -08006422 }
6423
6424 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006425 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006426 * Used for device configuration by some CDMA operators.
6427 *
chen xu6dac5ab2018-10-26 17:39:23 -07006428 * @param slotIndex - device slot.
6429 *
Jake Hambye994d462014-02-03 13:10:13 -08006430 * @return true on success; false on any failure
6431 */
6432 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006433 public boolean resetModemConfig(int slotIndex) {
6434 Phone phone = PhoneFactory.getPhone(slotIndex);
6435 if (phone != null) {
6436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6437 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006438
joonhunshin4ac60942023-11-15 15:23:39 +00006439 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6440 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6441
chen xu6dac5ab2018-10-26 17:39:23 -07006442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6445 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6446 return success;
6447 } finally {
6448 Binder.restoreCallingIdentity(identity);
6449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450 }
chen xu6dac5ab2018-10-26 17:39:23 -07006451 return false;
6452 }
6453
6454 /**
6455 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6456 *
6457 * @param slotIndex - device slot.
6458 *
6459 * @return true on success; false on any failure
6460 */
6461 @Override
6462 public boolean rebootModem(int slotIndex) {
6463 Phone phone = PhoneFactory.getPhone(slotIndex);
6464 if (phone != null) {
6465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6466 mApp, phone.getSubId(), "rebootModem");
6467
joonhunshin4ac60942023-11-15 15:23:39 +00006468 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6469 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6470
chen xu6dac5ab2018-10-26 17:39:23 -07006471 final long identity = Binder.clearCallingIdentity();
6472 try {
6473 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6474 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6475 return success;
6476 } finally {
6477 Binder.restoreCallingIdentity(identity);
6478 }
6479 }
6480 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006481 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006482
Brad Ebinger51f743a2017-01-23 13:50:20 -08006483 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006484 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6485 * {@link #disableIms(int)}.
6486 * @param slotIndex device slot.
6487 */
6488 public void resetIms(int slotIndex) {
6489 enforceModifyPermission();
6490
joonhunshin4ac60942023-11-15 15:23:39 +00006491 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6492 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6493
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006494 final long identity = Binder.clearCallingIdentity();
6495 try {
6496 if (mImsResolver == null) {
6497 // may happen if the does not support IMS.
6498 return;
6499 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006500 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006501 } finally {
6502 Binder.restoreCallingIdentity(identity);
6503 }
6504 }
6505
6506 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006507 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6508 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006509 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006510 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006511 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512
6513 final long identity = Binder.clearCallingIdentity();
6514 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006515 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006516 // may happen if the device does not support IMS.
6517 return;
6518 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006519 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520 } finally {
6521 Binder.restoreCallingIdentity(identity);
6522 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006523 }
6524
6525 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006526 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6527 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006528 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006529 public void disableIms(int slotId) {
6530 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531
6532 final long identity = Binder.clearCallingIdentity();
6533 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006534 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006535 // may happen if the device does not support IMS.
6536 return;
6537 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006538 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539 } finally {
6540 Binder.restoreCallingIdentity(identity);
6541 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006542 }
6543
6544 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006545 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6546 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006547 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006548 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006549 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006550 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551
6552 final long identity = Binder.clearCallingIdentity();
6553 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006554 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006555 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6556 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006557 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006558 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559 } finally {
6560 Binder.restoreCallingIdentity(identity);
6561 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006562 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006563 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006564 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6565 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006566 @Override
6567 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006568 enforceModifyPermission();
6569
6570 final long identity = Binder.clearCallingIdentity();
6571 try {
6572 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006573 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006574 } finally {
6575 Binder.restoreCallingIdentity(identity);
6576 }
6577 }
6578
6579 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006580 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006581 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006582 */
6583 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6584 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006585
6586 final long identity = Binder.clearCallingIdentity();
6587 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006588 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006589 // may happen if the device does not support IMS.
6590 return null;
6591 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006592 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593 } finally {
6594 Binder.restoreCallingIdentity(identity);
6595 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006596 }
6597
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006598 /**
6599 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006600 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006601 */
6602 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6603 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604
6605 final long identity = Binder.clearCallingIdentity();
6606 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006607 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006608 // may happen if the device does not support IMS.
6609 return null;
6610 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006611 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612 } finally {
6613 Binder.restoreCallingIdentity(identity);
6614 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006615 }
6616
Brad Ebinger884c07b2018-02-15 16:17:40 -08006617 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006618 * Sets the ImsService Package Name that Telephony will bind to.
6619 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006620 * @param slotIndex the slot ID that the ImsService should bind for.
6621 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006622 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006623 * @param featureTypes An integer array of feature types associated with a packageName.
6624 * @param packageName The name of the package that the current configuration will be replaced
6625 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006626 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006627 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006628 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6629 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006630 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006632 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 final long identity = Binder.clearCallingIdentity();
6635 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006636 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006637 // may happen if the device does not support IMS.
6638 return false;
6639 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006640 Map<Integer, String> featureConfig = new HashMap<>();
6641 for (int featureType : featureTypes) {
6642 featureConfig.put(featureType, packageName);
6643 }
6644 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6645 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646 } finally {
6647 Binder.restoreCallingIdentity(identity);
6648 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006649 }
6650
6651 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006652 * Clears any carrier ImsService overrides for the slot index specified that were previously
6653 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6654 *
6655 * This should only be used for testing.
6656 *
6657 * @param slotIndex the slot ID that the ImsService should bind for.
6658 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6659 */
6660 @Override
6661 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006662 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6663 "clearCarrierImsServiceOverride");
6664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006665 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006666
6667 final long identity = Binder.clearCallingIdentity();
6668 try {
6669 if (mImsResolver == null) {
6670 // may happen if the device does not support IMS.
6671 return false;
6672 }
6673 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6674 } finally {
6675 Binder.restoreCallingIdentity(identity);
6676 }
6677 }
6678
6679 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006680 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006681 *
6682 * @param slotId The slot that the ImsService is associated with.
6683 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6684 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006685 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006686 * @return the package name of the ImsService configuration.
6687 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006688 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6689 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006690 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006691 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6692 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 final long identity = Binder.clearCallingIdentity();
6695 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006696 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006697 // may happen if the device does not support IMS.
6698 return "";
6699 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006700 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006701 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6702 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703 } finally {
6704 Binder.restoreCallingIdentity(identity);
6705 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006706 }
6707
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006708 /**
6709 * Get the MmTelFeature state associated with the requested subscription id.
6710 * @param subId The subscription that the MmTelFeature is associated with.
6711 * @param callback A callback with an integer containing the
6712 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6713 */
6714 @Override
6715 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6716 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006717 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6718 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6719 "IMS not available on device.");
6720 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006721 final long token = Binder.clearCallingIdentity();
6722 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006723 int slotId = getSlotIndex(subId);
6724 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6725 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6726 + subId + "'");
6727 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6728 }
6729 verifyImsMmTelConfiguredOrThrow(slotId);
6730 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6731 try {
6732 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6733 } catch (RemoteException e) {
6734 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6735 + "Ignore");
6736 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006737 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006738 } catch (ImsException e) {
6739 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006740 } finally {
6741 Binder.restoreCallingIdentity(token);
6742 }
6743 }
6744
Daniel Brightbb5840b2021-01-12 15:48:18 -08006745 /**
6746 * Sets the ims registration state on all valid {@link Phone}s.
6747 */
6748 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006749 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750
6751 final long identity = Binder.clearCallingIdentity();
6752 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006753 // NOTE: Before S, this method only set the default phone.
6754 for (final Phone phone : PhoneFactory.getPhones()) {
6755 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6756 phone.setImsRegistrationState(registered);
6757 }
6758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
Wink Saville36469e72014-06-11 15:17:00 -07006762 }
6763
6764 /**
Stuart Scott54788802015-03-30 13:18:01 -07006765 * Set the network selection mode to automatic.
6766 *
6767 */
6768 @Override
6769 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6771 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772
joonhunshin4ac60942023-11-15 15:23:39 +00006773 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6774 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006776 final long identity = Binder.clearCallingIdentity();
6777 try {
shilufc958392020-01-20 11:36:01 -08006778 if (!isActiveSubscription(subId)) {
6779 return;
6780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006782 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6783 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
Stuart Scott54788802015-03-30 13:18:01 -07006787 }
6788
Jack Yud10cdd42020-09-28 20:28:01 -07006789 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006790 * Ask the radio to connect to the input network and change selection mode to manual.
6791 *
6792 * @param subId the id of the subscription.
6793 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6794 * the operator to attach to.
6795 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6796 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6797 * normal network selection next time.
6798 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006799 */
6800 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006801 public boolean setNetworkSelectionModeManual(
6802 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6804 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006805
joonhunshin4ac60942023-11-15 15:23:39 +00006806 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6807 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6808
Jack Yu285100e2022-12-02 22:48:35 -08006809 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006810 if (!isActiveSubscription(subId)) {
6811 return false;
6812 }
6813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006815 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006817 if (DBG) {
6818 log("setNetworkSelectionModeManual: subId: " + subId
6819 + " operator: " + operatorInfo);
6820 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6822 } finally {
6823 Binder.restoreCallingIdentity(identity);
6824 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006825 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006826 /**
shilu84f6e8b2019-12-19 13:58:01 -08006827 * Get the manual network selection
6828 *
6829 * @param subId the id of the subscription.
6830 *
6831 * @return the previously saved user selected PLMN
6832 */
6833 @Override
6834 public String getManualNetworkSelectionPlmn(int subId) {
6835 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006836 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6837 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006838
joonhunshin4ac60942023-11-15 15:23:39 +00006839 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6840 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6841
shilu84f6e8b2019-12-19 13:58:01 -08006842 final long identity = Binder.clearCallingIdentity();
6843 try {
6844 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006845 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006846 }
6847
6848 final Phone phone = getPhone(subId);
6849 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006850 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006851 }
6852 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6853 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006854 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006855 } finally {
6856 Binder.restoreCallingIdentity(identity);
6857 }
6858 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006859
6860 /**
6861 * Scans for available networks.
6862 */
6863 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006864 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6865 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6867 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006868 LocationAccessPolicy.LocationPermissionResult locationResult =
6869 LocationAccessPolicy.checkLocationPermission(mApp,
6870 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6871 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006872 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006873 .setCallingPid(Binder.getCallingPid())
6874 .setCallingUid(Binder.getCallingUid())
6875 .setMethod("getCellNetworkScanResults")
6876 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006877 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6878 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006879 .build());
6880 switch (locationResult) {
6881 case DENIED_HARD:
6882 throw new SecurityException("Not allowed to access scan results -- location");
6883 case DENIED_SOFT:
6884 return null;
6885 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886
Pengquan Menga1bb6272018-09-06 09:59:22 -07006887 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 try {
6889 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006890 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006892 } finally {
6893 Binder.restoreCallingIdentity(identity);
6894 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006895 }
6896
6897 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006898 * Get the call forwarding info, given the call forwarding reason.
6899 */
6900 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006901 public void getCallForwarding(int subId, int callForwardingReason,
6902 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006903 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006904
6905 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6906 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6907
Shuo Qian4a594052020-01-23 11:59:30 -08006908 long identity = Binder.clearCallingIdentity();
6909 try {
6910 if (DBG) {
6911 log("getCallForwarding: subId " + subId
6912 + " callForwardingReason" + callForwardingReason);
6913 }
Hall Liu27d24262020-09-18 19:04:59 -07006914
6915 Phone phone = getPhone(subId);
6916 if (phone == null) {
6917 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006918 callback.onError(
6919 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006920 } catch (RemoteException e) {
6921 // ignore
6922 }
6923 return;
6924 }
6925
6926 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6927 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6928 @Override
6929 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6930 try {
6931 callback.onCallForwardingInfoAvailable(info);
6932 } catch (RemoteException e) {
6933 // ignore
6934 }
6935 }
6936
6937 @Override
6938 public void onError(int error) {
6939 try {
6940 callback.onError(error);
6941 } catch (RemoteException e) {
6942 // ignore
6943 }
6944 }
6945 });
6946 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006947 } finally {
6948 Binder.restoreCallingIdentity(identity);
6949 }
6950 }
6951
6952 /**
6953 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6954 * reason, the number to forward, and the timeout before the forwarding is attempted.
6955 */
6956 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006957 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6958 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006959 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006960
6961 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6962 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6963
Shuo Qian4a594052020-01-23 11:59:30 -08006964 long identity = Binder.clearCallingIdentity();
6965 try {
6966 if (DBG) {
6967 log("setCallForwarding: subId " + subId
6968 + " callForwardingInfo" + callForwardingInfo);
6969 }
Hall Liu27d24262020-09-18 19:04:59 -07006970
6971 Phone phone = getPhone(subId);
6972 if (phone == null) {
6973 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006974 callback.accept(
6975 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006976 } catch (RemoteException e) {
6977 // ignore
6978 }
6979 return;
6980 }
6981
6982 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6983 FunctionalUtils.ignoreRemoteException(callback::accept));
6984
6985 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006986 } finally {
6987 Binder.restoreCallingIdentity(identity);
6988 }
6989 }
6990
6991 /**
Hall Liu27d24262020-09-18 19:04:59 -07006992 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006993 */
6994 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006995 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006996 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006997
6998 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6999 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7000
Shuo Qian4a594052020-01-23 11:59:30 -08007001 long identity = Binder.clearCallingIdentity();
7002 try {
Hall Liu27d24262020-09-18 19:04:59 -07007003 Phone phone = getPhone(subId);
7004 if (phone == null) {
7005 try {
7006 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7007 } catch (RemoteException e) {
7008 // ignore
7009 }
7010 return;
7011 }
SongFerngWang0e767992021-03-31 22:08:45 +08007012 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7013 PersistableBundle c = configManager.getConfigForSubId(subId);
7014 boolean requireUssd = c.getBoolean(
7015 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007016
Shuo Qian4a594052020-01-23 11:59:30 -08007017 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007018 if (requireUssd) {
7019 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7020 getSubscriptionCarrierId(subId));
7021 String newUssdCommand = "";
7022 try {
7023 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007024 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007025 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7026 } catch (NullPointerException e) {
7027 loge("Failed to generate USSD number" + e);
7028 }
7029 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7030 mMainThreadHandler, callback, carrierXmlParser,
7031 CarrierXmlParser.SsEntry.SSAction.QUERY);
7032 final String ussdCommand = newUssdCommand;
7033 Executors.newSingleThreadExecutor().execute(() -> {
7034 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7035 });
7036 } else {
7037 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7038 callback::accept);
7039 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7040 }
Shuo Qian4a594052020-01-23 11:59:30 -08007041 } finally {
7042 Binder.restoreCallingIdentity(identity);
7043 }
7044 }
7045
7046 /**
Hall Liu27d24262020-09-18 19:04:59 -07007047 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007048 */
7049 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007050 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007051 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007052
7053 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7054 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7055
Shuo Qian4a594052020-01-23 11:59:30 -08007056 long identity = Binder.clearCallingIdentity();
7057 try {
Hall Liu27d24262020-09-18 19:04:59 -07007058 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7059
7060 Phone phone = getPhone(subId);
7061 if (phone == null) {
7062 try {
7063 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7064 } catch (RemoteException e) {
7065 // ignore
7066 }
7067 return;
7068 }
7069
SongFerngWang0e767992021-03-31 22:08:45 +08007070 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7071 PersistableBundle c = configManager.getConfigForSubId(subId);
7072 boolean requireUssd = c.getBoolean(
7073 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007074
SongFerngWang0e767992021-03-31 22:08:45 +08007075 if (DBG) log("getCallWaitingStatus: subId " + subId);
7076 if (requireUssd) {
7077 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7078 getSubscriptionCarrierId(subId));
7079 CarrierXmlParser.SsEntry.SSAction ssAction =
7080 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7081 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7082 String newUssdCommand = "";
7083 try {
7084 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007085 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007086 .makeCommand(ssAction, null);
7087 } catch (NullPointerException e) {
7088 loge("Failed to generate USSD number" + e);
7089 }
7090 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7091 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7092 final String ussdCommand = newUssdCommand;
7093 Executors.newSingleThreadExecutor().execute(() -> {
7094 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7095 });
7096 } else {
7097 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7098 FunctionalUtils.ignoreRemoteException(callback::accept));
7099
7100 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7101 }
Shuo Qian4a594052020-01-23 11:59:30 -08007102 } finally {
7103 Binder.restoreCallingIdentity(identity);
7104 }
7105 }
7106
7107 /**
yinxub1bed742017-04-17 11:45:04 -07007108 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007109 *
yinxub1bed742017-04-17 11:45:04 -07007110 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007111 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7112 * location related information which will be sent if the caller already possess
7113 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007114 * @param request contains the radio access networks with bands/channels to scan
7115 * @param messenger callback messenger for scan results or errors
7116 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007117 * @return the id of the requested scan which can be used to stop the scan.
7118 */
7119 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007120 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7121 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007122 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7124 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007125 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007126 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7127 if (!renounceFineLocationAccess) {
7128 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007129 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7130 .setCallingPackage(callingPackage)
7131 .setCallingFeatureId(callingFeatureId)
7132 .setCallingPid(Binder.getCallingPid())
7133 .setCallingUid(Binder.getCallingUid())
7134 .setMethod("requestNetworkScan")
7135 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7136 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7137 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7138 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007139 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007140 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007141 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7142 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007143 if (e != null) {
7144 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7145 throw e;
7146 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007147 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007148 return TelephonyScanManager.INVALID_SCAN_ID;
7149 }
7150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 }
joonhunshin4ac60942023-11-15 15:23:39 +00007152
7153 enforceTelephonyFeatureWithException(callingPackage,
7154 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7155
Hall Liu912dfd32019-04-25 14:02:26 -07007156 int callingUid = Binder.getCallingUid();
7157 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007158 final long identity = Binder.clearCallingIdentity();
7159 try {
7160 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007161 renounceFineLocationAccess, request, messenger, binder,
7162 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007163 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007164 } finally {
7165 Binder.restoreCallingIdentity(identity);
7166 }
yinxu504e1392017-04-12 16:03:22 -07007167 }
7168
Hall Liub2ac8ef2019-02-28 15:56:23 -08007169 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007170 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007171 boolean hasCarrierPriv;
7172 final long identity = Binder.clearCallingIdentity();
7173 try {
7174 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7175 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7176 } finally {
7177 Binder.restoreCallingIdentity(identity);
7178 }
Hall Liu558027f2019-05-15 19:14:05 -07007179 boolean hasNetworkScanPermission =
7180 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007181 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007182
7183 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7184 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7185 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007186 }
7187
7188 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7189 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007190 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7191 return new SecurityException("Specific channels must not be"
7192 + " scanned without location access.");
7193 }
7194 }
7195 }
7196
Hall Liub2ac8ef2019-02-28 15:56:23 -08007197 return null;
7198 }
7199
yinxu504e1392017-04-12 16:03:22 -07007200 /**
7201 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007202 *
7203 * @param subId id of the subscription
7204 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007205 */
7206 @Override
7207 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7209 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210
Hall Liu912dfd32019-04-25 14:02:26 -07007211 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212 final long identity = Binder.clearCallingIdentity();
7213 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007214 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007215 } finally {
7216 Binder.restoreCallingIdentity(identity);
7217 }
yinxu504e1392017-04-12 16:03:22 -07007218 }
7219
7220 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007221 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007222 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007223 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007224 */
7225 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007226 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007227 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007228 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007229 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230
joonhunshin4ac60942023-11-15 15:23:39 +00007231 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7232 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234 final long identity = Binder.clearCallingIdentity();
7235 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007236 if (DBG) log("getAllowedNetworkTypesBitmask");
7237 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7238 int networkTypesBitmask = (result != null ? result[0] : -1);
7239 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7240 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007244 }
7245
7246 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007247 * Get the allowed network types for certain reason.
7248 *
7249 * @param subId the id of the subscription.
7250 * @param reason the reason the allowed network type change is taking place
7251 * @return the allowed network types.
7252 */
7253 @Override
7254 public long getAllowedNetworkTypesForReason(int subId,
7255 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007256 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007257 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007258
7259 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7260 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7261
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007262 final long identity = Binder.clearCallingIdentity();
7263 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007264 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007265 } finally {
7266 Binder.restoreCallingIdentity(identity);
7267 }
7268 }
7269
7270 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007271 * Enable/Disable E-UTRA-NR Dual Connectivity
7272 * @param subId subscription id of the sim card
7273 * @param nrDualConnectivityState expected NR dual connectivity state
7274 * This can be passed following states
7275 * <ol>
7276 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7277 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7278 * <li>Disable NR dual connectivity and force secondary cell to be released
7279 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7280 * </ol>
7281 * @return operation result.
7282 */
7283 @Override
7284 public int setNrDualConnectivityState(int subId,
7285 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7287 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007288 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007289 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7290 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7291 }
7292
Sooraj Sasindran37444802020-08-11 10:40:43 -07007293 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7294 final long identity = Binder.clearCallingIdentity();
7295 try {
7296 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7297 nrDualConnectivityState, subId,
7298 workSource);
7299 if (DBG) log("enableNRDualConnectivity result: " + result);
7300 return result;
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
7303 }
7304 }
7305
7306 /**
7307 * Is E-UTRA-NR Dual Connectivity enabled
7308 * @return true if dual connectivity is enabled else false
7309 */
7310 @Override
7311 public boolean isNrDualConnectivityEnabled(int subId) {
7312 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007313 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007314 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007315 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007316 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7317 return false;
7318 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007319 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7320 final long identity = Binder.clearCallingIdentity();
7321 try {
7322 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7323 null, subId, workSource);
7324 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7325 return isEnabled;
7326 } finally {
7327 Binder.restoreCallingIdentity(identity);
7328 }
7329 }
7330
7331 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007332 * Set the allowed network types of the device and
7333 * provide the reason triggering the allowed network change.
7334 *
7335 * @param subId the id of the subscription.
7336 * @param reason the reason the allowed network type change is taking place
7337 * @param allowedNetworkTypes the allowed network types.
7338 * @return true on success; false on any failure.
7339 */
7340 @Override
7341 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007342 @TelephonyManager.AllowedNetworkTypesReason int reason,
7343 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7345 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007346 // If the caller only has carrier privileges, then they should not be able to override
7347 // any network types which were set for security reasons.
7348 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7349 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007350 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007351 throw new SecurityException(
7352 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007353 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007354 }
joonhunshin4ac60942023-11-15 15:23:39 +00007355
7356 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7357 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7358
SongFerngWang3ef3e072020-12-21 16:41:52 +08007359 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007360 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007361 return false;
7362 }
7363 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7364 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007365 return false;
7366 }
7367
Jack Yu5b494332023-01-23 18:18:04 +00007368 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7369 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007370
Jack Yue37dd262022-12-16 11:53:37 -08007371 Phone phone = getPhone(subId);
7372 if (phone == null) {
7373 return false;
7374 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007375
Jack Yue37dd262022-12-16 11:53:37 -08007376 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007377 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007378 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007379 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007380
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007381 final long identity = Binder.clearCallingIdentity();
7382 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007383 Boolean success = (Boolean) sendRequest(
7384 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7385 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7386
7387 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7388 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007389 } finally {
7390 Binder.restoreCallingIdentity(identity);
7391 }
7392 }
7393
7394 /**
Miaoa84611c2019-03-15 09:21:10 +08007395 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007396 *
Miaoa84611c2019-03-15 09:21:10 +08007397 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007398 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007399 * @hide
7400 */
7401 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007402 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007403 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007404
7405 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7406 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007408 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007409 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 try {
Miaoa84611c2019-03-15 09:21:10 +08007411 if (phone != null) {
7412 return phone.hasMatchedTetherApnSetting();
7413 } else {
7414 return false;
7415 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416 } finally {
7417 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007418 }
Junda Liu475951f2014-11-07 16:45:03 -08007419 }
7420
7421 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007422 * Get the user enabled state of Mobile Data.
7423 *
7424 * TODO: remove and use isUserDataEnabled.
7425 * This can't be removed now because some vendor codes
7426 * calls through ITelephony directly while they should
7427 * use TelephonyManager.
7428 *
7429 * @return true on enabled
7430 */
7431 @Override
7432 public boolean getDataEnabled(int subId) {
7433 return isUserDataEnabled(subId);
7434 }
7435
7436 /**
7437 * Get whether mobile data is enabled per user setting.
7438 *
7439 * There are other factors deciding whether mobile data is actually enabled, but they are
7440 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007441 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007442 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7443 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007444 *
7445 * @return {@code true} if data is enabled else {@code false}
7446 */
7447 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007448 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007449 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007450 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007451 try {
7452 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7453 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007454 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007455 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7456 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007457 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007459 mApp, subId, functionName);
7460
Robert Greenwalt646120a2014-05-23 11:54:03 -07007461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462
7463 final long identity = Binder.clearCallingIdentity();
7464 try {
Jack Yu285100e2022-12-02 22:48:35 -08007465 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7467 Phone phone = PhoneFactory.getPhone(phoneId);
7468 if (phone != null) {
7469 boolean retVal = phone.isUserDataEnabled();
7470 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7471 return retVal;
7472 } else {
7473 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7474 return false;
7475 }
7476 } finally {
7477 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007478 }
7479 }
7480
7481 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007482 * Checks if the device is capable of mobile data by considering whether whether the
7483 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7484 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007485 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007486 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007487 */
7488 @Override
7489 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007490 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007491 try {
7492 try {
7493 mApp.enforceCallingOrSelfPermission(
7494 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007495 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007496 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007497 try {
7498 mApp.enforceCallingOrSelfPermission(
7499 android.Manifest.permission.READ_PHONE_STATE,
7500 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007501 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007502 mApp.enforceCallingOrSelfPermission(
7503 permission.READ_BASIC_PHONE_STATE, functionName);
7504 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007505 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007506 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007507 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007508 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509
joonhunshin4ac60942023-11-15 15:23:39 +00007510 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7511 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513 final long identity = Binder.clearCallingIdentity();
7514 try {
Jack Yu285100e2022-12-02 22:48:35 -08007515 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 Phone phone = PhoneFactory.getPhone(phoneId);
7517 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007518 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007519 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 return retVal;
7521 } else {
7522 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7523 return false;
7524 }
7525 } finally {
7526 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007527 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007528 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007529
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007530 /**
7531 * Check if data is enabled for a specific reason
7532 * @param subId Subscription index
7533 * @param reason the reason the data enable change is taking place
7534 * @return {@code true} if the overall data is enabled; {@code false} if not.
7535 */
7536 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007537 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007538 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007539 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007540 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007541 try {
7542 mApp.enforceCallingOrSelfPermission(
7543 android.Manifest.permission.ACCESS_NETWORK_STATE,
7544 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007545 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007546 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7547 functionName);
7548 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007549 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007550 try {
7551 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007552 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007553 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007555 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007556 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007557 }
7558
joonhunshin4ac60942023-11-15 15:23:39 +00007559 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7560 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007561
7562 final long identity = Binder.clearCallingIdentity();
7563 try {
Jack Yu285100e2022-12-02 22:48:35 -08007564 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007565 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007566 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007567 + " reason=" + reason);
7568 }
7569 Phone phone = PhoneFactory.getPhone(phoneId);
7570 if (phone != null) {
7571 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007572 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007573 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007574 return retVal;
7575 } else {
7576 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007577 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007578 + subId + " retVal=false");
7579 }
7580 return false;
7581 }
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
7585 }
7586
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007587 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007588 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007589 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7590 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7591
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007592 // No permission needed; this only lets the caller inspect their own status.
7593 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007594 }
Junda Liu29340342014-07-10 15:23:27 -07007595
7596 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007597 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007598 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007599
7600 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7601 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7602
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007603 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7604 }
7605
7606 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7607 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007608 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007609 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007610 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7611 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007612 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7613 if (cpt == null) {
7614 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007615 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7616 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007617 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007618 }
7619
7620 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007621 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007622 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007623
7624 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7625 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7626
chen xuf7e9fe82019-05-09 19:31:02 -07007627 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007628 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007629 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007630 Phone phone = getPhone(subId);
7631 if (phone == null) {
7632 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7633 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7634 }
7635 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7636 if (cpt == null) {
7637 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007638 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7639 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007640 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007641 }
7642
7643 @Override
7644 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007645 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007646
7647 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7648 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7649 "checkCarrierPrivilegesForPackageAnyPhone");
7650
Rambo Wange7209ce2022-02-23 13:41:02 -08007651 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7652 }
7653
7654 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007655 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007656 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007657 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007658 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007659 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7660 Phone phone = PhoneFactory.getPhone(phoneId);
7661 if (phone == null) {
7662 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007663 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007664 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7665 if (cpt == null) {
7666 continue;
7667 }
7668 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007669 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7670 break;
7671 }
7672 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007673 return result;
Junda Liu29340342014-07-10 15:23:27 -07007674 }
Derek Tan89e89d42014-07-08 17:00:10 -07007675
7676 @Override
Junda Liue64de782015-04-16 17:19:16 -07007677 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007678 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007679
7680 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7681 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7682 "getCarrierPackageNamesForIntentAndPhone");
7683
Rambo Wang8a247eb2022-02-08 21:11:18 +00007684 Phone phone = PhoneFactory.getPhone(phoneId);
7685 if (phone == null) {
7686 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007687 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007688 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7689 if (cpt == null) {
7690 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007691 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007692 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007693 }
7694
Amith Yamasani6e118872016-02-19 12:53:51 -08007695 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007696 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007697 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Yan Yan965c84f2024-09-24 18:14:17 -07007698
7699 enforceTelephonyFeatureWithException(
7700 getCurrentPackageName(),
7701 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7702 "getPackagesWithCarrierPrivileges");
7703
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007704 Phone phone = PhoneFactory.getPhone(phoneId);
7705 if (phone == null) {
7706 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007707 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007708 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7709 if (cpt == null) {
7710 return Collections.emptyList();
7711 }
7712 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007713 }
7714
chen xuf7e9fe82019-05-09 19:31:02 -07007715 @Override
7716 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007717 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007718
7719 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7720 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7721 "getPackagesWithCarrierPrivilegesForAllPhones");
7722
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007723 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007724 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007725 try {
7726 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7727 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7728 }
7729 } finally {
7730 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007731 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007732 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007733 }
7734
Rambo Wang6812ffb2022-03-15 16:54:17 -07007735 @Override
7736 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7737 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7738
joonhunshin4ac60942023-11-15 15:23:39 +00007739 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7740 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7741 "getCarrierServicePackageNameForLogicalSlot");
7742
Rambo Wang6812ffb2022-03-15 16:54:17 -07007743 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7744 if (phone == null) {
7745 return null;
7746 }
7747 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7748 if (cpt == null) {
7749 return null;
7750 }
7751 return cpt.getCarrierServicePackageName();
7752 }
7753
Wink Savilleb564aae2014-10-23 10:18:09 -07007754 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007755 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007756 UiccPort port = phone == null ? null : phone.getUiccPort();
7757 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007758 return null;
7759 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007760 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007761 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007762 return null;
7763 }
7764 return iccId;
7765 }
7766
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007767 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007768 public void setCallComposerStatus(int subId, int status) {
7769 enforceModifyPermission();
7770
joonhunshin4ac60942023-11-15 15:23:39 +00007771 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7772 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7773
Shuo Qiane4e11672020-12-15 22:15:33 -08007774 final long identity = Binder.clearCallingIdentity();
7775 try {
7776 Phone phone = getPhone(subId);
7777 if (phone != null) {
7778 Phone defaultPhone = phone.getImsPhone();
7779 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7780 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7781 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007782 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7783 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007784 }
7785 }
Shuo Qian284ae752020-12-22 19:10:14 -08007786 } catch (ImsException e) {
7787 throw new ServiceSpecificException(e.getCode());
7788 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007789 Binder.restoreCallingIdentity(identity);
7790 }
7791 }
7792
7793 @Override
7794 public int getCallComposerStatus(int subId) {
7795 enforceReadPrivilegedPermission("getCallComposerStatus");
7796
joonhunshin4ac60942023-11-15 15:23:39 +00007797 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7798 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7799
Shuo Qiane4e11672020-12-15 22:15:33 -08007800 final long identity = Binder.clearCallingIdentity();
7801 try {
7802 Phone phone = getPhone(subId);
7803 if (phone != null) {
7804 Phone defaultPhone = phone.getImsPhone();
7805 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7806 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7807 return imsPhone.getCallComposerStatus();
7808 }
7809 }
7810 } finally {
7811 Binder.restoreCallingIdentity(identity);
7812 }
7813 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7814 }
7815
7816 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007817 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7818 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007819 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007820 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007821
joonhunshin4ac60942023-11-15 15:23:39 +00007822 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7823 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7824 "setLine1NumberForDisplayForSubscriber");
7825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826 final long identity = Binder.clearCallingIdentity();
7827 try {
7828 final String iccId = getIccId(subId);
7829 final Phone phone = getPhone(subId);
7830 if (phone == null) {
7831 return false;
7832 }
7833 final String subscriberId = phone.getSubscriberId();
7834
7835 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007836 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837 + subscriberId + " to " + number);
7838 }
7839
7840 if (TextUtils.isEmpty(iccId)) {
7841 return false;
7842 }
7843
7844 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7845
7846 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7847 if (alphaTag == null) {
7848 editor.remove(alphaTagPrefKey);
7849 } else {
7850 editor.putString(alphaTagPrefKey, alphaTag);
7851 }
7852
7853 // Record both the line number and IMSI for this ICCID, since we need to
7854 // track all merged IMSIs based on line number
7855 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7856 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7857 if (number == null) {
7858 editor.remove(numberPrefKey);
7859 editor.remove(subscriberPrefKey);
7860 } else {
7861 editor.putString(numberPrefKey, number);
7862 editor.putString(subscriberPrefKey, subscriberId);
7863 }
7864
7865 editor.commit();
7866 return true;
7867 } finally {
7868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007869 }
Derek Tan7226c842014-07-02 17:42:23 -07007870 }
7871
7872 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007873 public String getLine1NumberForDisplay(int subId, String callingPackage,
7874 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007875 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007876 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007877 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007878 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007879 return null;
7880 }
Derek Tan97ebb422014-09-05 16:55:38 -07007881
joonhunshin4ac60942023-11-15 15:23:39 +00007882 enforceTelephonyFeatureWithException(callingPackage,
7883 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7884
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885 final long identity = Binder.clearCallingIdentity();
7886 try {
7887 String iccId = getIccId(subId);
7888 if (iccId != null) {
7889 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7890 if (DBG_MERGE) {
7891 log("getLine1NumberForDisplay returning "
7892 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7893 }
7894 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7897 return null;
7898 } finally {
7899 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007900 }
Derek Tan7226c842014-07-02 17:42:23 -07007901 }
7902
7903 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007904 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7905 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007906 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007907 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007908 return null;
7909 }
Derek Tan97ebb422014-09-05 16:55:38 -07007910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911 final long identity = Binder.clearCallingIdentity();
7912 try {
7913 String iccId = getIccId(subId);
7914 if (iccId != null) {
7915 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7916 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7917 }
7918 return null;
7919 } finally {
7920 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007921 }
Derek Tan7226c842014-07-02 17:42:23 -07007922 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007923
7924 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007925 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7926 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007927 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7928 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007930 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007931 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007932 return null;
7933 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007934
Jordan Liub49b04b2019-05-06 14:45:15 -07007935 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7936 // the process, where TelephonyManager was instantiated.
7937 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007938 final long identity = Binder.clearCallingIdentity();
7939 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007940 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007941 final TelephonyManager tele = TelephonyManager.from(context);
7942 final SubscriptionManager sub = SubscriptionManager.from(context);
7943
7944 // Figure out what subscribers are currently active
7945 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007946
Jordan Liub49b04b2019-05-06 14:45:15 -07007947 // Only consider subs which match the current subId
7948 // This logic can be simplified. See b/131189269 for progress.
7949 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007950 activeSubscriberIds.add(tele.getSubscriberId(subId));
7951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952
7953 // First pass, find a number override for an active subscriber
7954 String mergeNumber = null;
7955 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7956 for (String key : prefs.keySet()) {
7957 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7958 final String subscriberId = (String) prefs.get(key);
7959 if (activeSubscriberIds.contains(subscriberId)) {
7960 final String iccId = key.substring(
7961 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7962 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7963 mergeNumber = (String) prefs.get(numberKey);
7964 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007965 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007966 + " for active subscriber " + subscriberId);
7967 }
7968 if (!TextUtils.isEmpty(mergeNumber)) {
7969 break;
7970 }
7971 }
7972 }
7973 }
7974
7975 // Shortcut when no active merged subscribers
7976 if (TextUtils.isEmpty(mergeNumber)) {
7977 return null;
7978 }
7979
7980 // Second pass, find all subscribers under that line override
7981 final ArraySet<String> result = new ArraySet<>();
7982 for (String key : prefs.keySet()) {
7983 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7984 final String number = (String) prefs.get(key);
7985 if (mergeNumber.equals(number)) {
7986 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7987 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7988 final String subscriberId = (String) prefs.get(subscriberKey);
7989 if (!TextUtils.isEmpty(subscriberId)) {
7990 result.add(subscriberId);
7991 }
7992 }
7993 }
7994 }
7995
7996 final String[] resultArray = result.toArray(new String[result.size()]);
7997 Arrays.sort(resultArray);
7998 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007999 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008000 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8001 }
8002 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008003 } finally {
8004 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008005 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008006 }
8007
8008 @Override
zoey chen38003472019-12-13 17:16:31 +08008009 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8010 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008011
joonhunshin4ac60942023-11-15 15:23:39 +00008012 enforceTelephonyFeatureWithException(callingPackage,
8013 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8014
Malcolm Chen6ca97372019-07-01 16:28:21 -07008015 final long identity = Binder.clearCallingIdentity();
8016 try {
8017 final TelephonyManager telephonyManager = mApp.getSystemService(
8018 TelephonyManager.class);
8019 String subscriberId = telephonyManager.getSubscriberId(subId);
8020 if (subscriberId == null) {
8021 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008022 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008023 + subId);
8024 }
8025 return null;
8026 }
8027
Jack Yu3beaf9d2023-04-14 09:17:27 -07008028 final SubscriptionInfo info = getSubscriptionManagerService()
8029 .getSubscriptionInfo(subId);
8030 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008031 // If it doesn't belong to any group, return just subscriberId of itself.
8032 if (groupUuid == null) {
8033 return new String[]{subscriberId};
8034 }
8035
8036 // Get all subscriberIds from the group.
8037 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008038 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8039 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8040 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008041 for (SubscriptionInfo subInfo : groupInfos) {
8042 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8043 if (subscriberId != null) {
8044 mergedSubscriberIds.add(subscriberId);
8045 }
8046 }
8047
8048 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8049 } finally {
8050 Binder.restoreCallingIdentity(identity);
8051
8052 }
8053 }
8054
8055 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008056 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008057 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008058 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008059
joonhunshin4ac60942023-11-15 15:23:39 +00008060 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8061 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063 final long identity = Binder.clearCallingIdentity();
8064 try {
8065 final Phone phone = getPhone(subId);
8066 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8067 } finally {
8068 Binder.restoreCallingIdentity(identity);
8069 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008070 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008071
8072 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008073 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008074 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8075 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008076 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8077 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078
8079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 final Phone phone = getPhone(subId);
8082 if (phone == null) {
8083 return false;
8084 }
8085 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8086 cdmaNonRoamingList);
8087 } finally {
8088 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008089 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008090 }
8091
8092 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008093 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008094 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008095 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008096 if (phone == null) {
8097 return raf;
8098 }
8099
Shuo Qiandee53402020-05-29 14:08:15 -07008100 try {
8101 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008102 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008103 mApp, phone.getSubId(), "getRadioAccessFamily");
8104 } catch (SecurityException e) {
8105 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8106 throw e;
8107 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008108
joonhunshin4ac60942023-11-15 15:23:39 +00008109 enforceTelephonyFeatureWithException(callingPackage,
8110 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008112 final long identity = Binder.clearCallingIdentity();
8113 try {
chen xub97461a2018-10-26 14:17:57 -07008114 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008115 } finally {
8116 Binder.restoreCallingIdentity(identity);
8117 }
chen xub97461a2018-10-26 14:17:57 -07008118 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008119 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008120
8121 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008122 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008123 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008124 try {
8125 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8126 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008127 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008128 }
8129 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008130 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008131 }
joonhunshin4ac60942023-11-15 15:23:39 +00008132
8133 enforceTelephonyFeatureWithException(callingPackage,
8134 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8135
Hall Liu82694d52020-12-11 18:22:04 -08008136 RoleManager rm = mApp.getSystemService(RoleManager.class);
8137 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8138 if (!dialerRoleHolders.contains(callingPackage)) {
8139 throw new SecurityException("App must be the dialer role holder to"
8140 + " upload a call composer pic");
8141 }
8142
8143 Executors.newSingleThreadExecutor().execute(() -> {
8144 ByteArrayOutputStream output = new ByteArrayOutputStream(
8145 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8146 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8147 boolean readUntilEnd = false;
8148 int totalBytesRead = 0;
8149 byte[] buffer = new byte[16 * 1024];
8150 while (true) {
8151 int numRead;
8152 try {
8153 numRead = input.read(buffer);
8154 } catch (IOException e) {
8155 try {
8156 fd.checkError();
8157 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8158 null);
8159 } catch (IOException e1) {
8160 // This means that the other side closed explicitly with an error. If this
8161 // happens, log and ignore.
8162 loge("Remote end of call composer picture pipe closed: " + e1);
8163 }
8164 break;
8165 }
8166 if (numRead == -1) {
8167 readUntilEnd = true;
8168 break;
8169 }
8170 totalBytesRead += numRead;
8171 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8172 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8173 try {
8174 input.close();
8175 } catch (IOException e) {
8176 // ignore
8177 }
8178 break;
8179 }
8180 output.write(buffer, 0, numRead);
8181 }
8182 // Generally, the remote end will close the file descriptors. The only case where we
8183 // close is above, where the picture size is too big.
8184
8185 try {
8186 fd.checkError();
8187 } catch (IOException e) {
8188 loge("Remote end for call composer closed with an error: " + e);
8189 return;
8190 }
8191
Hall Liuaa4211e2021-01-20 15:43:39 -08008192 if (!readUntilEnd) {
8193 loge("Did not finish reading entire image; aborting");
8194 return;
8195 }
Hall Liu82694d52020-12-11 18:22:04 -08008196
Hall Liuaa4211e2021-01-20 15:43:39 -08008197 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8198 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8199 new CallComposerPictureTransfer.Factory() {},
8200 imageData,
8201 (result) -> {
8202 if (result.first != null) {
8203 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8204 Bundle outputResult = new Bundle();
8205 outputResult.putParcelable(
8206 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8207 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8208 outputResult);
8209 } else {
8210 callback.send(result.second, null);
8211 }
8212 }
8213 );
Hall Liu82694d52020-12-11 18:22:04 -08008214 });
8215 }
8216
8217 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008218 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008219 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008220 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221
joonhunshin4ac60942023-11-15 15:23:39 +00008222 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8223 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 final long identity = Binder.clearCallingIdentity();
8226 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008227 ImsManager.getInstance(defaultPhone.getContext(),
8228 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008229 } finally {
8230 Binder.restoreCallingIdentity(identity);
8231 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008232 }
8233
8234 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008235 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008236 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8238 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008239 return false;
8240 }
Svet Ganovb320e182015-04-16 12:30:10 -07008241
joonhunshin4ac60942023-11-15 15:23:39 +00008242 enforceTelephonyFeatureWithException(callingPackage,
8243 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245 final long identity = Binder.clearCallingIdentity();
8246 try {
8247 // Check the user preference and the system-level IMS setting. Even if the user has
8248 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8249 // In the long run, we may instead need to check if there exists a connection service
8250 // which can support video calling.
8251 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008252 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008253 return imsManager.isVtEnabledByPlatform()
8254 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8255 && imsManager.isVtEnabledByUser();
8256 } finally {
8257 Binder.restoreCallingIdentity(identity);
8258 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008259 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008260
Andrew Leea1239f22015-03-02 17:44:07 -08008261 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008262 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8263 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008265 mApp, subId, callingPackage, callingFeatureId,
8266 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008267 return false;
8268 }
8269
joonhunshin4ac60942023-11-15 15:23:39 +00008270 enforceTelephonyFeatureWithException(callingPackage,
8271 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273 final long identity = Binder.clearCallingIdentity();
8274 try {
8275 CarrierConfigManager configManager =
8276 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008277 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
Andrew Leea1239f22015-03-02 17:44:07 -08008282 }
8283
8284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008285 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008287 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008288 return false;
8289 }
8290
joonhunshin4ac60942023-11-15 15:23:39 +00008291 enforceTelephonyFeatureWithException(callingPackage,
8292 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 final long identity = Binder.clearCallingIdentity();
8295 try {
8296 CarrierConfigManager configManager =
8297 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008298 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8300 } finally {
8301 Binder.restoreCallingIdentity(identity);
8302 }
Andrew Leea1239f22015-03-02 17:44:07 -08008303 }
8304
Andrew Lee9431b832015-03-09 18:46:45 -07008305 @Override
8306 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008307 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008308 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008309 }
8310
8311 @Override
8312 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008313 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8314 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8315
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316 final long identity = Binder.clearCallingIdentity();
8317 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008318 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008319 } finally {
8320 Binder.restoreCallingIdentity(identity);
8321 }
Andrew Lee9431b832015-03-09 18:46:45 -07008322 }
8323
Hall Liuf6668912018-10-31 17:05:23 -07008324 /**
8325 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8326 * support for the feature and device firmware support.
8327 *
8328 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8329 */
8330 @Override
8331 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008332 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8333 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008336 final Phone phone = getPhone(subscriptionId);
8337 if (phone == null) {
8338 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8339 return false;
8340 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008342 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008344 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8345 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8346 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008347 return isCarrierSupported && isDeviceSupported;
8348 } finally {
8349 Binder.restoreCallingIdentity(identity);
8350 }
Hall Liu98187582018-01-22 19:15:32 -08008351 }
8352
Hall Liuf6668912018-10-31 17:05:23 -07008353 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008354 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8355 * RTT setting, will return true if the device and carrier both support RTT.
8356 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008357 */
8358 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008359 final long identity = Binder.clearCallingIdentity();
8360 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008361 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8362 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8363 return false;
8364 }
8365 }
8366
Hall Liu5bab75c2019-12-11 23:58:20 +00008367 boolean isRttSupported = isRttSupported(subscriptionId);
8368 boolean isUserRttSettingOn = Settings.Secure.getInt(
8369 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8370 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8371 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8372 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008373 } finally {
8374 Binder.restoreCallingIdentity(identity);
8375 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008376 }
8377
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008378 @Deprecated
8379 @Override
8380 public String getDeviceId(String callingPackage) {
8381 return getDeviceIdWithFeature(callingPackage, null);
8382 }
8383
Sanket Padawe7310cc72015-01-14 09:53:20 -08008384 /**
8385 * Returns the unique device ID of phone, for example, the IMEI for
8386 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8387 *
8388 * <p>Requires Permission:
8389 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8390 */
8391 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008392 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008393 try {
8394 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8395 } catch (SecurityException se) {
8396 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8397 throw new SecurityException("Package " + callingPackage + " does not belong to "
8398 + Binder.getCallingUid());
8399 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008400 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008401 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008402 return null;
8403 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008404 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008405 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008406 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008407 return null;
8408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008409
8410 final long identity = Binder.clearCallingIdentity();
8411 try {
8412 return phone.getDeviceId();
8413 } finally {
8414 Binder.restoreCallingIdentity(identity);
8415 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008416 }
8417
Ping Sunc67b7c22016-03-02 19:16:45 +08008418 /**
8419 * {@hide}
8420 * Returns the IMS Registration Status on a particular subid
8421 *
8422 * @param subId
8423 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008424 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008425 Phone phone = getPhone(subId);
8426 if (phone != null) {
8427 return phone.isImsRegistered();
8428 } else {
8429 return false;
8430 }
8431 }
8432
Santos Cordon7a1885b2015-02-03 11:15:19 -08008433 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008434 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008435 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008437 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008438 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8439 }
8440 final long identity = Binder.clearCallingIdentity();
8441 try {
8442 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8443 } finally {
8444 Binder.restoreCallingIdentity(identity);
8445 }
8446 }
8447
8448 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008449 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008450 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008451 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008452 mApp,
8453 subscriptionId,
8454 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8455 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008456
8457 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8458 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8459
Tyler Gunnf70ed162019-04-03 15:28:53 -07008460 final long identity = Binder.clearCallingIdentity();
8461 try {
8462 Phone phone = getPhone(subscriptionId);
8463 if (phone == null) {
8464 return null;
8465 }
8466 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8467 } finally {
8468 Binder.restoreCallingIdentity(identity);
8469 }
8470 }
8471
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008472 /**
8473 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008474 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008475 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008476 final long identity = Binder.clearCallingIdentity();
8477 try {
8478 Phone phone = getPhone(subId);
8479 if (phone != null) {
8480 return phone.isWifiCallingEnabled();
8481 } else {
8482 return false;
8483 }
8484 } finally {
8485 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008486 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008487 }
8488
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008489 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008490 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008491 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008492 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008493 final long identity = Binder.clearCallingIdentity();
8494 try {
8495 Phone phone = getPhone(subId);
8496 if (phone != null) {
8497 return phone.isVideoEnabled();
8498 } else {
8499 return false;
8500 }
8501 } finally {
8502 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008503 }
8504 }
8505
8506 /**
8507 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8508 * defined in {@link ImsRegistrationImplBase}.
8509 */
8510 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008511 final long identity = Binder.clearCallingIdentity();
8512 try {
8513 Phone phone = getPhone(subId);
8514 if (phone != null) {
8515 return phone.getImsRegistrationTech();
8516 } else {
8517 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8518 }
8519 } finally {
8520 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008521 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008522 }
8523
Stuart Scott8eef64f2015-04-08 15:13:54 -07008524 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008525 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008526 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008527
8528 enforceTelephonyFeatureWithException(callingPackage,
8529 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8530
Stuart Scott981d8582015-04-21 14:09:50 -07008531 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8532 return;
8533 }
Kai Shif70f46f2021-03-03 13:59:46 -08008534 Phone defaultPhone = getDefaultPhone();
8535 if (defaultPhone != null) {
8536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8537 mApp, getDefaultPhone().getSubId(), "factoryReset");
8538 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008539 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008540
Svet Ganovcc087f82015-05-12 20:35:54 -07008541 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008542 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8543 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008544 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008545 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008546 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008547 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008548 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008549 setDataRoamingEnabled(subId, phone == null ? false
8550 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008551 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008552 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008553 // There has been issues when Sms raw table somehow stores orphan
8554 // fragments. They lead to garbled message when new fragments come
8555 // in and combined with those stale ones. In case this happens again,
8556 // user can reset all network settings which will clean up this table.
8557 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008558 // Clean up IMS settings as well here.
8559 int slotId = getSlotIndex(subId);
8560 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8561 ImsManager.getInstance(mApp, slotId).factoryReset();
8562 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008563
Kai Shif70f46f2021-03-03 13:59:46 -08008564 if (defaultPhone == null) {
8565 return;
8566 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008567 // Erase modem config if erase modem on network setting is enabled.
8568 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8569 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8570 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008571 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008572 }
Kai Shif70f46f2021-03-03 13:59:46 -08008573
8574 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008575 } finally {
8576 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008577 }
8578 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008579
SongFerngWangfd89b102021-05-27 22:44:54 +08008580 @VisibleForTesting
8581 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8582 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8583 return;
8584 }
8585 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8586 RILConstants.PREFERRED_NETWORK_MODE);
8587 SubscriptionManager.setSubscriptionProperty(subId,
8588 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8589 "user=" + defaultNetworkType);
8590 phone.loadAllowedNetworksFromSubscriptionDatabase();
8591 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8592 defaultNetworkType, null);
8593 }
8594
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008595 private void cleanUpSmsRawTable(Context context) {
8596 ContentResolver resolver = context.getContentResolver();
8597 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8598 resolver.delete(uri, null, null);
8599 }
8600
Narayan Kamath1c496c22015-04-16 14:40:19 +01008601 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008602 public String getSimLocaleForSubscriber(int subId) {
8603 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008604
8605 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8606 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8607
chen xu5d3637b2019-01-21 23:31:38 -08008608 final Phone phone = getPhone(subId);
8609 if (phone == null) {
8610 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008611 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008612 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008613 final long identity = Binder.clearCallingIdentity();
8614 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008615 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8616 phone.getContext().getOpPackageName(),
8617 phone.getContext().getAttributionTag());
8618 if (info == null) {
8619 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8620 return null;
chen xu6291c472019-02-04 12:55:53 -08008621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008622 // Try and fetch the locale from the carrier properties or from the SIM language
8623 // preferences (EF-PL and EF-LI)...
8624 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008625 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008626 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8627 if (localeFromDefaultSim != null) {
8628 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8629 if (DBG) log("Using locale from subId: " + subId + " locale: "
8630 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008631 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008632 } else {
8633 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008634 }
8635 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008637 // The SIM language preferences only store a language (e.g. fr = French), not an
8638 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8639 // the SIM and carrier preferences does not include a country we add the country
8640 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008641 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008642 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008643 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008644 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008645 }
8646
8647 if (DBG) log("No locale found - returning null");
8648 return null;
8649 } finally {
8650 Binder.restoreCallingIdentity(identity);
8651 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008652 }
8653
tom hsu0b59d292022-09-29 23:49:21 +08008654 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008655 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008656 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008657 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008658 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008659 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8660 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008661 Locale.forLanguageTag(localeTag).getCountry())) {
8662 return localeTag;
8663 }
8664 }
8665 return inputLocale.toLanguageTag();
8666 }
8667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008668 /**
8669 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8670 */
8671 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008672 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008673 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008674 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008675
Gary Jian3aa9a762022-01-24 16:41:19 +08008676 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8677 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008678
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008679 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008680 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8681 * representing the state of the modem.
8682 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008683 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8684 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008685 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008686 */
8687 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008688 public void requestModemActivityInfo(ResultReceiver result) {
8689 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008690
8691 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8692 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8693
vagdeviaf9a5b92018-08-15 16:01:53 -07008694 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008695
8696 final long identity = Binder.clearCallingIdentity();
8697 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008698 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008699 } finally {
8700 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008701 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008702 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008703
Gary Jian76280a42022-12-07 16:18:33 +08008704 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008705 // less than total activity duration.
8706 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8707 if (info == null) {
8708 return false;
8709 }
8710 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008711 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008712 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8713
Hall Liu49656c02020-10-09 19:00:11 -07008714 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8715
Siddharth Rayb8114062018-06-17 15:02:38 -07008716 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008717 && (info.getSleepTimeMillis() <= activityDurationMs)
8718 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008719 }
8720
Gary Jian3aa9a762022-01-24 16:41:19 +08008721 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8722 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8723 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8724 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8725
8726 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8727 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8728 }
8729
8730 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8731 mLastModemActivityInfo.setReceiveTimeMillis(
8732 rat,
8733 freq,
8734 info.getReceiveTimeMillis(rat, freq)
8735 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8736 }
8737
8738 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8739 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8740 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8741 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8742
8743 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8744 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8745 }
8746 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8747 mLastModemActivityInfo.setReceiveTimeMillis(
8748 rat,
8749 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8750 }
8751
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008752 /**
8753 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8754 * @param info recent ModemActivityInfo
8755 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008756 private void mergeModemActivityInfo(ModemActivityInfo info) {
8757 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008758 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008759 boolean matched;
8760 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8761 matched = false;
8762 int rat = info.getSpecificInfoRat(i);
8763 int freq = info.getSpecificInfoFrequencyRange(i);
8764 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8765 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8766 //if it already exists
8767 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8768 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8769 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8770 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8771 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8772 updateLastModemActivityInfo(info, rat, freq);
8773 matched = true;
8774 }
8775 } else {
8776 updateLastModemActivityInfo(info, rat);
8777 matched = true;
8778 }
8779 }
8780 }
8781
8782 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008783 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008784 new ActivityStatsTechSpecificInfo(
8785 rat,
8786 freq,
8787 info.getTransmitTimeMillis(rat, freq),
8788 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008789 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008790 }
8791 }
8792 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8793 mLastModemActivitySpecificInfo =
8794 new ActivityStatsTechSpecificInfo[merged.size()];
8795 merged.toArray(mLastModemActivitySpecificInfo);
8796
8797 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8798 mLastModemActivityInfo.setSleepTimeMillis(
8799 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008800 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008801 mLastModemActivityInfo.setIdleTimeMillis(
8802 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008803 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008804
8805 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008806 new ModemActivityInfo(
8807 mLastModemActivityInfo.getTimestampMillis(),
8808 mLastModemActivityInfo.getSleepTimeMillis(),
8809 mLastModemActivityInfo.getIdleTimeMillis(),
8810 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008811 }
8812
8813 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8814 ActivityStatsTechSpecificInfo[] info) {
8815 int infoSize = info.length;
8816 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8817 for (int i = 0; i < infoSize; i++) {
8818 ret[i] = new ActivityStatsTechSpecificInfo(
8819 info[i].getRat(), info[i].getFrequencyRange(),
8820 info[i].getTransmitTimeMillis(),
8821 (int) info[i].getReceiveTimeMillis());
8822 }
8823 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008824 }
8825
Jack Yu85bd38a2015-11-09 11:34:32 -08008826 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008827 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008828 */
8829 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008830 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8831 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8832 Phone phone = PhoneFactory.getPhone(slotIndex);
8833 if (phone == null) {
8834 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8835 return null;
8836 }
8837
8838 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008839 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008840 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008841 return null;
8842 }
8843
joonhunshin4ac60942023-11-15 15:23:39 +00008844 enforceTelephonyFeatureWithException(callingPackage,
8845 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8846
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008847 boolean hasFinePermission = false;
8848 boolean hasCoarsePermission = false;
8849 if (!renounceFineLocationAccess) {
8850 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8851 LocationAccessPolicy.checkLocationPermission(mApp,
8852 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8853 .setCallingPackage(callingPackage)
8854 .setCallingFeatureId(callingFeatureId)
8855 .setCallingPid(Binder.getCallingPid())
8856 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008857 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008858 .setLogAsInfo(true)
8859 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8860 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8861 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8862 .build());
8863 hasFinePermission =
8864 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8865 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008866
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008867 if (!renounceCoarseLocationAccess) {
8868 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8869 LocationAccessPolicy.checkLocationPermission(mApp,
8870 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8871 .setCallingPackage(callingPackage)
8872 .setCallingFeatureId(callingFeatureId)
8873 .setCallingPid(Binder.getCallingPid())
8874 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008875 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008876 .setLogAsInfo(true)
8877 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8878 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8879 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8880 .build());
8881 hasCoarsePermission =
8882 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8883 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008884
Jordan Liu0f2bc442020-11-18 16:47:37 -08008885 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008886 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008887 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8888 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008889 if (subInfo != null && !subInfo.isActive()) {
8890 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008891 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008892 }
8893
Hall Liuf19c44f2018-11-27 14:38:17 -08008894 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008895 boolean isCallingPackageDataService = phone.getDataServicePackages()
8896 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008897
8898 // Scrub out the location info in ServiceState depending on what level of access
8899 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008900 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008901 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8902 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008903 } finally {
8904 Binder.restoreCallingIdentity(identity);
8905 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008906 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008907
8908 /**
8909 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8910 *
8911 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8912 * voicemail ringtone.
8913 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8914 * PhoneAccount.
8915 */
8916 @Override
8917 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008918 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8919 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008921 final long identity = Binder.clearCallingIdentity();
8922 try {
8923 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8924 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008925 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008926 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008928 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8929 } finally {
8930 Binder.restoreCallingIdentity(identity);
8931 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008932 }
8933
8934 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008935 * Sets the per-account voicemail ringtone.
8936 *
8937 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8938 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8939 *
8940 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8941 * voicemail ringtone.
8942 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8943 * PhoneAccount.
8944 */
8945 @Override
8946 public void setVoicemailRingtoneUri(String callingPackage,
8947 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008948 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008949 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008950 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8951 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8953 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8954 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008956
joonhunshin4ac60942023-11-15 15:23:39 +00008957 enforceTelephonyFeatureWithException(callingPackage,
8958 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008960 final long identity = Binder.clearCallingIdentity();
8961 try {
8962 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8963 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008964 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008965 }
8966 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8967 } finally {
8968 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008969 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008970 }
8971
8972 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008973 * Returns whether vibration is set for voicemail notification in Phone settings.
8974 *
8975 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8976 * voicemail vibration setting.
8977 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8978 */
8979 @Override
8980 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008981 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8982 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008984 final long identity = Binder.clearCallingIdentity();
8985 try {
8986 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8987 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008988 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008989 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008991 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8992 } finally {
8993 Binder.restoreCallingIdentity(identity);
8994 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008995 }
8996
Youhan Wange64578a2016-05-02 15:32:42 -07008997 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008998 * Sets the per-account voicemail vibration.
8999 *
9000 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9001 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9002 *
9003 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9004 * voicemail vibration setting.
9005 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9006 * specific PhoneAccount.
9007 */
9008 @Override
9009 public void setVoicemailVibrationEnabled(String callingPackage,
9010 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009011 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009012 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009013 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9014 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9016 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9017 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009018 }
9019
joonhunshin4ac60942023-11-15 15:23:39 +00009020 enforceTelephonyFeatureWithException(callingPackage,
9021 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009023 final long identity = Binder.clearCallingIdentity();
9024 try {
9025 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9026 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009027 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009028 }
9029 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9030 } finally {
9031 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009032 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009033 }
9034
9035 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009036 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9037 *
9038 * @throws SecurityException if the caller does not have the required permission
9039 */
arunvoddud7401012022-12-15 16:08:12 +00009040 @VisibleForTesting
9041 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009042 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009043 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009044 }
9045
9046 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009047 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9048 * permission.
9049 *
9050 * @throws SecurityException if the caller does not have the required permission
9051 */
9052 private void enforceSendSmsPermission() {
9053 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9054 }
9055
9056 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009057 * Make sure either called from same process as self (phone) or IPC caller has interact across
9058 * users permission.
9059 *
9060 * @throws SecurityException if the caller does not have the required permission
9061 */
9062 private void enforceInteractAcrossUsersPermission(String message) {
9063 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9064 }
9065
9066 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009067 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009068 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009069 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009070 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009071 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009072 final long identity = Binder.clearCallingIdentity();
9073 try {
9074 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009075 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009076 if (componentName == null) {
9077 throw new SecurityException(
9078 "Caller not current active visual voicemail package[null]");
9079 }
9080 String vvmPackage = componentName.getPackageName();
9081 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009082 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009083 }
9084 } finally {
9085 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009086 }
9087 }
9088
9089 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009090 * Return the application ID for the app type.
9091 *
9092 * @param subId the subscription ID that this request applies to.
9093 * @param appType the uicc app type.
9094 * @return Application ID for specificied app type, or null if no uicc.
9095 */
9096 @Override
9097 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009098 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009099
9100 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9101 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9102
Youhan Wange64578a2016-05-02 15:32:42 -07009103 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009104
9105 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009106 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009107 if (phone == null) {
9108 return null;
9109 }
9110 String aid = null;
9111 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009112 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009113 .getApplicationByType(appType).getAid();
9114 } catch (Exception e) {
9115 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9116 }
9117 return aid;
9118 } finally {
9119 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009120 }
Youhan Wange64578a2016-05-02 15:32:42 -07009121 }
9122
Youhan Wang4001d252016-05-11 10:29:41 -07009123 /**
9124 * Return the Electronic Serial Number.
9125 *
9126 * @param subId the subscription ID that this request applies to.
9127 * @return ESN or null if error.
9128 */
9129 @Override
9130 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009131 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009132 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009133
9134 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009135 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009136 if (phone == null) {
9137 return null;
9138 }
9139 String esn = null;
9140 try {
9141 esn = phone.getEsn();
9142 } catch (Exception e) {
9143 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9144 }
9145 return esn;
9146 } finally {
9147 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009148 }
Youhan Wang4001d252016-05-11 10:29:41 -07009149 }
9150
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009151 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009152 * Return the Preferred Roaming List Version.
9153 *
9154 * @param subId the subscription ID that this request applies to.
9155 * @return PRLVersion or null if error.
9156 */
9157 @Override
9158 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009159 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009160
9161 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9162 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9163
Youhan Wang66ad5d72016-07-18 17:56:58 -07009164 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009165
9166 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009167 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009168 if (phone == null) {
9169 return null;
9170 }
9171 String cdmaPrlVersion = null;
9172 try {
9173 cdmaPrlVersion = phone.getCdmaPrlVersion();
9174 } catch (Exception e) {
9175 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9176 }
9177 return cdmaPrlVersion;
9178 } finally {
9179 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009180 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009181 }
9182
9183 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009184 * Get snapshot of Telephony histograms
9185 * @return List of Telephony histograms
9186 * @hide
9187 */
9188 @Override
9189 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9191 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009192
9193 final long identity = Binder.clearCallingIdentity();
9194 try {
9195 return RIL.getTelephonyRILTimingHistograms();
9196 } finally {
9197 Binder.restoreCallingIdentity(identity);
9198 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009199 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009200
9201 /**
9202 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009203 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9204 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009205 * Require system privileges. In the future we may add this to carrier APIs.
9206 *
Michele Berionne482f8202018-11-27 18:57:59 -08009207 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009208 */
9209 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009210 @TelephonyManager.SetCarrierRestrictionResult
9211 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009212 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009213
9214 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9215 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9216
vagdeviaf9a5b92018-08-15 16:01:53 -07009217 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009218
Michele Berionne482f8202018-11-27 18:57:59 -08009219 if (carrierRestrictionRules == null) {
9220 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009221 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009223 final long identity = Binder.clearCallingIdentity();
9224 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009225 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009226 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009227 } finally {
9228 Binder.restoreCallingIdentity(identity);
9229 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009230 }
9231
9232 /**
9233 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009234 * Get the allowed carrier list and the excluded carrier list, including the priority between
9235 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009236 * Require system privileges. In the future we may add this to carrier APIs.
9237 *
Michele Berionne482f8202018-11-27 18:57:59 -08009238 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009239 */
9240 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009241 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009242 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009243
9244 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9245 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9246
vagdeviaf9a5b92018-08-15 16:01:53 -07009247 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009248
9249 final long identity = Binder.clearCallingIdentity();
9250 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009251 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9252 if (response instanceof CarrierRestrictionRules) {
9253 return (CarrierRestrictionRules) response;
9254 }
9255 // Response is an Exception of some kind,
9256 // which is signalled to the user as a NULL retval
9257 return null;
9258 } catch (Exception e) {
9259 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9260 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009261 } finally {
9262 Binder.restoreCallingIdentity(identity);
9263 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009264 }
9265
fionaxu59545b42016-05-25 15:53:37 -07009266 /**
arunvoddud7401012022-12-15 16:08:12 +00009267 * Fetches the carrier restriction status of the device and sends the status to the caller
9268 * through the callback.
9269 *
9270 * @param callback The callback that will be used to send the result.
9271 * @throws SecurityException if the caller does not have the required permission/privileges or
9272 * the caller is not allowlisted.
9273 */
9274 @Override
9275 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9276 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009277
9278 enforceTelephonyFeatureWithException(packageName,
9279 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9280
Steve Statia28b7cb32024-03-11 23:58:50 +00009281 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9282 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009283 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9284 throw new SecurityException("Not an authorized caller");
9285 }
9286 final long identity = Binder.clearCallingIdentity();
9287 try {
9288 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009289 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009290 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9291 } finally {
9292 Binder.restoreCallingIdentity(identity);
9293 }
9294 }
9295
arunvoddu567f2b42023-04-25 17:22:00 +00009296 @Override
9297 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9298 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9299 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9300 return allowListInfo.getShaIdList(pkgName, carrierId);
9301 }
9302
arunvoddud7401012022-12-15 16:08:12 +00009303 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009304 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009305 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009306 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009307 }
9308
9309 /**
fionaxu59545b42016-05-25 15:53:37 -07009310 * Action set from carrier signalling broadcast receivers to enable/disable radio
9311 * @param subId the subscription ID that this action applies to.
9312 * @param enabled control enable or disable radio.
9313 * {@hide}
9314 */
9315 @Override
9316 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9317 enforceModifyPermission();
9318 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009319
9320 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009321 if (phone == null) {
9322 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9323 return;
9324 }
9325 try {
9326 phone.carrierActionSetRadioEnabled(enabled);
9327 } catch (Exception e) {
9328 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009329 } finally {
9330 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009331 }
9332 }
9333
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009334 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009335 * Enable or disable Voice over NR (VoNR)
9336 * @param subId the subscription ID that this action applies to.
9337 * @param enabled enable or disable VoNR.
9338 * @return operation result.
9339 */
9340 @Override
9341 public int setVoNrEnabled(int subId, boolean enabled) {
9342 enforceModifyPermission();
9343 final Phone phone = getPhone(subId);
9344
9345 final long identity = Binder.clearCallingIdentity();
9346 if (phone == null) {
9347 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9348 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9349 }
9350
9351 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9352 try {
9353 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9354 workSource);
9355 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009356
9357 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9358 if (DBG) {
9359 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9360 }
9361 SubscriptionManager.setSubscriptionProperty(
9362 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9363 (enabled ? "1" : "0"));
9364 }
9365
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009366 return result;
9367 } finally {
9368 Binder.restoreCallingIdentity(identity);
9369 }
9370 }
9371
9372 /**
9373 * Is voice over NR enabled
9374 * @return true if VoNR is enabled else false
9375 */
9376 @Override
9377 public boolean isVoNrEnabled(int subId) {
9378 enforceReadPrivilegedPermission("isVoNrEnabled");
9379 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9380 final long identity = Binder.clearCallingIdentity();
9381 try {
9382 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9383 null, subId, workSource);
9384 if (DBG) log("isVoNrEnabled: " + isEnabled);
9385 return isEnabled;
9386 } finally {
9387 Binder.restoreCallingIdentity(identity);
9388 }
9389 }
9390
9391 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009392 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9393 * network status based on which carrier apps could apply actions accordingly,
9394 * enable/disable default url handler for example.
9395 *
9396 * @param subId the subscription ID that this action applies to.
9397 * @param report control start/stop reporting the default network status.
9398 * {@hide}
9399 */
9400 @Override
9401 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9402 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009403
9404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9405 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9406 "carrierActionReportDefaultNetworkStatus");
9407
fionaxu8da9cb12017-05-23 15:02:46 -07009408 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009409
9410 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009411 if (phone == null) {
9412 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9413 return;
9414 }
9415 try {
9416 phone.carrierActionReportDefaultNetworkStatus(report);
9417 } catch (Exception e) {
9418 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009419 } finally {
9420 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009421 }
9422 }
9423
9424 /**
fionaxud9622282017-07-17 17:51:30 -07009425 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9426 * @param subId the subscription ID that this action applies to.
9427 * {@hide}
9428 */
9429 @Override
9430 public void carrierActionResetAll(int subId) {
9431 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009432
9433 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9434 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9435
fionaxud9622282017-07-17 17:51:30 -07009436 final Phone phone = getPhone(subId);
9437 if (phone == null) {
9438 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9439 return;
9440 }
9441 try {
9442 phone.carrierActionResetAll();
9443 } catch (Exception e) {
9444 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9445 }
9446 }
9447
9448 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009449 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9450 * bug report is being generated.
9451 */
9452 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009453 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009454 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9455 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009456 writer.println("Permission Denial: can't dump Phone from pid="
9457 + Binder.getCallingPid()
9458 + ", uid=" + Binder.getCallingUid()
9459 + "without permission "
9460 + android.Manifest.permission.DUMP);
9461 return;
9462 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009463 try {
9464 DumpsysHandler.dump(mApp, fd, writer, args);
9465 } catch (Exception e) {
9466 writer.println("Failed to dump phone information: " + e);
9467 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009468 }
Jack Yueb89b242016-06-22 13:27:47 -07009469
Brad Ebingerdac2f002018-04-03 15:17:52 -07009470 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009471 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9472 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9473 @NonNull String[] args) {
9474 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9475 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009476 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009477 }
9478
Jack Yueb89b242016-06-22 13:27:47 -07009479 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009480 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009481 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009482 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009483 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009484 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009485 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009486 */
9487 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009488 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009489 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009490 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9491 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9492 try {
9493 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009494 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009495 } catch (SecurityException se) {
9496 enforceModifyPermission();
9497 }
9498 } else {
9499 enforceModifyPermission();
9500 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009501
joonhunshin4ac60942023-11-15 15:23:39 +00009502 enforceTelephonyFeatureWithException(callingPackage,
9503 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9504
Nate Myren116695d2024-02-09 09:36:01 -08009505 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009506 final long identity = Binder.clearCallingIdentity();
9507 try {
Nate Myren116695d2024-02-09 09:36:01 -08009508 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9509 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009510 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009511 callingUid, callingPackage, null, null);
9512 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009513 Phone phone = getPhone(subId);
9514 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009515 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9516 phone.carrierActionSetMeteredApnsEnabled(enabled);
9517 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009518 phone.getDataSettingsManager().setDataEnabled(
9519 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009521 }
9522 } finally {
9523 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009524 }
9525 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009526
9527 /**
9528 * Get Client request stats
9529 * @return List of Client Request Stats
9530 * @hide
9531 */
9532 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009533 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9534 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009536 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009537 return null;
9538 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009539 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009541 final long identity = Binder.clearCallingIdentity();
9542 try {
9543 if (phone != null) {
9544 return phone.getClientRequestStats();
9545 }
9546
9547 return null;
9548 } finally {
9549 Binder.restoreCallingIdentity(identity);
9550 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009551 }
9552
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009553 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009554 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009555 if (uid == Process.ROOT_UID && packageName == null) {
9556 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9557 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9558 // exception. ROOT_UID seems not to have a valid package name returned by
9559 // PackageManager, so just fake it here to avoid issues when running telephony shell
9560 // commands that plumb through the RIL as root, like so:
9561 // $ adb root
9562 // $ adb shell cmd phone ...
9563 packageName = "root";
9564 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009565 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009566 }
Jack Yueb4124c2017-02-16 15:32:43 -08009567
9568 /**
Grace Chen70990072017-03-24 17:21:30 -07009569 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009570 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009571 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009572 * @param state State of SIM (power down, power up, pass through)
9573 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9574 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9575 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009576 *
9577 **/
9578 @Override
Grace Chen70990072017-03-24 17:21:30 -07009579 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009580 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009581
9582 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9583 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9584
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009585 Phone phone = PhoneFactory.getPhone(slotIndex);
9586
vagdeviaf9a5b92018-08-15 16:01:53 -07009587 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009589 final long identity = Binder.clearCallingIdentity();
9590 try {
9591 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009592 phone.setSimPowerState(state, null, workSource);
9593 }
9594 } finally {
9595 Binder.restoreCallingIdentity(identity);
9596 }
9597 }
9598
9599 /**
9600 * Set SIM card power state.
9601 *
9602 * @param slotIndex SIM slot id.
9603 * @param state State of SIM (power down, power up, pass through)
9604 * @param callback callback to trigger after success or failure
9605 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9606 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9607 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9608 *
9609 **/
9610 @Override
9611 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9612 IIntegerConsumer callback) {
9613 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009614
9615 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9616 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9617 "setSimPowerStateForSlotWithCallback");
9618
Jordan Liu109698e2020-11-24 14:50:34 -08009619 Phone phone = PhoneFactory.getPhone(slotIndex);
9620
9621 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9622
9623 final long identity = Binder.clearCallingIdentity();
9624 try {
9625 if (phone != null) {
9626 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9627 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009628 }
9629 } finally {
9630 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009631 }
9632 }
Shuo Qiandd210312017-04-12 22:11:33 +00009633
Tyler Gunn65d45c22017-06-05 11:22:26 -07009634 private boolean isUssdApiAllowed(int subId) {
9635 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009636 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009637 if (configManager == null) {
9638 return false;
9639 }
9640 PersistableBundle pb = configManager.getConfigForSubId(subId);
9641 if (pb == null) {
9642 return false;
9643 }
9644 return pb.getBoolean(
9645 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9646 }
9647
Shuo Qiandd210312017-04-12 22:11:33 +00009648 /**
Ling Mac28f0212023-03-24 16:07:15 -07009649 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009650 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009651 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009652 */
goneil9c5f4872017-12-05 14:07:56 -08009653 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009654 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009655 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009656
9657 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9658 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009660 final long identity = Binder.clearCallingIdentity();
9661 try {
Ling Mac28f0212023-03-24 16:07:15 -07009662 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009663 } finally {
9664 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009665 }
9666 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009667
9668 /**
9669 * Get the current signal strength information for the given subscription.
9670 * Because this information is not updated when the device is in a low power state
9671 * it should not be relied-upon to be current.
9672 * @param subId Subscription index
9673 * @return the most recent cached signal strength info from the modem
9674 */
9675 @Override
9676 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009677 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9678 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009680 final long identity = Binder.clearCallingIdentity();
9681 try {
9682 Phone p = getPhone(subId);
9683 if (p == null) {
9684 return null;
9685 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009687 return p.getSignalStrength();
9688 } finally {
9689 Binder.restoreCallingIdentity(identity);
9690 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009691 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009692
Pengquan Meng77b7f132018-08-22 14:49:57 -07009693 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009694 * Get the current modem radio state for the given slot.
9695 * @param slotIndex slot index.
9696 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009697 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009698 * @return the current radio power state from the modem
9699 */
9700 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009701 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009702 Phone phone = PhoneFactory.getPhone(slotIndex);
9703 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9705 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009706 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9707 }
9708
joonhunshin4ac60942023-11-15 15:23:39 +00009709 enforceTelephonyFeatureWithException(callingPackage,
9710 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9711
Chen Xuf792fd62018-10-17 17:54:36 +00009712 final long identity = Binder.clearCallingIdentity();
9713 try {
9714 return phone.getRadioPowerState();
9715 } finally {
9716 Binder.restoreCallingIdentity(identity);
9717 }
9718 }
9719 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9720 }
9721
9722 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009723 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9724 *
9725 * <p>Requires one of the following permissions:
9726 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009727 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009728 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9729 * privileges.
9730 *
9731 * @param subId subscription id
9732 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9733 * {@code false}.
9734 */
9735 @Override
9736 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009737 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009738 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009739 try {
9740 mApp.enforceCallingOrSelfPermission(
9741 android.Manifest.permission.ACCESS_NETWORK_STATE,
9742 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009743 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009744 mApp.enforceCallingOrSelfPermission(
9745 permission.READ_BASIC_PHONE_STATE, functionName);
9746 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009747 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009748 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009749 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009750 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009751
joonhunshin4ac60942023-11-15 15:23:39 +00009752 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9753 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9754
Pengquan Menga1bb6272018-09-06 09:59:22 -07009755 boolean isEnabled = false;
9756 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009757 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009758 Phone phone = getPhone(subId);
9759 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009760 } finally {
9761 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009762 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009763 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009764 }
9765
9766
9767 /**
9768 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9769 *
9770 * <p> Requires permission:
9771 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9772 * privileges.
9773 *
9774 * @param subId subscription id
9775 * @param isEnabled {@code true} means enable, {@code false} means disable.
9776 */
9777 @Override
9778 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9780 mApp, subId, "setDataRoamingEnabled");
9781
joonhunshin4ac60942023-11-15 15:23:39 +00009782 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9783 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9784
Pengquan Menga1bb6272018-09-06 09:59:22 -07009785 final long identity = Binder.clearCallingIdentity();
9786 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009787 Phone phone = getPhone(subId);
9788 if (phone != null) {
9789 phone.setDataRoamingEnabled(isEnabled);
9790 }
9791 } finally {
9792 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009793 }
9794 }
9795
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009796 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009797 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009798 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009799 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009800 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009801
joonhunshin4ac60942023-11-15 15:23:39 +00009802 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9803 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9804
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009805 boolean isAllowed = true;
9806 final long identity = Binder.clearCallingIdentity();
9807 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009808 Phone phone = getPhone(subId);
9809 if (phone != null) {
9810 isAllowed = phone.isCspPlmnEnabled();
9811 }
9812 } finally {
9813 Binder.restoreCallingIdentity(identity);
9814 }
9815 return isAllowed;
9816 }
9817
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009818 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9819 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009820 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009821 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009822 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009823 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9824 if (phone == null) {
9825 return false;
9826 }
9827 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9828 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9829 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009830 }
9831
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009832 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009833 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009834 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009835 mApp.getSystemService(AppOpsManager.class)
9836 .checkPackage(Binder.getCallingUid(), callingPackage);
9837
Jordan Liu1e142fc2019-04-22 15:10:43 -07009838 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009839 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009840 try {
9841 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009842 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009843 } catch (SecurityException e) {
9844 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9845 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009846 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009847 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009848 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009849 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009850 }
joonhunshin4ac60942023-11-15 15:23:39 +00009851
9852 enforceTelephonyFeatureWithException(callingPackage,
9853 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9854
sandeepjsb6c87872021-09-27 15:34:44 +00009855 // checking compatibility, if calling app's target SDK is T and beyond.
9856 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9857 Binder.getCallingUid())) {
9858 isIccIdAccessRestricted = true;
9859 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009860 final long identity = Binder.clearCallingIdentity();
9861 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009862 UiccController uiccController = UiccController.getInstance();
9863 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009864 if (hasReadPermission) {
9865 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009866 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009867
9868 // Remove private info if the caller doesn't have access
9869 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9870 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009871 //setting the value after compatibility check
9872 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009873 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9874 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009875 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009876 if (card == null) {
9877 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009878 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009879 continue;
9880 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009881 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9882 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009883 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009884 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009885 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009886 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9887 for (UiccPortInfo portInfo : portInfos) {
9888 UiccPort port = uiccController.getUiccPortForSlot(
9889 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9890 if (port == null) {
9891 // assume no access if port is null
9892 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9893 continue;
9894 }
9895 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9896 uiccPortInfos.add(portInfo);
9897 } else {
9898 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9899 }
9900 }
9901 filteredInfos.add(new UiccCardInfo(
9902 cardInfo.isEuicc(),
9903 cardInfo.getCardId(),
9904 null,
9905 cardInfo.getPhysicalSlotIndex(),
9906 cardInfo.isRemovable(),
9907 cardInfo.isMultipleEnabledProfilesSupported(),
9908 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009909 }
9910 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009911 } finally {
9912 Binder.restoreCallingIdentity(identity);
9913 }
9914 }
9915
sandeepjsb6c87872021-09-27 15:34:44 +00009916 /**
9917 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9918 * generally private and require carrier privileges to view.
9919 *
9920 * @hide
9921 */
9922 @NonNull
9923 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9924 List<UiccPortInfo> portinfo = new ArrayList<>();
9925 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9926 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9927 }
9928 return new UiccCardInfo(
9929 cardInfo.isEuicc(),
9930 cardInfo.getCardId(),
9931 null,
9932 cardInfo.getPhysicalSlotIndex(),
9933 cardInfo.isRemovable(),
9934 cardInfo.isMultipleEnabledProfilesSupported(),
9935 portinfo
9936 );
9937 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009938
sandeepjsb6c87872021-09-27 15:34:44 +00009939 /**
9940 * @hide
9941 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9942 * These values are generally private and require carrier privileges to view.
9943 */
9944 @NonNull
9945 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9946 return new UiccPortInfo(
9947 UiccPortInfo.ICCID_REDACTED,
9948 portInfo.getPortIndex(),
9949 portInfo.getLogicalSlotIndex(),
9950 portInfo.isActive()
9951 );
9952 }
9953 @Override
9954 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009955 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009956 mApp.getSystemService(AppOpsManager.class)
9957 .checkPackage(Binder.getCallingUid(), callingPackage);
9958
sandeepjsb6c87872021-09-27 15:34:44 +00009959 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009960
Aman Guptaf3c90b32022-03-17 04:54:16 +00009961 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9962 // we are reading iccId which is PII data.
9963 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009964
joonhunshin4ac60942023-11-15 15:23:39 +00009965 enforceTelephonyFeatureWithException(callingPackage,
9966 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9967
sandeepjsb6c87872021-09-27 15:34:44 +00009968 // checking compatibility, if calling app's target SDK is T and beyond.
9969 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9970 Binder.getCallingUid())) {
9971 isLogicalSlotAccessRestricted = true;
9972 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009973 final long identity = Binder.clearCallingIdentity();
9974 try {
9975 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009976 if (slots == null || slots.length == 0) {
9977 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009978 return null;
9979 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009980 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9981 for (int i = 0; i < slots.length; i++) {
9982 UiccSlot slot = slots[i];
9983 if (slot == null) {
9984 continue;
9985 }
9986
Jordan Liu7be7e652019-05-06 18:55:02 +00009987 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009988 UiccCard card = slot.getUiccCard();
9989 if (card != null) {
9990 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009991 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009992 cardId = slot.getEid();
9993 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009994 // If cardId is null, use iccId of default port as cardId.
9995 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009997 }
9998
Jordan Liu857451f2019-05-09 16:35:35 -07009999 if (cardId != null) {
10000 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10001 // if cardId is an EID, it's all digits so this is fine
10002 cardId = IccUtils.stripTrailingFs(cardId);
10003 }
10004
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010005 int cardState = 0;
10006 switch (slot.getCardState()) {
10007 case CARDSTATE_ABSENT:
10008 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10009 break;
10010 case CARDSTATE_PRESENT:
10011 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10012 break;
10013 case CARDSTATE_ERROR:
10014 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10015 break;
10016 case CARDSTATE_RESTRICTED:
10017 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10018 break;
10019 default:
10020 break;
10021
10022 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010023 List<UiccPortInfo> portInfos = new ArrayList<>();
10024 int[] portIndexes = slot.getPortList();
10025 for (int portIdx : portIndexes) {
10026 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010027 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010028 portInfos.add(new UiccPortInfo(iccId, portIdx,
10029 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010031 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010032 slot.isEuicc(),
10033 cardId,
10034 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010035 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010036 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010037 //setting the value after compatibility check
10038 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010039 }
10040 return infos;
10041 } finally {
10042 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010043 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010044 }
10045
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010046 /* Returns null if doesn't have read permission or carrier privilege access. */
10047 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10048 boolean hasReadPermission) {
10049 String iccId = slot.getIccId(portIndex);
10050 if (hasReadPermission) { // if has read permission
10051 return iccId;
10052 } else {
10053 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10054 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10055 // if no read permission, checking carrier privilege access
10056 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10057 return iccId;
10058 }
10059 }
10060 }
10061 // No read permission or carrier privilege access.
10062 return UiccPortInfo.ICCID_REDACTED;
10063 }
10064
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010065 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010066 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010067 public boolean switchSlots(int[] physicalSlots) {
10068 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010069
joonhunshin4ac60942023-11-15 15:23:39 +000010070 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10071 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10072
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010073 final long identity = Binder.clearCallingIdentity();
10074 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010075 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10076 for (int i = 0; i < physicalSlots.length; i++) {
10077 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10078 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10079 physicalSlots[i], i));
10080 }
10081 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010082 } finally {
10083 Binder.restoreCallingIdentity(identity);
10084 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010085 }
Jack Yu4c988042018-02-27 15:30:01 -080010086
10087 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010088 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10089 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10090 enforceModifyPermission();
10091
joonhunshin4ac60942023-11-15 15:23:39 +000010092 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10093 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10094
sandeepjsb6c87872021-09-27 15:34:44 +000010095 final long identity = Binder.clearCallingIdentity();
10096 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010097 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010098 } finally {
10099 Binder.restoreCallingIdentity(identity);
10100 }
10101 }
10102
10103 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010104 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010105 enforceTelephonyFeatureWithException(callingPackage,
10106 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10107
Jordan Liu7de49fa2018-12-06 14:48:49 -080010108 final long identity = Binder.clearCallingIdentity();
10109 try {
10110 return UiccController.getInstance().getCardIdForDefaultEuicc();
10111 } finally {
10112 Binder.restoreCallingIdentity(identity);
10113 }
10114 }
10115
Pengquan Meng85728fb2018-03-12 16:31:21 -070010116 /**
goneil47ffb6e2018-04-06 15:40:58 -070010117 * A test API to reload the UICC profile.
10118 *
10119 * <p>Requires that the calling app has permission
10120 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10121 * @hide
10122 */
10123 @Override
10124 public void refreshUiccProfile(int subId) {
10125 enforceModifyPermission();
10126
10127 final long identity = Binder.clearCallingIdentity();
10128 try {
10129 Phone phone = getPhone(subId);
10130 if (phone == null) {
10131 return;
10132 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010133 UiccPort uiccPort = phone.getUiccPort();
10134 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010135 return;
10136 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010137 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010138 if (uiccProfile == null) {
10139 return;
10140 }
10141 uiccProfile.refresh();
10142 } finally {
10143 Binder.restoreCallingIdentity(identity);
10144 }
10145 }
10146
10147 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010148 * Returns false if the mobile data is disabled by default, otherwise return true.
10149 */
10150 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010151 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010152 }
10153
10154 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010155 * Returns the default network type for the given {@code subId}, if the default network type is
10156 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10157 */
10158 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010159 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010160 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010161 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10162 return list.get(phoneId);
10163 }
10164 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010165 }
fionaxua13278b2018-03-21 00:08:13 -070010166
10167 @Override
10168 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010169 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010171
10172 final long identity = Binder.clearCallingIdentity();
10173 try {
10174 final Phone phone = getPhone(subId);
10175 if (phone == null) {
10176 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10177 return;
10178 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010179 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10180 if (cpt != null) {
10181 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10182 }
10183 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010184 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10185 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010186 if (carrierPrivilegeRules == null) {
10187 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10188 } else {
10189 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10190 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010191 } finally {
10192 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010193 }
fionaxua13278b2018-03-21 00:08:13 -070010194 }
10195
10196 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010197 public void setCarrierServicePackageOverride(
10198 int subId, String carrierServicePackage, String callingPackage) {
10199 TelephonyPermissions.enforceShellOnly(
10200 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10201
Benedict Wong66477622023-02-03 23:30:57 +000010202 final long identity = Binder.clearCallingIdentity();
10203 try {
10204 final Phone phone = getPhone(subId);
10205 if (phone == null || phone.getSubId() != subId) {
10206 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10207 throw new IllegalArgumentException("No phone for subid");
10208 }
10209 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10210 if (cpt == null) {
10211 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10212 throw new IllegalStateException("No CPT for phone");
10213 }
10214 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10215 } finally {
10216 Binder.restoreCallingIdentity(identity);
10217 }
10218 }
10219
10220 @Override
fionaxua13278b2018-03-21 00:08:13 -070010221 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010222 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010223
10224 final long identity = Binder.clearCallingIdentity();
10225 try {
10226 final Phone phone = getPhone(subId);
10227 if (phone == null) {
10228 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10229 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10230 }
10231 return phone.getCarrierIdListVersion();
10232 } finally {
10233 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010234 }
fionaxua13278b2018-03-21 00:08:13 -070010235 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010236
10237 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010238 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10239 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010241 mApp, subId, callingPackage, callingFeatureId,
10242 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010243 return -1;
10244 }
10245
10246 final long identity = Binder.clearCallingIdentity();
10247 try {
10248 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10249 } finally {
10250 Binder.restoreCallingIdentity(identity);
10251 }
10252 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010253
10254 @Override
10255 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010256 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010257 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010258 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010259
joonhunshin4ac60942023-11-15 15:23:39 +000010260 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10261 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10262
Pengquan Menga1bb6272018-09-06 09:59:22 -070010263 final long identity = Binder.clearCallingIdentity();
10264 try {
10265 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10266 } finally {
10267 Binder.restoreCallingIdentity(identity);
10268 }
10269 }
10270
10271 @Override
10272 public boolean setCdmaRoamingMode(int subId, int mode) {
10273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10274 mApp, subId, "setCdmaRoamingMode");
10275
joonhunshin4ac60942023-11-15 15:23:39 +000010276 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10277 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10278
Pengquan Menga1bb6272018-09-06 09:59:22 -070010279 final long identity = Binder.clearCallingIdentity();
10280 try {
10281 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10282 } finally {
10283 Binder.restoreCallingIdentity(identity);
10284 }
10285 }
10286
10287 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010288 public int getCdmaSubscriptionMode(int subId) {
10289 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010290 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010291 mApp, subId, "getCdmaSubscriptionMode");
10292
joonhunshin4ac60942023-11-15 15:23:39 +000010293 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10294 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10295
Sarah Chinbaab1432020-10-28 13:46:24 -070010296 final long identity = Binder.clearCallingIdentity();
10297 try {
10298 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10299 } finally {
10300 Binder.restoreCallingIdentity(identity);
10301 }
10302 }
10303
10304 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010305 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10307 mApp, subId, "setCdmaSubscriptionMode");
10308
joonhunshin4ac60942023-11-15 15:23:39 +000010309 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10310 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10311
Pengquan Menga1bb6272018-09-06 09:59:22 -070010312 final long identity = Binder.clearCallingIdentity();
10313 try {
10314 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10315 } finally {
10316 Binder.restoreCallingIdentity(identity);
10317 }
10318 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010319
sqianc5eccab2018-10-19 18:46:41 -070010320 @Override
sqian8c685422019-02-22 15:55:18 -080010321 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010322 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010324 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10325 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010326 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10327 }
joonhunshin4ac60942023-11-15 15:23:39 +000010328
10329 enforceTelephonyFeatureWithException(callingPackage,
10330 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10331
sqian11b7a0e2018-12-05 18:48:28 -080010332 final long identity = Binder.clearCallingIdentity();
10333 try {
sqian854d44b2018-12-12 16:48:18 -080010334 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10335 for (Phone phone: PhoneFactory.getPhones()) {
10336 if (phone.getEmergencyNumberTracker() != null
10337 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10338 emergencyNumberListInternal.put(
10339 phone.getSubId(),
10340 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10341 }
sqian11b7a0e2018-12-05 18:48:28 -080010342 }
sqian854d44b2018-12-12 16:48:18 -080010343 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010344 } finally {
10345 Binder.restoreCallingIdentity(identity);
10346 }
sqianc5eccab2018-10-19 18:46:41 -070010347 }
10348
10349 @Override
sqian8c685422019-02-22 15:55:18 -080010350 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010351 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010352 if (!exactMatch) {
10353 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010354 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010355 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010356 }
joonhunshin4ac60942023-11-15 15:23:39 +000010357
10358 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10359 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10360
sqian11b7a0e2018-12-05 18:48:28 -080010361 final long identity = Binder.clearCallingIdentity();
10362 try {
sqian854d44b2018-12-12 16:48:18 -080010363 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010364 //Note: we ignore passed in param exactMatch. We can remove it once
10365 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010366 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010367 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010368 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010369 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010370 }
sqian11b7a0e2018-12-05 18:48:28 -080010371 }
10372 return false;
10373 } finally {
10374 Binder.restoreCallingIdentity(identity);
10375 }
10376 }
10377
sqianf4ca7ed2019-01-15 18:32:07 -080010378 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010379 * Start emergency callback mode for GsmCdmaPhone for testing.
10380 */
10381 @Override
10382 public void startEmergencyCallbackMode() {
10383 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10384 "startEmergencyCallbackMode");
10385 enforceModifyPermission();
10386 final long identity = Binder.clearCallingIdentity();
10387 try {
10388 for (Phone phone : PhoneFactory.getPhones()) {
10389 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10390 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10391 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10392 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10393 gsmCdmaPhone.obtainMessage(
10394 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10395 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10396 }
10397 }
10398 } finally {
10399 Binder.restoreCallingIdentity(identity);
10400 }
10401 }
10402
10403 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010404 * Update emergency number list for test mode.
10405 */
10406 @Override
10407 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10408 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10409 "updateEmergencyNumberListTestMode");
10410
10411 final long identity = Binder.clearCallingIdentity();
10412 try {
10413 for (Phone phone: PhoneFactory.getPhones()) {
10414 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10415 if (tracker != null) {
10416 tracker.executeEmergencyNumberTestModeCommand(action, num);
10417 }
10418 }
10419 } finally {
10420 Binder.restoreCallingIdentity(identity);
10421 }
10422 }
10423
10424 /**
10425 * Get the full emergency number list for test mode.
10426 */
10427 @Override
10428 public List<String> getEmergencyNumberListTestMode() {
10429 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10430 "getEmergencyNumberListTestMode");
10431
10432 final long identity = Binder.clearCallingIdentity();
10433 try {
10434 Set<String> emergencyNumbers = new HashSet<>();
10435 for (Phone phone: PhoneFactory.getPhones()) {
10436 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10437 if (tracker != null) {
10438 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10439 emergencyNumbers.add(num.getNumber());
10440 }
10441 }
10442 }
10443 return new ArrayList<>(emergencyNumbers);
10444 } finally {
10445 Binder.restoreCallingIdentity(identity);
10446 }
10447 }
10448
chen xud6b45bd2018-10-30 22:27:10 -070010449 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010450 public int getEmergencyNumberDbVersion(int subId) {
10451 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10452
joonhunshin4ac60942023-11-15 15:23:39 +000010453 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10454 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10455
Shuo Qian3b6ee772019-11-13 17:43:31 -080010456 final long identity = Binder.clearCallingIdentity();
10457 try {
10458 final Phone phone = getPhone(subId);
10459 if (phone == null) {
10460 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10461 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10462 }
10463 return phone.getEmergencyNumberDbVersion();
10464 } finally {
10465 Binder.restoreCallingIdentity(identity);
10466 }
10467 }
10468
10469 @Override
10470 public void notifyOtaEmergencyNumberDbInstalled() {
10471 enforceModifyPermission();
10472
joonhunshin4ac60942023-11-15 15:23:39 +000010473 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10474 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10475
Shuo Qian3b6ee772019-11-13 17:43:31 -080010476 final long identity = Binder.clearCallingIdentity();
10477 try {
10478 for (Phone phone: PhoneFactory.getPhones()) {
10479 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10480 if (tracker != null) {
10481 tracker.updateOtaEmergencyNumberDatabase();
10482 }
10483 }
10484 } finally {
10485 Binder.restoreCallingIdentity(identity);
10486 }
10487 }
10488
10489 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010490 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010491 enforceActiveEmergencySessionPermission();
10492
joonhunshin4ac60942023-11-15 15:23:39 +000010493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10494 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10495
Shuo Qian3b6ee772019-11-13 17:43:31 -080010496 final long identity = Binder.clearCallingIdentity();
10497 try {
10498 for (Phone phone: PhoneFactory.getPhones()) {
10499 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10500 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010501 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10502 }
10503 }
10504 } finally {
10505 Binder.restoreCallingIdentity(identity);
10506 }
10507 }
10508
10509 @Override
10510 public void resetOtaEmergencyNumberDbFilePath() {
10511 enforceActiveEmergencySessionPermission();
10512
joonhunshin4ac60942023-11-15 15:23:39 +000010513 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10514 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10515
Shuo Qianc373f112020-03-05 17:55:34 -080010516 final long identity = Binder.clearCallingIdentity();
10517 try {
10518 for (Phone phone: PhoneFactory.getPhones()) {
10519 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10520 if (tracker != null) {
10521 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010522 }
10523 }
10524 } finally {
10525 Binder.restoreCallingIdentity(identity);
10526 }
10527 }
10528
10529 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010530 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10531 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10532 Phone phone = getPhone(subId);
10533 if (phone == null) {
10534 return null;
10535 }
10536 final long identity = Binder.clearCallingIdentity();
10537 try {
10538 UiccProfile profile = UiccController.getInstance()
10539 .getUiccProfileForPhone(phone.getPhoneId());
10540 if (profile != null) {
10541 return profile.getCertsFromCarrierPrivilegeAccessRules();
10542 }
10543 } finally {
10544 Binder.restoreCallingIdentity(identity);
10545 }
10546 return null;
10547 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010548
10549 /**
10550 * Enable or disable a modem stack.
10551 */
10552 @Override
10553 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10554 enforceModifyPermission();
10555
joonhunshin4ac60942023-11-15 15:23:39 +000010556 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10557 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10558
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010559 final long identity = Binder.clearCallingIdentity();
10560 try {
10561 Phone phone = PhoneFactory.getPhone(slotIndex);
10562 if (phone == null) {
10563 return false;
10564 } else {
10565 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10566 }
10567 } finally {
10568 Binder.restoreCallingIdentity(identity);
10569 }
10570 }
Michelecea4cf22018-12-21 15:00:11 -080010571
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010572 /**
10573 * Whether a modem stack is enabled or not.
10574 */
10575 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010576 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10577 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010578 Phone phone = PhoneFactory.getPhone(slotIndex);
10579 if (phone == null) return false;
10580
10581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010582 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10583 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010584 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10585 }
10586
joonhunshin4ac60942023-11-15 15:23:39 +000010587 enforceTelephonyFeatureWithException(callingPackage,
10588 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10589
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010590 final long identity = Binder.clearCallingIdentity();
10591 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010592 try {
10593 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10594 } catch (NoSuchElementException ex) {
10595 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10596 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010597 } finally {
10598 Binder.restoreCallingIdentity(identity);
10599 }
10600 }
10601
Michelecea4cf22018-12-21 15:00:11 -080010602 @Override
Michele0ea7d782019-03-19 14:58:42 -070010603 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010604 enforceModifyPermission();
10605
joonhunshin4ac60942023-11-15 15:23:39 +000010606 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10607 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10608
Michelecea4cf22018-12-21 15:00:11 -080010609 final long identity = Binder.clearCallingIdentity();
10610 try {
10611 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010612 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010613 .commit();
10614 } finally {
10615 Binder.restoreCallingIdentity(identity);
10616 }
10617 }
10618
10619 @Override
Michele0ea7d782019-03-19 14:58:42 -070010620 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010621 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010623 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10624 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010625 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010626 }
Michelecea4cf22018-12-21 15:00:11 -080010627
joonhunshin4ac60942023-11-15 15:23:39 +000010628 enforceTelephonyFeatureWithException(callingPackage,
10629 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10630
Michelecea4cf22018-12-21 15:00:11 -080010631 final long identity = Binder.clearCallingIdentity();
10632 try {
Michele0ea7d782019-03-19 14:58:42 -070010633 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010634 } finally {
10635 Binder.restoreCallingIdentity(identity);
10636 }
10637 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010638
Michele0ea7d782019-03-19 14:58:42 -070010639 @TelephonyManager.IsMultiSimSupportedResult
10640 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010641 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10642 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10643 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010644 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10645 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010646 }
10647 // Check if the hardware supports multisim functionality. If usage of multisim is not
10648 // supported by the modem, indicate that it is restricted.
10649 PhoneCapability staticCapability =
10650 mPhoneConfigurationManager.getStaticPhoneCapability();
10651 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010652 loge("isMultiSimSupportedInternal: no static configuration available");
10653 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010654 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010655 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010656 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10657 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010658 }
10659 // Check if support of multiple SIMs is restricted by carrier
10660 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010661 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010662 }
10663
Michele0ea7d782019-03-19 14:58:42 -070010664 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010665 }
10666
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010667 /**
10668 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010669 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10670 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10671 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010672 * @param numOfSims number of active sims we want to switch to
10673 */
10674 @Override
10675 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010676 if (numOfSims == 1) {
10677 enforceModifyPermission();
10678 } else {
10679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10680 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10681 }
joonhunshin4ac60942023-11-15 15:23:39 +000010682
10683 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10684 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10685
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010686 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010687
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010688 try {
Michele30b57b22019-03-01 12:01:14 -080010689 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010690 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010691 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10692 return;
10693 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010694 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10695 } finally {
10696 Binder.restoreCallingIdentity(identity);
10697 }
10698 }
10699
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010700 @Override
10701 public boolean isApplicationOnUicc(int subId, int appType) {
10702 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010703
10704 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10705 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10706
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010707 Phone phone = getPhone(subId);
10708 if (phone == null) {
10709 return false;
10710 }
10711 final long identity = Binder.clearCallingIdentity();
10712 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010713 UiccPort uiccPort = phone.getUiccPort();
10714 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010715 return false;
10716 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010717 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010718 if (uiccProfile == null) {
10719 return false;
10720 }
10721 if (TelephonyManager.APPTYPE_SIM <= appType
10722 && appType <= TelephonyManager.APPTYPE_ISIM) {
10723 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10724 }
10725 return false;
10726 } finally {
10727 Binder.restoreCallingIdentity(identity);
10728 }
10729 }
10730
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010731 /**
chen xub4baa772019-04-03 10:23:41 -070010732 * Get whether making changes to modem configurations will trigger reboot.
10733 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010734 */
10735 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010736 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10737 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010739 mApp, subId, callingPackage, callingFeatureId,
10740 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010741 return false;
10742 }
joonhunshin4ac60942023-11-15 15:23:39 +000010743
10744 enforceTelephonyFeatureWithException(callingPackage,
10745 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10746 "doesSwitchMultiSimConfigTriggerReboot");
10747
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010748 final long identity = Binder.clearCallingIdentity();
10749 try {
10750 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10751 } finally {
10752 Binder.restoreCallingIdentity(identity);
10753 }
10754 }
10755
Nathan Harold29f5f052019-02-15 13:41:57 -080010756 private void updateModemStateMetrics() {
10757 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10758 // TODO: check the state for each modem if the api is ready.
10759 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10760 }
10761
Pengquan Meng3889a572019-01-23 11:16:29 -080010762 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010763 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010764 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010765 // Verify that the callingPackage belongs to the calling UID
10766 mApp.getSystemService(AppOpsManager.class)
10767 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010768
10769 enforceTelephonyFeatureWithException(callingPackage,
10770 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10771
Pengquan Meng3889a572019-01-23 11:16:29 -080010772 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010773 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010774 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010775 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10776 if (slotInfos != null) {
10777 for (int i = 0; i < slotInfos.length; i++) {
10778 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10779 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10780 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10781 portInfo.getLogicalSlotIndex()));
10782 }
10783 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010784 }
10785 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010786 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010787 } finally {
10788 Binder.restoreCallingIdentity(identity);
10789 }
10790 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010791
10792 /**
10793 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010794 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010795 */
jimsunf9ec1622022-09-13 21:18:43 +080010796 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010797 @Override
10798 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010799 return getHalVersion(HAL_SERVICE_RADIO);
10800 }
10801
10802 /**
10803 * Get the HAL Version of a specific service
10804 */
10805 @Override
10806 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010807 Phone phone = getDefaultPhone();
10808 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010809 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010810 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10811 return hv.major * 100 + hv.minor;
10812 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010813
10814 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010815 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010816 *
10817 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010818 */
10819 @Override
sangyun097dcf72024-01-04 10:35:49 +090010820 public @Nullable String getCurrentPackageName() {
10821 PackageManager pm = mApp.getPackageManager();
10822 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10823 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010824 }
10825
10826 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010827 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10828 * corresponding network requests on a subId.
10829 *
10830 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010831 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010832 * 2) APN is un-metered for this subscription, or
10833 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010834 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010835 *
10836 * @return whether data is allowed for a apn type.
10837 *
10838 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010839 */
10840 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010841 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010842 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10843 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010844
joonhunshin4ac60942023-11-15 15:23:39 +000010845 enforceTelephonyFeatureWithException(callingPackage,
10846 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10847
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010848 // Now that all security checks passes, perform the operation as ourselves.
10849 final long identity = Binder.clearCallingIdentity();
10850 try {
10851 Phone phone = getPhone(subId);
10852 if (phone == null) return false;
10853
Jack Yu27422a52022-03-21 10:38:05 -070010854 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010855 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010856 isMetered = phone.getDataNetworkController().getDataConfigManager()
10857 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10858 phone.getServiceState().getDataRoaming());
10859 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010860 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010861 } finally {
10862 Binder.restoreCallingIdentity(identity);
10863 }
10864 }
10865
10866 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010867 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010868 enforceReadPrivilegedPermission("isApnMetered");
10869
joonhunshin4ac60942023-11-15 15:23:39 +000010870 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10871 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10872
Malcolm Chene5ad5792019-04-18 13:51:02 -070010873 // Now that all security checks passes, perform the operation as ourselves.
10874 final long identity = Binder.clearCallingIdentity();
10875 try {
10876 Phone phone = getPhone(subId);
10877 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010878 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10879 DataUtils.apnTypeToNetworkCapability(apnType),
10880 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010881 } finally {
10882 Binder.restoreCallingIdentity(identity);
10883 }
10884 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010885
10886 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010887 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10888 int subscriptionId, IBooleanConsumer resultCallback) {
10889 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010890
10891 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10892 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10893
Hall Liu73f5d362020-01-20 13:42:00 -080010894 long token = Binder.clearCallingIdentity();
10895 try {
10896 Phone phone = getPhone(subscriptionId);
10897 if (phone == null) {
10898 try {
10899 if (resultCallback != null) {
10900 resultCallback.accept(false);
10901 }
10902 } catch (RemoteException e) {
10903 // ignore
10904 }
10905 return;
10906 }
10907 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10908 Pair.create(specifiers, (x) -> {
10909 try {
10910 if (resultCallback != null) {
10911 resultCallback.accept(x);
10912 }
10913 } catch (RemoteException e) {
10914 // ignore
10915 }
10916 });
10917 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10918 } finally {
10919 Binder.restoreCallingIdentity(token);
10920 }
10921 }
10922
10923 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010924 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10925 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010926 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010927 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010928
10929 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10930 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10931
Sarah Chin679c08a2020-11-18 13:39:35 -080010932 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10933 final long identity = Binder.clearCallingIdentity();
10934 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010935 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10936 if (result instanceof IllegalStateException) {
10937 throw (IllegalStateException) result;
10938 }
10939 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010940 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10941 return specifiers;
10942 } finally {
10943 Binder.restoreCallingIdentity(identity);
10944 }
10945 }
10946
10947 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010948 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010949 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010950
10951 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10952 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10953
Jack Yu8b766fc2022-03-21 09:42:33 -070010954 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010955 }
10956
10957 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010958 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10959 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010960 if (callingPackage == null) {
10961 callingPackage = getCurrentPackageName();
10962 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010963 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10964 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010965 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10966 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010967 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10968 }
10969 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10970 Intent intent = new Intent();
10971 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10972 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10973 // Bring up choose default SMS subscription dialog right now
10974 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10975 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10976 mApp.startActivity(intent);
10977 }
chen xud5ca2d52019-05-28 15:20:57 -070010978
10979 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010980 public void showSwitchToManagedProfileDialog() {
10981 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010982 try {
10983 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10984 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10985 // for work telephony.
10986 Intent intent = new Intent(Intent.ACTION_SENDTO);
10987 intent.setData(Uri.parse("smsto:"));
10988 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10989 mApp.startActivity(intent);
10990 } catch (ActivityNotFoundException e) {
10991 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10992 Intent intent = new Intent();
10993 intent.setClass(mApp, ErrorDialogActivity.class);
10994 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10995 mApp.startActivity(intent);
10996 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010997 }
10998
10999 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011000 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011001 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11002 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11003
chen xud5ca2d52019-05-28 15:20:57 -070011004 //TODO investigate if this API should require proper permission check in R b/133791609
11005 final long identity = Binder.clearCallingIdentity();
11006 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011007 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11008 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11009 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11010 return carrierUAProfUrl;
11011 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011012 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11013 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011014 } finally {
11015 Binder.restoreCallingIdentity(identity);
11016 }
11017 }
11018
11019 @Override
11020 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011021 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11022 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11023
chen xud5ca2d52019-05-28 15:20:57 -070011024 //TODO investigate if this API should require proper permission check in R b/133791609
11025 final long identity = Binder.clearCallingIdentity();
11026 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011027 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11028 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11029 if (!TextUtils.isEmpty(carrierUserAgent)) {
11030 return carrierUserAgent;
11031 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011032 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11033 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011034 } finally {
11035 Binder.restoreCallingIdentity(identity);
11036 }
11037 }
Jack Yub07d4972019-05-28 16:12:25 -070011038
11039 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011040 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11041 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011042
joonhunshin4ac60942023-11-15 15:23:39 +000011043 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11044 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11045
Jack Yub07d4972019-05-28 16:12:25 -070011046 final long identity = Binder.clearCallingIdentity();
11047 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011048 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011049 if (phone == null) return false;
11050
Ling Maf188d502022-09-16 15:22:36 -070011051 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011052 } finally {
11053 Binder.restoreCallingIdentity(identity);
11054 }
11055 }
11056
11057 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011058 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011059 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011060 enforceModifyPermission();
11061
joonhunshin4ac60942023-11-15 15:23:39 +000011062 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11063 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11064
changbettyd5c246e2019-12-24 15:40:37 +080011065 final long identity = Binder.clearCallingIdentity();
11066 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011067 Phone phone = getPhone(subscriptionId);
11068 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011069
Ling Maf188d502022-09-16 15:22:36 -070011070 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011071 } finally {
11072 Binder.restoreCallingIdentity(identity);
11073 }
11074 }
11075
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011076 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011077 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011078 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11079 * otherwise.
11080 */
11081 @Override
11082 public void setCepEnabled(boolean isCepEnabled) {
11083 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11084
11085 final long identity = Binder.clearCallingIdentity();
11086 try {
11087 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11088 for (Phone phone : PhoneFactory.getPhones()) {
11089 Phone defaultPhone = phone.getImsPhone();
11090 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11091 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11092 ImsPhoneCallTracker imsPhoneCallTracker =
11093 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11094 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11095 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11096 + imsPhone.getMsisdn());
11097 }
11098 }
11099 } finally {
11100 Binder.restoreCallingIdentity(identity);
11101 }
11102 }
allenwtsu46dcc572020-01-08 18:24:03 +080011103
11104 /**
11105 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11106 *
11107 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11108 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11109 * before being read.
11110 */
11111 @Override
11112 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11113 isCompressed) {
11114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11115 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011116 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11117 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11118 }
joonhunshin4ac60942023-11-15 15:23:39 +000011119
11120 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11121 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11122 Binder.getCallingUserHandle())) {
11123 if (!isImsAvailableOnDevice()) {
11124 // ProvisioningManager can not handle ServiceSpecificException.
11125 // Throw the IllegalStateException and annotate ProvisioningManager.
11126 throw new IllegalStateException("IMS not available on device.");
11127 }
11128 } else {
11129 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11130 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11131 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011132 }
11133
11134 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011135 try {
Hui Wang761a6682020-10-31 05:12:53 +000011136 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11137 } finally {
11138 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011139 }
11140 }
zoey chene02881a2019-12-30 16:11:23 +080011141
11142 @Override
11143 public boolean isIccLockEnabled(int subId) {
11144 enforceReadPrivilegedPermission("isIccLockEnabled");
11145
joonhunshin4ac60942023-11-15 15:23:39 +000011146 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11147 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11148
zoey chene02881a2019-12-30 16:11:23 +080011149 // Now that all security checks passes, perform the operation as ourselves.
11150 final long identity = Binder.clearCallingIdentity();
11151 try {
11152 Phone phone = getPhone(subId);
11153 if (phone != null && phone.getIccCard() != null) {
11154 return phone.getIccCard().getIccLockEnabled();
11155 } else {
11156 return false;
11157 }
11158 } finally {
11159 Binder.restoreCallingIdentity(identity);
11160 }
11161 }
11162
11163 /**
11164 * Set the ICC pin lock enabled or disabled.
11165 *
11166 * @return an integer representing the status of IccLock enabled or disabled in the following
11167 * three cases:
11168 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11169 * successfully.
11170 * - Positive number and zero for remaining password attempts.
11171 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11172 *
11173 */
11174 @Override
11175 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11176 enforceModifyPermission();
11177
joonhunshin4ac60942023-11-15 15:23:39 +000011178 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11179 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11180
zoey chene02881a2019-12-30 16:11:23 +080011181 Phone phone = getPhone(subId);
11182 if (phone == null) {
11183 return 0;
11184 }
11185 // Now that all security checks passes, perform the operation as ourselves.
11186 final long identity = Binder.clearCallingIdentity();
11187 try {
11188 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11189 new Pair<Boolean, String>(enabled, password), phone, null);
11190 return attemptsRemaining;
11191
11192 } catch (Exception e) {
11193 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11194 } finally {
11195 Binder.restoreCallingIdentity(identity);
11196 }
11197 return 0;
11198 }
11199
11200 /**
11201 * Change the ICC password used in ICC pin lock.
11202 *
11203 * @return an integer representing the status of IccLock changed in the following three cases:
11204 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11205 * - Positive number and zero for remaining password attempts.
11206 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11207 *
11208 */
11209 @Override
11210 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11211 enforceModifyPermission();
11212
joonhunshin4ac60942023-11-15 15:23:39 +000011213 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11214 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11215
zoey chene02881a2019-12-30 16:11:23 +080011216 Phone phone = getPhone(subId);
11217 if (phone == null) {
11218 return 0;
11219 }
11220 // Now that all security checks passes, perform the operation as ourselves.
11221 final long identity = Binder.clearCallingIdentity();
11222 try {
11223 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11224 new Pair<String, String>(oldPassword, newPassword), phone, null);
11225 return attemptsRemaining;
11226
11227 } catch (Exception e) {
11228 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11229 } finally {
11230 Binder.restoreCallingIdentity(identity);
11231 }
11232 return 0;
11233 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011234
11235 /**
11236 * Request for receiving user activity notification
11237 */
11238 @Override
11239 public void requestUserActivityNotification() {
11240 if (!mNotifyUserActivity.get()
11241 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11242 mNotifyUserActivity.set(true);
11243 }
11244 }
11245
11246 /**
11247 * Called when userActivity is signalled in the power manager.
11248 * This is safe to call from any thread, with any window manager locks held or not.
11249 */
11250 @Override
11251 public void userActivity() {
11252 // ***************************************
11253 // * Inherited from PhoneWindowManager *
11254 // ***************************************
11255 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11256 // WITH ITS LOCKS HELD.
11257 //
11258 // This code must be VERY careful about the locks
11259 // it acquires.
11260 // In fact, the current code acquires way too many,
11261 // and probably has lurking deadlocks.
11262
11263 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11264 throw new SecurityException("Only the OS may call notifyUserActivity()");
11265 }
11266
11267 if (mNotifyUserActivity.getAndSet(false)) {
11268 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11269 USER_ACTIVITY_NOTIFICATION_DELAY);
11270 }
11271 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011272
11273 @Override
11274 public boolean canConnectTo5GInDsdsMode() {
11275 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11276 }
Jack Yud10cdd42020-09-28 20:28:01 -070011277
11278 @Override
11279 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11280 String callingFeatureId) {
11281 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11282 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11283 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11284 }
11285
joonhunshin4ac60942023-11-15 15:23:39 +000011286 enforceTelephonyFeatureWithException(callingPackage,
11287 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11288
Jack Yud10cdd42020-09-28 20:28:01 -070011289 Phone phone = getPhone(subId);
11290 if (phone == null) {
11291 throw new RuntimeException("phone is not available");
11292 }
11293 // Now that all security checks passes, perform the operation as ourselves.
11294 final long identity = Binder.clearCallingIdentity();
11295 try {
11296 return phone.getEquivalentHomePlmns();
11297 } finally {
11298 Binder.restoreCallingIdentity(identity);
11299 }
11300 }
Daniel Bright59e67312020-11-13 11:49:37 -080011301
11302 @Override
11303 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011304 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011305 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11306 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11307 "isRadioInterfaceCapabilitySupported");
11308
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011309 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011310 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011311 if (radioInterfaceCapabilities == null) {
11312 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011313 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011314 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011315 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011316
Hui Wang641e81c2020-10-12 12:14:23 -070011317 @Override
11318 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11319 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011320 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11321 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11322 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11323 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11324 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011325
11326 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11327 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11328
Hui Wang641e81c2020-10-12 12:14:23 -070011329 if (DBG) {
11330 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11331 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11332 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11333 }
11334
11335 if (!SubscriptionManager.isValidSubscriptionId(subId)
11336 || appType < TelephonyManager.APPTYPE_UNKNOWN
11337 || appType > TelephonyManager.APPTYPE_ISIM
11338 || nafUrl == null || securityProtocol == null || callback == null) {
11339 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11340 if (callback != null) {
11341 try {
11342 callback.onAuthenticationFailure(
11343 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11344 } catch (RemoteException exception) {
11345 log("Fail to notify onAuthenticationFailure due to " + exception);
11346 }
11347 return;
11348 }
11349 }
11350
11351 final long token = Binder.clearCallingIdentity();
11352 try {
11353 getGbaManager(subId).bootstrapAuthenticationRequest(
11354 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011355 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011356 } finally {
11357 Binder.restoreCallingIdentity(token);
11358 }
11359 }
11360
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011361 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011362 * Attempts to set the radio power state for all phones for thermal reason.
11363 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011364 * requested radio power state will actually be set. See {@link
11365 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11366 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011367 * @param enable {@code true} if trying to turn radio on.
11368 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11369 * false}.
11370 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011371 private boolean setRadioPowerForThermal(boolean enable) {
11372 boolean isPhoneAvailable = false;
11373 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11374 Phone phone = PhoneFactory.getPhone(i);
11375 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011376 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011377 isPhoneAvailable = true;
11378 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011379 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011380
11381 // return true if successfully informed the phone object about the thermal radio power
11382 // request.
11383 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011384 }
11385
11386 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011387 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011388 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11389 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11390 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11391 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11392 throw new IllegalArgumentException("modem does not support data throttling");
11393 }
11394
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011395 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11396 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011397 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011398 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11399 }
11400
Sarah Chinecc78c42022-03-31 21:16:48 -070011401 setDataEnabledForReason(
11402 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011403
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011404 if (isDataThrottlingSupported) {
11405 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011406 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011407 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11408 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11409 } else if (thermalMitigationResult
11410 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011411 log("Modem likely does not support data throttling on secondary carrier. Data " +
11412 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11413 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011414 }
11415 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011416 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011417
11418 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011419 }
11420
Jack Nudelman644b91a2021-03-12 14:09:48 -080011421 private static List<String> getThermalMitigationAllowlist(Context context) {
11422 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11423 for (String pckg : context.getResources()
11424 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11425 sThermalMitigationAllowlistedPackages.add(pckg);
11426 }
11427 }
11428
11429 return sThermalMitigationAllowlistedPackages;
11430 }
11431
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011432 private boolean isAnyPhoneInEmergencyState() {
11433 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11434 if (tm.isInEmergencyCall()) {
11435 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11436 return true;
11437 }
11438 for (Phone phone : PhoneFactory.getPhones()) {
11439 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11440 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011441 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11442 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011443 return true;
11444 }
11445 }
11446
11447 return false;
11448 }
11449
Jack Nudelman644b91a2021-03-12 14:09:48 -080011450 /**
11451 * Used by shell commands to add an authorized package name for thermal mitigation.
11452 * @param packageName name of package to be allowlisted
11453 * @param context
11454 */
11455 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11456 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11457 sThermalMitigationAllowlistedPackages.add(packageName);
11458 }
11459
11460 /**
11461 * Used by shell commands to remove an authorized package name for thermal mitigation.
11462 * @param packageName name of package to remove from allowlist
11463 * @param context
11464 */
11465 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11466 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11467 sThermalMitigationAllowlistedPackages.remove(packageName);
11468 }
11469
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011470 /**
11471 * Thermal mitigation request to control functionalities at modem.
11472 *
11473 * @param subId the id of the subscription.
11474 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011475 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011476 *
11477 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11478 */
11479 @Override
11480 @ThermalMitigationResult
11481 public int sendThermalMitigationRequest(
11482 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011483 ThermalMitigationRequest thermalMitigationRequest,
11484 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011485 enforceModifyPermission();
11486
Jack Nudelman644b91a2021-03-12 14:09:48 -080011487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011488
11489 enforceTelephonyFeatureWithException(callingPackage,
11490 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11491
Jack Nudelman644b91a2021-03-12 14:09:48 -080011492 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11493 .contains(callingPackage)) {
11494 throw new SecurityException("Calling package must be configured in the device config. "
11495 + "calling package: " + callingPackage);
11496 }
11497
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011498 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11499 final long identity = Binder.clearCallingIdentity();
11500
11501 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11502 try {
11503 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11504 switch (thermalMitigationAction) {
11505 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11506 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011507 handleDataThrottlingRequest(subId,
11508 thermalMitigationRequest.getDataThrottlingRequest(),
11509 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011510 break;
11511 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11512 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11513 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11514 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11515 }
11516
11517 // Ensure that radio is on. If not able to power on due to phone being
11518 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011519 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011520 thermalMitigationResult =
11521 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11522 break;
11523 }
11524
11525 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011526 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011527 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11528 break;
11529 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11530 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11531 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11532 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11533 }
11534
11535 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11536 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011537 Phone phone = getPhone(subId);
11538 if (phone == null) {
11539 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011540 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011541 break;
11542 }
11543
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011544 TelephonyConnectionService service =
11545 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011546 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011547 Log.e(LOG_TAG, "An emergency call is pending");
11548 thermalMitigationResult =
11549 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11550 break;
11551 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011552 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011553 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011554 break;
11555 }
11556 } else {
11557 thermalMitigationResult =
11558 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11559 break;
11560 }
11561
11562 // Turn radio off. If not able to power off due to phone being unavailable,
11563 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011564 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011565 thermalMitigationResult =
11566 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11567 break;
11568 }
11569 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011570 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011571 break;
11572 default:
11573 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11574 + "not exist. Requested action: " + thermalMitigationAction);
11575 }
11576 } catch (IllegalArgumentException e) {
11577 throw e;
11578 } catch (Exception e) {
11579 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11580 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11581 } finally {
11582 Binder.restoreCallingIdentity(identity);
11583 }
11584
11585 if (DBG) {
11586 log("thermalMitigationRequest returning with thermalMitigationResult: "
11587 + thermalMitigationResult);
11588 }
11589
11590 return thermalMitigationResult;
11591 }
Hui Wang641e81c2020-10-12 12:14:23 -070011592
11593 /**
11594 * Set the GbaService Package Name that Telephony will bind to.
11595 *
11596 * @param subId The sim that the GbaService is associated with.
11597 * @param packageName The name of the package to be replaced with.
11598 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11599 */
11600 @Override
11601 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11602 enforceModifyPermission();
11603
11604 final long identity = Binder.clearCallingIdentity();
11605 try {
11606 return getGbaManager(subId).overrideServicePackage(packageName);
11607 } finally {
11608 Binder.restoreCallingIdentity(identity);
11609 }
11610 }
11611
11612 /**
11613 * Return the package name of the currently bound GbaService.
11614 *
11615 * @param subId The sim that the GbaService is associated with.
11616 * @return the package name of the GbaService configuration, null if GBA is not supported.
11617 */
11618 @Override
11619 public String getBoundGbaService(int subId) {
11620 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11621
11622 final long identity = Binder.clearCallingIdentity();
11623 try {
11624 return getGbaManager(subId).getServicePackage();
11625 } finally {
11626 Binder.restoreCallingIdentity(identity);
11627 }
11628 }
11629
11630 /**
11631 * Set the release time for telephony to unbind GbaService.
11632 *
11633 * @param subId The sim that the GbaService is associated with.
11634 * @param interval The release time to unbind GbaService by millisecond.
11635 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11636 */
11637 @Override
11638 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11639 enforceModifyPermission();
11640
11641 final long identity = Binder.clearCallingIdentity();
11642 try {
11643 return getGbaManager(subId).overrideReleaseTime(interval);
11644 } finally {
11645 Binder.restoreCallingIdentity(identity);
11646 }
11647 }
11648
11649 /**
11650 * Return the release time for telephony to unbind GbaService.
11651 *
11652 * @param subId The sim that the GbaService is associated with.
11653 * @return The release time to unbind GbaService by millisecond.
11654 */
11655 @Override
11656 public int getGbaReleaseTime(int subId) {
11657 enforceReadPrivilegedPermission("getGbaReleaseTime");
11658
11659 final long identity = Binder.clearCallingIdentity();
11660 try {
11661 return getGbaManager(subId).getReleaseTime();
11662 } finally {
11663 Binder.restoreCallingIdentity(identity);
11664 }
11665 }
11666
11667 private GbaManager getGbaManager(int subId) {
11668 GbaManager instance = GbaManager.getInstance(subId);
11669 if (instance == null) {
11670 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11671 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11672 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11673 }
11674 return instance;
11675 }
Hui Wang761a6682020-10-31 05:12:53 +000011676
11677 /**
11678 * indicate whether the device and the carrier can support
11679 * RCS VoLTE single registration.
11680 */
11681 @Override
11682 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011683 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11684 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11685 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11686 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011687
11688 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11689 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11690 }
11691
11692 final long identity = Binder.clearCallingIdentity();
11693 try {
11694 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11695 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011696 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11697 if (isCapable != null) {
11698 return isCapable;
11699 }
Hui Wang761a6682020-10-31 05:12:53 +000011700 }
Hui Wang67af90e2021-06-04 16:57:15 -070011701 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11702 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011703 } finally {
11704 Binder.restoreCallingIdentity(identity);
11705 }
11706 }
11707
11708 /**
11709 * Register RCS provisioning callback.
11710 */
11711 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011712 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011713 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011714 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011715 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011716 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11717 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011718
11719 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11720 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11721 }
joonhunshin4ac60942023-11-15 15:23:39 +000011722 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11723 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11724 Binder.getCallingUserHandle())) {
11725 if (!isImsAvailableOnDevice()) {
11726 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11727 "IMS not available on device.");
11728 }
11729 } else {
11730 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11731 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011732 }
11733
11734 final long identity = Binder.clearCallingIdentity();
11735 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011736 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011737 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011738 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11739 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011740 }
Hui Wang761a6682020-10-31 05:12:53 +000011741 } finally {
11742 Binder.restoreCallingIdentity(identity);
11743 }
11744 }
11745
11746 /**
11747 * Unregister RCS provisioning callback.
11748 */
11749 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011750 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011751 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011752 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011753 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011754 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11755 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011756
11757 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11758 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11759 }
joonhunshin4ac60942023-11-15 15:23:39 +000011760
11761 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11762 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11763 Binder.getCallingUserHandle())) {
11764 if (!isImsAvailableOnDevice()) {
11765 // operation failed silently
11766 Rlog.w(LOG_TAG, "IMS not available on device.");
11767 return;
11768 }
11769 } else {
11770 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11771 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11772 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011773 }
11774
11775 final long identity = Binder.clearCallingIdentity();
11776 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011777 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011778 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011779 } finally {
11780 Binder.restoreCallingIdentity(identity);
11781 }
11782 }
11783
11784 /**
11785 * trigger RCS reconfiguration.
11786 */
11787 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011788 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11789 "triggerRcsReconfiguration",
11790 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011791
11792 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11793 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11794 }
joonhunshin4ac60942023-11-15 15:23:39 +000011795 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11796 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11797 Binder.getCallingUserHandle())) {
11798 if (!isImsAvailableOnDevice()) {
11799 // ProvisioningManager can not handle ServiceSpecificException.
11800 // Throw the IllegalStateException and annotate ProvisioningManager.
11801 throw new IllegalStateException("IMS not available on device.");
11802 }
11803 } else {
11804 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11805 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011806 }
11807
11808 final long identity = Binder.clearCallingIdentity();
11809 try {
11810 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11811 } finally {
11812 Binder.restoreCallingIdentity(identity);
11813 }
11814 }
11815
11816 /**
11817 * Provide the client configuration parameters of the RCS application.
11818 */
11819 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011820 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11821 "setRcsClientConfiguration",
11822 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011823
11824 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11825 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11826 }
joonhunshin4ac60942023-11-15 15:23:39 +000011827 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11828 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11829 Binder.getCallingUserHandle())) {
11830 if (!isImsAvailableOnDevice()) {
11831 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11832 "IMS not available on device.");
11833 }
11834 } else {
11835 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11836 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011837 }
11838
11839 final long identity = Binder.clearCallingIdentity();
11840
11841 try {
11842 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11843 if (configBinder == null) {
11844 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011845 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11846 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011847 } else {
11848 configBinder.setRcsClientConfiguration(rcc);
11849 }
joonhunshin3e154242021-09-17 06:33:39 +000011850
11851 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11852 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011853 } catch (RemoteException e) {
11854 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011855 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11856 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011857 } finally {
11858 Binder.restoreCallingIdentity(identity);
11859 }
11860 }
11861
11862 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011863 * Enables or disables the test mode for RCS VoLTE single registration.
11864 */
11865 @Override
11866 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11868 "setRcsSingleRegistrationTestModeEnabled");
11869
11870 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11871 }
11872
11873 /**
11874 * Gets the test mode for RCS VoLTE single registration.
11875 */
11876 @Override
11877 public boolean getRcsSingleRegistrationTestModeEnabled() {
11878 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11879 "getRcsSingleRegistrationTestModeEnabled");
11880
11881 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11882 }
11883
11884 /**
Hui Wang761a6682020-10-31 05:12:53 +000011885 * Overrides the config of RCS VoLTE single registration enabled for the device.
11886 */
11887 @Override
11888 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11889 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11890 "setDeviceSingleRegistrationEnabledOverride");
11891 enforceModifyPermission();
11892
11893 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11894 : Boolean.parseBoolean(enabledStr);
11895 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011896 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011897 }
11898
11899 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011900 * Sends a device to device communication message. Only usable via shell.
11901 * @param message message to send.
11902 * @param value message value.
11903 */
11904 @Override
11905 public void sendDeviceToDeviceMessage(int message, int value) {
11906 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011907 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011908 enforceModifyPermission();
11909
11910 final long identity = Binder.clearCallingIdentity();
11911 try {
11912 TelephonyConnectionService service =
11913 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11914 if (service == null) {
11915 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11916 return;
11917 }
11918 service.sendTestDeviceToDeviceMessage(message, value);
11919 } finally {
11920 Binder.restoreCallingIdentity(identity);
11921 }
11922 }
11923
Tyler Gunnbabbda02021-02-10 11:05:02 -080011924 /**
11925 * Sets the specified device to device transport active.
11926 * @param transport The transport to set active.
11927 */
11928 @Override
11929 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11930 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11931 "setActiveDeviceToDeviceTransport");
11932 enforceModifyPermission();
11933
11934 final long identity = Binder.clearCallingIdentity();
11935 try {
11936 TelephonyConnectionService service =
11937 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11938 if (service == null) {
11939 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11940 return;
11941 }
11942 service.setActiveDeviceToDeviceTransport(transport);
11943 } finally {
11944 Binder.restoreCallingIdentity(identity);
11945 }
11946 }
Tyler Gunn92479152021-01-20 16:30:10 -080011947
Tyler Gunnd4339262021-05-03 14:46:49 -070011948 @Override
11949 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11950 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11951 "setDeviceToDeviceForceEnabled");
11952
11953 final long identity = Binder.clearCallingIdentity();
11954 try {
11955 Arrays.stream(PhoneFactory.getPhones()).forEach(
11956 p -> {
11957 Phone thePhone = p.getImsPhone();
11958 if (thePhone != null && thePhone instanceof ImsPhone) {
11959 ImsPhone imsPhone = (ImsPhone) thePhone;
11960 CallTracker tracker = imsPhone.getCallTracker();
11961 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11962 ImsPhoneCallTracker imsPhoneCallTracker =
11963 (ImsPhoneCallTracker) tracker;
11964 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11965 }
11966 }
11967 }
11968 );
11969 } finally {
11970 Binder.restoreCallingIdentity(identity);
11971 }
11972 }
11973
Tyler Gunn92479152021-01-20 16:30:10 -080011974 /**
Hui Wang761a6682020-10-31 05:12:53 +000011975 * Gets the config of RCS VoLTE single registration enabled for the device.
11976 */
11977 @Override
11978 public boolean getDeviceSingleRegistrationEnabled() {
11979 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11980 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11981 }
11982
11983 /**
11984 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11985 */
11986 @Override
11987 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11988 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11989 "setCarrierSingleRegistrationEnabledOverride");
11990 enforceModifyPermission();
11991
11992 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11993 : Boolean.parseBoolean(enabledStr);
11994 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11995 subId, enabled);
11996 }
11997
11998 /**
11999 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12000 */
12001 @Override
12002 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12003 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12004 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12005 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012006
12007 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012008 * Overrides the ims feature validation result
12009 */
12010 @Override
12011 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12012 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12013 "setImsFeatureValidationOverride");
12014
12015 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12016 : Boolean.parseBoolean(enabledStr);
12017 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12018 subId, enabled);
12019 }
12020
12021 /**
12022 * Gets the ims feature validation override value
12023 */
12024 @Override
12025 public boolean getImsFeatureValidationOverride(int subId) {
12026 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12027 "getImsFeatureValidationOverride");
12028 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12029 }
12030
12031 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012032 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12033 * their mobile plan.
12034 */
12035 @Override
12036 public String getMobileProvisioningUrl() {
12037 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12038 final long identity = Binder.clearCallingIdentity();
12039 try {
12040 return getDefaultPhone().getMobileProvisioningUrl();
12041 } finally {
12042 Binder.restoreCallingIdentity(identity);
12043 }
12044 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012045
James.cf Linbcdf8b32021-01-14 16:44:13 +080012046 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012047 * Get the EAB contact from the EAB database.
12048 */
12049 @Override
12050 public String getContactFromEab(String contact) {
12051 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12052 enforceModifyPermission();
12053 final long identity = Binder.clearCallingIdentity();
12054 try {
12055 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12056 } finally {
12057 Binder.restoreCallingIdentity(identity);
12058 }
12059 }
12060
12061 /**
Calvin Pana1434322021-07-01 19:27:01 +080012062 * Get the EAB capability from the EAB database.
12063 */
12064 @Override
12065 public String getCapabilityFromEab(String contact) {
12066 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12067 enforceModifyPermission();
12068 final long identity = Binder.clearCallingIdentity();
12069 try {
12070 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12071 } finally {
12072 Binder.restoreCallingIdentity(identity);
12073 }
12074 }
12075
12076 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012077 * Remove the EAB contacts from the EAB database.
12078 */
12079 @Override
12080 public int removeContactFromEab(int subId, String contacts) {
12081 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12082 enforceModifyPermission();
12083 final long identity = Binder.clearCallingIdentity();
12084 try {
12085 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12086 } finally {
12087 Binder.restoreCallingIdentity(identity);
12088 }
12089 }
12090
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012091 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012092 public boolean getDeviceUceEnabled() {
12093 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12094 final long identity = Binder.clearCallingIdentity();
12095 try {
12096 return mApp.getDeviceUceEnabled();
12097 } finally {
12098 Binder.restoreCallingIdentity(identity);
12099 }
12100 }
12101
12102 @Override
12103 public void setDeviceUceEnabled(boolean isEnabled) {
12104 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12105 final long identity = Binder.clearCallingIdentity();
12106 try {
12107 mApp.setDeviceUceEnabled(isEnabled);
12108 } finally {
12109 Binder.restoreCallingIdentity(identity);
12110 }
12111 }
12112
Brad Ebinger14d467f2021-02-12 06:18:28 +000012113 /**
12114 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12115 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12116 */
12117 // Used for SHELL command only right now.
12118 @Override
12119 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12120 List<String> featureTags) {
12121 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12122 "addUceRegistrationOverrideShell");
12123 final long identity = Binder.clearCallingIdentity();
12124 try {
12125 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12126 new ArraySet<>(featureTags));
12127 } catch (ImsException e) {
12128 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12129 } finally {
12130 Binder.restoreCallingIdentity(identity);
12131 }
12132 }
12133
12134 /**
12135 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12136 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12137 */
12138 // Used for SHELL command only right now.
12139 @Override
12140 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12141 List<String> featureTags) {
12142 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12143 "removeUceRegistrationOverrideShell");
12144 final long identity = Binder.clearCallingIdentity();
12145 try {
12146 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12147 new ArraySet<>(featureTags));
12148 } catch (ImsException e) {
12149 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12150 } finally {
12151 Binder.restoreCallingIdentity(identity);
12152 }
12153 }
12154
12155 /**
12156 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12157 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12158 */
12159 // Used for SHELL command only right now.
12160 @Override
12161 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12162 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12163 "clearUceRegistrationOverrideShell");
12164 final long identity = Binder.clearCallingIdentity();
12165 try {
12166 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12167 } catch (ImsException e) {
12168 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12169 } finally {
12170 Binder.restoreCallingIdentity(identity);
12171 }
12172 }
12173
12174 /**
12175 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12176 */
12177 // Used for SHELL command only right now.
12178 @Override
12179 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12180 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12181 "getLatestRcsContactUceCapabilityShell");
12182 final long identity = Binder.clearCallingIdentity();
12183 try {
12184 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12185 } catch (ImsException e) {
12186 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12187 } finally {
12188 Binder.restoreCallingIdentity(identity);
12189 }
12190 }
12191
12192 /**
12193 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12194 * device does not have an active PUBLISH.
12195 */
12196 // Used for SHELL command only right now.
12197 @Override
12198 public String getLastUcePidfXmlShell(int subId) {
12199 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12200 final long identity = Binder.clearCallingIdentity();
12201 try {
12202 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12203 } catch (ImsException e) {
12204 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12205 } finally {
12206 Binder.restoreCallingIdentity(identity);
12207 }
12208 }
12209
James.cf Line8713a42021-04-29 16:04:26 +080012210 /**
12211 * Remove UCE requests cannot be sent to the network status.
12212 */
12213 // Used for SHELL command only right now.
12214 @Override
12215 public boolean removeUceRequestDisallowedStatus(int subId) {
12216 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12217 final long identity = Binder.clearCallingIdentity();
12218 try {
12219 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12220 } catch (ImsException e) {
12221 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12222 } finally {
12223 Binder.restoreCallingIdentity(identity);
12224 }
12225 }
12226
James.cf Lin18bb9002021-05-25 01:37:38 +080012227 /**
12228 * Remove UCE requests cannot be sent to the network status.
12229 */
12230 // Used for SHELL command only.
12231 @Override
12232 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12233 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12234 final long identity = Binder.clearCallingIdentity();
12235 try {
12236 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12237 } catch (ImsException e) {
12238 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12239 } finally {
12240 Binder.restoreCallingIdentity(identity);
12241 }
12242 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012243
James.cf Lin4b784aa2021-01-31 03:25:15 +080012244 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012245 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12246 String callingPackage) {
12247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12248 mApp, subId, "setSignalStrengthUpdateRequest");
12249
joonhunshin4ac60942023-11-15 15:23:39 +000012250 enforceTelephonyFeatureWithException(callingPackage,
12251 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12252
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012253 final int callingUid = Binder.getCallingUid();
12254 // Verify that tha callingPackage belongs to the calling UID
12255 mApp.getSystemService(AppOpsManager.class)
12256 .checkPackage(callingUid, callingPackage);
12257
Rambo Wang3607f502021-02-01 21:51:40 -080012258 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012259
12260 final long identity = Binder.clearCallingIdentity();
12261 try {
12262 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12263 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12264
12265 if (result instanceof IllegalStateException) {
12266 throw (IllegalStateException) result;
12267 }
12268 } finally {
12269 Binder.restoreCallingIdentity(identity);
12270 }
12271 }
12272
12273 @Override
12274 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12275 String callingPackage) {
12276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12277 mApp, subId, "clearSignalStrengthUpdateRequest");
12278
joonhunshin4ac60942023-11-15 15:23:39 +000012279 enforceTelephonyFeatureWithException(callingPackage,
12280 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12281
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012282 final int callingUid = Binder.getCallingUid();
12283 // Verify that tha callingPackage belongs to the calling UID
12284 mApp.getSystemService(AppOpsManager.class)
12285 .checkPackage(callingUid, callingPackage);
12286
12287 final long identity = Binder.clearCallingIdentity();
12288 try {
12289 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12290 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12291
12292 if (result instanceof IllegalStateException) {
12293 throw (IllegalStateException) result;
12294 }
12295 } finally {
12296 Binder.restoreCallingIdentity(identity);
12297 }
12298 }
12299
Rambo Wang3607f502021-02-01 21:51:40 -080012300 private static void validateSignalStrengthUpdateRequest(Context context,
12301 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012302 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12303 // phone/system process do not have further restriction on request
12304 return;
12305 }
12306
12307 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012308 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012309 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012310 context.enforceCallingOrSelfPermission(
12311 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12312 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012313 }
12314
12315 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012316 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012317 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012318 || info.isEnabled()) {
12319 throw new IllegalArgumentException(
12320 "Only system can set hide fields in SignalThresholdInfo");
12321 }
12322
12323 // Thresholds length for each RAN need in range. This has been validated in
12324 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12325 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12326 final int[] thresholds = info.getThresholds();
12327 Objects.requireNonNull(thresholds);
12328 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12329 || thresholds.length
12330 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12331 throw new IllegalArgumentException(
12332 "thresholds length is out of range: " + thresholds.length);
12333 }
12334 }
12335 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012336
12337 /**
12338 * Gets the current phone capability.
12339 *
12340 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12341 * @return the PhoneCapability which describes the data connection capability of modem.
12342 * It's used to evaluate possible phone config change, for example from single
12343 * SIM device to multi-SIM device.
12344 */
12345 @Override
12346 public PhoneCapability getPhoneCapability() {
12347 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012348
12349 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12350 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12351
SongFerngWang8236caa2021-01-17 21:51:44 +080012352 final long identity = Binder.clearCallingIdentity();
12353 try {
12354 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12355 } finally {
12356 Binder.restoreCallingIdentity(identity);
12357 }
12358 }
Michele Berionne5e411512020-11-13 02:36:59 +000012359
12360 /**
12361 * Prepare TelephonyManager for an unattended reboot. The reboot is
12362 * required to be done shortly after the API is invoked.
12363 */
12364 @Override
12365 @TelephonyManager.PrepareUnattendedRebootResult
12366 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012367 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012368 enforceRebootPermission();
12369
joonhunshin4ac60942023-11-15 15:23:39 +000012370 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12371 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12372
Michele Berionne5e411512020-11-13 02:36:59 +000012373 final long identity = Binder.clearCallingIdentity();
12374 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012375 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012376 } finally {
12377 Binder.restoreCallingIdentity(identity);
12378 }
12379 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012380
12381 /**
12382 * Request to get the current slicing configuration including URSP rules and
12383 * NSSAIs (configured, allowed and rejected).
12384 *
12385 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12386 */
12387 @Override
12388 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012389 TelephonyPermissions
12390 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12391 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012392
joonhunshin4ac60942023-11-15 15:23:39 +000012393 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12394 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12395 "getSlicingConfig");
12396
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012397 final long identity = Binder.clearCallingIdentity();
12398 try {
12399 Phone phone = getDefaultPhone();
12400 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12401 } finally {
12402 Binder.restoreCallingIdentity(identity);
12403 }
12404 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012405
12406 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012407 * Check whether the given premium capability is available for purchase from the carrier.
12408 *
12409 * @param capability The premium capability to check.
12410 * @param subId The subId to check the premium capability for.
12411 *
12412 * @return Whether the given premium capability is available to purchase.
12413 */
12414 @Override
12415 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12416 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12417 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12418 log("Premium capability "
12419 + TelephonyManager.convertPremiumCapabilityToString(capability)
12420 + " is not available for purchase due to missing permissions.");
12421 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12422 + "permission READ_BASIC_PHONE_STATE.");
12423 }
12424
joonhunshin4ac60942023-11-15 15:23:39 +000012425 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12426 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12427
Sarah Chin2ec39f62022-08-31 17:03:26 -070012428 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012429 if (phone == null) {
12430 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12431 return false;
12432 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012433 final long identity = Binder.clearCallingIdentity();
12434 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012435 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012436 .isPremiumCapabilityAvailableForPurchase(capability);
12437 } finally {
12438 Binder.restoreCallingIdentity(identity);
12439 }
12440 }
12441
12442 /**
12443 * Purchase the given premium capability from the carrier.
12444 *
12445 * @param capability The premium capability to purchase.
12446 * @param callback The result of the purchase request.
12447 * @param subId The subId to purchase the premium capability for.
12448 */
12449 @Override
12450 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12451 log("purchasePremiumCapability: capability="
12452 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12453 + getCurrentPackageName());
12454
12455 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12456 mApp, "purchasePremiumCapability")) {
12457 log("purchasePremiumCapability "
12458 + TelephonyManager.convertPremiumCapabilityToString(capability)
12459 + " failed due to missing permissions.");
12460 throw new SecurityException("purchasePremiumCapability requires permission "
12461 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012462 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12463 mApp, "purchasePremiumCapability")) {
12464 log("purchasePremiumCapability "
12465 + TelephonyManager.convertPremiumCapabilityToString(capability)
12466 + " failed due to missing permissions.");
12467 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012468 }
12469
joonhunshin4ac60942023-11-15 15:23:39 +000012470 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12471 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12472
Sarah Chin2ec39f62022-08-31 17:03:26 -070012473 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012474 if (phone == null) {
12475 try {
12476 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12477 callback.accept(result);
12478 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12479 } catch (RemoteException e) {
12480 String logStr = "Purchase premium capability "
12481 + TelephonyManager.convertPremiumCapabilityToString(capability)
12482 + " failed due to RemoteException handling null phone: " + e;
12483 if (DBG) log(logStr);
12484 AnomalyReporter.reportAnomaly(
12485 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12486 }
12487 return;
12488 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012489
12490 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012491 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012492 callingProcess = mApp.getPackageManager().getApplicationInfo(
12493 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012494 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012495 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012496 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012497
12498 boolean isVisible = false;
12499 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12500 if (am != null) {
12501 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12502 if (processes != null) {
12503 for (ActivityManager.RunningAppProcessInfo process : processes) {
12504 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012505 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012506 if (process.processName.equals(callingProcess) && process.importance
12507 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12508 isVisible = true;
12509 break;
12510 }
12511 }
12512 }
12513 }
12514
12515 if (!isVisible) {
12516 try {
12517 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12518 callback.accept(result);
12519 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12520 } catch (RemoteException e) {
12521 String logStr = "Purchase premium capability "
12522 + TelephonyManager.convertPremiumCapabilityToString(capability)
12523 + " failed due to RemoteException handling background application: " + e;
12524 if (DBG) log(logStr);
12525 AnomalyReporter.reportAnomaly(
12526 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12527 }
12528 return;
12529 }
12530
Sarah Chin71b3a852022-09-28 15:54:19 -070012531 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012532 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012533 }
12534
12535 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012536 * Register an IMS connection state callback
12537 */
12538 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012539 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12540 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012541 if (feature == ImsFeature.FEATURE_MMTEL) {
12542 // ImsMmTelManager
12543 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12544 TelephonyPermissions
12545 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12546 mApp, subId, "registerImsStateCallback");
12547 } else if (feature == ImsFeature.FEATURE_RCS) {
12548 // ImsRcsManager or SipDelegateManager
12549 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12550 Binder.getCallingUid(), "registerImsStateCallback",
12551 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12552 Manifest.permission.READ_PRECISE_PHONE_STATE,
12553 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12554 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12555 }
12556
12557 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12558 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12559 "IMS not available on device.");
12560 }
12561
12562 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12563 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12564 }
12565
12566 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12567 if (controller == null) {
12568 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12569 "IMS not available on device.");
12570 }
12571
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012572 if (callingPackage == null) {
12573 callingPackage = getCurrentPackageName();
12574 }
12575
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012576 final long token = Binder.clearCallingIdentity();
12577 try {
12578 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012579 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012580 } catch (ImsException e) {
12581 throw new ServiceSpecificException(e.getCode());
12582 } finally {
12583 Binder.restoreCallingIdentity(token);
12584 }
12585 }
12586
12587 /**
12588 * Unregister an IMS connection state callback
12589 */
12590 @Override
12591 public void unregisterImsStateCallback(IImsStateCallback cb) {
12592 final long token = Binder.clearCallingIdentity();
12593 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12594 if (controller == null) {
12595 return;
12596 }
12597 try {
12598 controller.unregisterImsStateCallback(cb);
12599 } finally {
12600 Binder.restoreCallingIdentity(token);
12601 }
12602 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012603
12604 /**
12605 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12606 *
12607 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012608 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012609 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012610 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012611 * If there is current registered network this value will be same as the registered cell
12612 * identity. If the device goes out of service the previous cell identity is cached and
12613 * will be returned. If the cache age of the Cell identity is more than 24 hours
12614 * it will be cleared and null will be returned.
12615 *
12616 */
12617 @Override
12618 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12619 String callingFeatureId) {
12620 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12621 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12622 LocationAccessPolicy.checkLocationPermission(mApp,
12623 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12624 .setCallingPackage(callingPackage)
12625 .setCallingFeatureId(callingFeatureId)
12626 .setCallingPid(Binder.getCallingPid())
12627 .setCallingUid(Binder.getCallingUid())
12628 .setMethod("getLastKnownCellIdentity")
12629 .setLogAsInfo(true)
12630 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12631 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12632 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12633 .build());
12634
12635 boolean hasFinePermission =
12636 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12637 if (!hasFinePermission
12638 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12639 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012640 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012641 }
12642
12643 final long identity = Binder.clearCallingIdentity();
12644 try {
Ling Mac28f0212023-03-24 16:07:15 -070012645 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012646 if (sst == null) return null;
12647 return sst.getLastKnownCellIdentity();
12648 } finally {
12649 Binder.restoreCallingIdentity(identity);
12650 }
12651 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012652
jimsun3b9ccac2021-10-26 15:01:23 +080012653 /**
12654 * Sets the modem service class Name that Telephony will bind to.
12655 *
12656 * @param serviceName The class name of the modem service.
12657 * @return true if the operation is succeed, otherwise false.
12658 */
12659 public boolean setModemService(String serviceName) {
12660 Log.d(LOG_TAG, "setModemService - " + serviceName);
12661 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012663 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12664 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012665 return mPhoneConfigurationManager.setModemService(serviceName);
12666 }
12667
12668 /**
12669 * Return the class name of the currently bounded modem service.
12670 *
12671 * @return the class name of the modem service.
12672 */
12673 public String getModemService() {
12674 String result;
12675 Log.d(LOG_TAG, "getModemService");
12676 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12677 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012678 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012679 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12680 "getModemService");
12681 result = mPhoneConfigurationManager.getModemService();
12682 Log.d(LOG_TAG, "result = " + result);
12683 return result;
12684 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012685
Hakjun Choi3ee81112023-12-19 15:40:58 +000012686 /**
12687 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12688 * including carrier config, entitlement server, and config update.
12689 *
12690 * @param subId subId The subscription ID of the carrier.
12691 *
12692 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12693 * be returned.
12694 *
12695 * @throws SecurityException if the caller doesn't have the required permission.
12696 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012697 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12698 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012699 final long identity = Binder.clearCallingIdentity();
12700 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012701 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012702 } finally {
12703 Binder.restoreCallingIdentity(identity);
12704 }
12705 }
12706
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012707 @Override
12708 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12709 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12710 mApp.enforceCallingOrSelfPermission(
12711 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12713
12714 final long identity = Binder.clearCallingIdentity();
12715 try {
12716 Phone phone = getPhone(subId);
12717 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012718 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12719 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012720 phone.setVoiceServiceStateOverride(hasService);
12721 } finally {
12722 Binder.restoreCallingIdentity(identity);
12723 }
12724 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012725
12726 /**
12727 * set removable eSIM as default eUICC.
12728 *
12729 * @hide
12730 */
12731 @Override
12732 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12733 enforceModifyPermission();
12734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12735
12736 final long identity = Binder.clearCallingIdentity();
12737 try {
12738 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12739 } finally {
12740 Binder.restoreCallingIdentity(identity);
12741 }
12742 }
12743
12744 /**
12745 * Returns whether the removable eSIM is default eUICC or not.
12746 *
12747 * @hide
12748 */
12749 @Override
12750 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12751 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12752 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12753
12754 final long identity = Binder.clearCallingIdentity();
12755 try {
12756 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12757 } finally {
12758 Binder.restoreCallingIdentity(identity);
12759 }
12760 }
12761
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012762 /**
12763 * Get the component name of the default app to direct respond-via-message intent for the
12764 * user associated with this subscription, update the cache if there is no respond-via-message
12765 * application currently configured for this user.
12766 * @return component name of the app and class to direct Respond Via Message intent to, or
12767 * {@code null} if the functionality is not supported.
12768 * @hide
12769 */
12770 @Override
12771 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12772 boolean updateIfNeeded) {
12773 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012774
joonhunshin4ac60942023-11-15 15:23:39 +000012775 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12776 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12777 "getDefaultRespondViaMessageApplication");
12778
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012779 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12780
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012781 UserHandle userHandle = null;
12782 final long identity = Binder.clearCallingIdentity();
12783 try {
12784 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12785 } finally {
12786 Binder.restoreCallingIdentity(identity);
12787 }
12788 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12789 updateIfNeeded, userHandle);
12790 }
Jack Yuf5badd92022-12-08 00:50:53 -080012791
12792 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012793 * Set whether the device is able to connect with null ciphering or integrity
12794 * algorithms. This is a global setting and will apply to all active subscriptions
12795 * and all new subscriptions after this.
12796 *
12797 * @param enabled when true, null cipher and integrity algorithms are allowed.
12798 * @hide
12799 */
12800 @Override
12801 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12802 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12803 enforceModifyPermission();
12804 checkForNullCipherAndIntegritySupport();
12805
12806 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12807 // for listening to these preference changes and applying them immediately.
12808 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12809 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12810 editor.apply();
12811
12812 for (Phone phone: PhoneFactory.getPhones()) {
12813 phone.handleNullCipherEnabledChange();
12814 }
12815 }
12816
12817
12818 /**
12819 * Get whether the device is able to connect with null ciphering or integrity
12820 * algorithms. Note that this retrieves the phone-global preference and not
12821 * the state of the radio.
12822 *
12823 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12824 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12825 * version for this feature.
12826 * @hide
12827 */
12828 @Override
12829 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12830 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12831 enforceReadPermission();
12832 checkForNullCipherAndIntegritySupport();
12833 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12834 }
12835
12836 private void checkForNullCipherAndIntegritySupport() {
12837 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12838 throw new UnsupportedOperationException(
12839 "Null cipher and integrity operations require HAL 2.1 or above");
12840 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012841 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12842 throw new UnsupportedOperationException(
12843 "Null cipher and integrity operations unsupported by modem");
12844 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012845 }
12846
Gil Cukierman06403e12023-11-29 16:33:03 +000012847 private void checkForIdentifierDisclosureNotificationSupport() {
12848 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12849 throw new UnsupportedOperationException(
12850 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12851 + "above");
12852 }
12853 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12854 throw new UnsupportedOperationException(
12855 "Cellular identifier disclosure transparency operations unsupported by modem");
12856 }
12857 }
12858
Michael Groover826b71d2023-12-21 22:08:06 -060012859 private void checkForNullCipherNotificationSupport() {
12860 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12861 throw new UnsupportedOperationException(
12862 "Null cipher notification operations require HAL 2.2 or above");
12863 }
12864 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12865 throw new UnsupportedOperationException(
12866 "Null cipher notification operations unsupported by modem");
12867 }
12868 }
12869
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012870 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012871 * Get the SIM state for the slot index.
12872 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12873 *
12874 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12875 */
12876 @Override
12877 @SimState
12878 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012879 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12880 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12881
Jack Yuf5badd92022-12-08 00:50:53 -080012882 IccCardConstants.State simState;
12883 if (slotIndex < 0) {
12884 simState = IccCardConstants.State.UNKNOWN;
12885 } else {
12886 Phone phone = null;
12887 try {
12888 phone = PhoneFactory.getPhone(slotIndex);
12889 } catch (IllegalStateException e) {
12890 // ignore
12891 }
12892 if (phone == null) {
12893 simState = IccCardConstants.State.UNKNOWN;
12894 } else {
12895 IccCard icc = phone.getIccCard();
12896 if (icc == null) {
12897 simState = IccCardConstants.State.UNKNOWN;
12898 } else {
12899 simState = icc.getState();
12900 }
12901 }
12902 }
12903 return simState.ordinal();
12904 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012905
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012906 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12907 boolean enableLogcat,
12908 long logcatStartTimestampMillis, boolean enableTelecomDump,
12909 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012910 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012911 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12912 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12913 ecdDataBuilder
12914 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12915 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012916 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012917 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012918 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012919 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12920 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012921 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12922 Executors.newCachedThreadPool(), db,
12923 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012924 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012925 }
12926
12927 /**
12928 * Request telephony to persist state for debugging emergency call failures.
12929 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012930 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012931 * @param enableLogcat whether to collect logcat output
12932 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12933 * @param enableTelecomDump whether to collect telecom dumpsys
12934 * @param enableTelephonyDump whether to collect telephony dumpsys
12935 */
12936 @Override
12937 @RequiresPermission(android.Manifest.permission.DUMP)
12938 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12939 long logcatStartTimestampMillis, boolean enableTelecomDump,
12940 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012941 // Verify that the caller has READ_DROPBOX_DATA permission.
12942 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12943 && Flags.enableReadDropboxPermission()) {
12944 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12945 "persistEmergencyCallDiagnosticData");
12946 } else {
12947 // Otherwise, enforce legacy permission.
12948 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12949 "persistEmergencyCallDiagnosticData");
12950 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012951 final long identity = Binder.clearCallingIdentity();
12952 try {
12953 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12954 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12955
12956 } finally {
12957 Binder.restoreCallingIdentity(identity);
12958 }
12959 }
12960
Hui Wang9b5793a2022-12-05 14:38:06 -060012961 /**
12962 * Get current cell broadcast ranges.
12963 */
12964 @Override
12965 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12966 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12967 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12968 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012969
12970 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12971 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12972
Hui Wang9b5793a2022-12-05 14:38:06 -060012973 final long identity = Binder.clearCallingIdentity();
12974 try {
12975 return getPhone(subId).getCellBroadcastIdRanges();
12976 } finally {
12977 Binder.restoreCallingIdentity(identity);
12978 }
12979 }
12980
12981 /**
12982 * Set reception of cell broadcast messages with the list of the given ranges
12983 *
12984 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12985 */
12986 @Override
12987 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12988 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12989 @Nullable IIntegerConsumer callback) {
12990 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12991 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012992
12993 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12994 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12995
Hui Wang9b5793a2022-12-05 14:38:06 -060012996 final long identity = Binder.clearCallingIdentity();
12997 try {
12998 Phone phone = getPhoneFromSubId(subId);
12999 if (DBG) {
13000 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13001 }
13002 phone.setCellBroadcastIdRanges(ranges, result -> {
13003 if (callback != null) {
13004 try {
13005 callback.accept(result);
13006 } catch (RemoteException e) {
13007 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13008 }
13009 }
13010 });
13011 } finally {
13012 Binder.restoreCallingIdentity(identity);
13013 }
13014 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013015
13016 /**
13017 * Returns whether the device supports the domain selection service.
13018 *
13019 * @return {@code true} if the device supports the domain selection service.
13020 */
13021 @Override
13022 public boolean isDomainSelectionSupported() {
13023 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13024 "isDomainSelectionSupported");
13025
13026 final long identity = Binder.clearCallingIdentity();
13027 try {
13028 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13029 } finally {
13030 Binder.restoreCallingIdentity(identity);
13031 }
13032 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013033
13034 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013035 * Returns whether the AOSP domain selection service is supported.
13036 *
13037 * @return {@code true} if the AOSP domain selection service is supported,
13038 * {@code false} otherwise.
13039 */
13040 @Override
13041 public boolean isAospDomainSelectionService() {
13042 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13043 "isAospDomainSelectionService");
13044
13045 final long identity = Binder.clearCallingIdentity();
13046 try {
13047 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13048 String dssComponentName = mApp.getResources().getString(
13049 R.string.config_domain_selection_service_component_name);
13050 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13051 TelephonyDomainSelectionService.class.getName());
13052 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13053 + ", aosp=" + componentName.flattenToString());
13054 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13055 }
13056 } finally {
13057 Binder.restoreCallingIdentity(identity);
13058 }
13059 return false;
13060 }
13061
13062 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013063 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13064 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13065 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013066 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013067 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013068 * @param enableSatellite {@code true} to enable the satellite modem and
13069 * {@code false} to disable.
13070 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013071 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013072 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013073 *
13074 * @throws SecurityException if the caller doesn't have the required permission.
13075 */
13076 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013077 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013078 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013079 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013080 if (enableSatellite) {
13081 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13082 @Override
13083 protected void onReceiveResult(int resultCode, Bundle resultData) {
13084 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13085 + ", resultData=" + resultData);
13086 boolean isAllowed = false;
13087 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13088 callback::accept);
13089 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13090 if (resultData != null
13091 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13092 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13093 } else {
13094 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13095 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013096 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013097 result.accept(resultCode);
13098 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013099 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013100 if (isAllowed) {
13101 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013102 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013103 } else {
13104 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13105 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013106 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013107 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013108 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013109 subId, resultReceiver);
13110 } else {
13111 // No need to check if satellite is allowed at current location when disabling satellite
13112 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013113 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013114 }
Sarah Chin503828c2023-02-01 23:54:20 -080013115 }
13116
13117 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013118 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013119 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013120 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013121 * @param result The result receiver that returns whether the satellite modem is enabled
13122 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013123 *
13124 * @throws SecurityException if the caller doesn't have the required permission.
13125 */
13126 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013127 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13128 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013129 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013130 }
13131
13132 /**
Sarah Chin43457982023-02-15 17:50:38 -080013133 * Request to get whether the satellite service demo mode is enabled.
13134 *
13135 * @param subId The subId of the subscription to check whether the satellite demo mode
13136 * is enabled for.
13137 * @param result The result receiver that returns whether the satellite demo mode is enabled
13138 * if the request is successful or an error code if the request failed.
13139 *
13140 * @throws SecurityException if the caller doesn't have the required permission.
13141 */
13142 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013143 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13144 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13145 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013146 }
13147
13148 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013149 * Request to get whether the satellite service is enabled with emergency mode.
13150 *
13151 * @param subId The subId of the subscription to check whether the satellite demo mode
13152 * is enabled for.
13153 * @param result The result receiver that returns whether the satellite emergency mode is
13154 * enabled if the request is successful or an error code if the request failed.
13155 *
13156 * @throws SecurityException if the caller doesn't have the required permission.
13157 */
13158 @Override
13159 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13160 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13161 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13162 }
13163
13164 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013165 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013166 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013167 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013168 * @param result The result receiver that returns whether the satellite service is supported on
13169 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013170 */
13171 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013172 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013173 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013174 }
13175
13176 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013177 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013178 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013179 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013180 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13181 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013182 *
13183 * @throws SecurityException if the caller doesn't have required permission.
13184 */
13185 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013186 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13187 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013188 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013189 }
13190
13191 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013192 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013193 * This can be called by the pointing UI when the user starts pointing to the satellite.
13194 * Modem should continue to report the pointing input as the device or satellite moves.
13195 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013196 * @param subId The subId of the subscription to start satellite transmission updates for.
13197 * @param resultCallback The callback to get the result of the request.
13198 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013199 *
13200 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013201 */
13202 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013203 public void startSatelliteTransmissionUpdates(int subId,
13204 @NonNull IIntegerConsumer resultCallback,
13205 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13206 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13207 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013208 }
13209
13210 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013211 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013212 * This can be called by the pointing UI when the user stops pointing to the satellite.
13213 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013214 * @param subId The subId of the subscription to stop satellite transmission updates for.
13215 * @param resultCallback The callback to get the result of the request.
13216 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13217 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013218 *
13219 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013220 */
13221 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013222 public void stopSatelliteTransmissionUpdates(int subId,
13223 @NonNull IIntegerConsumer resultCallback,
13224 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13225 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13226 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013227 }
13228
13229 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013230 * Register the subscription with a satellite provider.
13231 * This is needed to register the subscription if the provider allows dynamic registration.
13232 *
13233 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013234 * @param token The token to be used as a unique identifier for provisioning with satellite
13235 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013236 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013237 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013238 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013239 * @return The signal transport used by the caller to cancel the provision request,
13240 * or {@code null} if the request failed.
13241 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013242 * @throws SecurityException if the caller doesn't have the required permission.
13243 */
13244 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013245 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013246 @NonNull String token, @NonNull byte[] provisionData,
13247 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013248 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013249 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13250 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013251 }
13252
13253 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013254 * Unregister the device/subscription with the satellite provider.
13255 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013256 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013257 * should report as deprovisioned.
13258 *
13259 * @param subId The subId of the subscription to be deprovisioned.
13260 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013261 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013262 *
13263 * @throws SecurityException if the caller doesn't have the required permission.
13264 */
13265 @Override
13266 public void deprovisionSatelliteService(int subId,
13267 @NonNull String token, @NonNull IIntegerConsumer callback) {
13268 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013269 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013270 }
13271
13272 /**
Sarah Chin43457982023-02-15 17:50:38 -080013273 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013274 *
Sarah Chin43457982023-02-15 17:50:38 -080013275 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013276 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013277 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013278 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013279 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013280 * @throws SecurityException if the caller doesn't have the required permission.
13281 */
13282 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013283 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13284 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013285 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013286 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013287 }
13288
13289 /**
Sarah Chin43457982023-02-15 17:50:38 -080013290 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013291 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013292 *
Sarah Chin43457982023-02-15 17:50:38 -080013293 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013294 * @param callback The callback that was passed to
13295 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013296 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013297 * @throws SecurityException if the caller doesn't have the required permission.
13298 */
13299 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013300 public void unregisterForSatelliteProvisionStateChanged(
13301 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013302 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013303 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013304 }
13305
13306 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013307 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013308 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013309 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013310 * @param result The result receiver that returns whether the device is provisioned with a
13311 * satellite provider if the request is successful or an error code if the
13312 * request failed.
13313 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013314 * @throws SecurityException if the caller doesn't have the required permission.
13315 */
13316 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013317 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13318 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013319 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013320 }
13321
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013322 /**
Sarah Chin43457982023-02-15 17:50:38 -080013323 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013324 *
Sarah Chin43457982023-02-15 17:50:38 -080013325 * @param subId The subId of the subscription to register for satellite modem state changed.
13326 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013327 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013328 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013329 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013330 * @throws SecurityException if the caller doesn't have the required permission.
13331 */
13332 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013333 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013334 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013335 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013336 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013337 }
13338
13339 /**
Sarah Chin43457982023-02-15 17:50:38 -080013340 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013341 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013342 *
Sarah Chin43457982023-02-15 17:50:38 -080013343 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013344 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013345 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013346 *
13347 * @throws SecurityException if the caller doesn't have the required permission.
13348 */
13349 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013350 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013351 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013352 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13353 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013354 }
13355
13356 /**
13357 * Register to receive incoming datagrams over satellite.
13358 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013359 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013360 * @param callback The callback to handle incoming datagrams over satellite.
13361 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013362 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013363 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013364 * @throws SecurityException if the caller doesn't have the required permission.
13365 */
13366 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013367 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013368 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013369 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13370 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013371 }
13372
13373 /**
13374 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013375 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013376 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013377 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13378 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013379 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013380 *
13381 * @throws SecurityException if the caller doesn't have the required permission.
13382 */
13383 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013384 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013385 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013386 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13387 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013388 }
13389
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013390 /**
13391 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013392 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013393 * This method requests modem to check if there are any pending datagrams to be received over
13394 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013395 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013396 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013397 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013398 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013399 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013400 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013401 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013402 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13403 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13404 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013405 }
13406
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013407 /**
13408 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013409 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013410 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13411 * input to this method. Datagram received here will be passed down to modem without any
13412 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013413 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013414 * @param subId The subId of the subscription to send satellite datagrams for.
13415 * @param datagramType datagram type indicating whether the datagram is of type
13416 * SOS_SMS or LOCATION_SHARING.
13417 * @param datagram encoded gateway datagram which is encrypted by the caller.
13418 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013419 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13420 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013421 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013422 *
13423 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013424 */
13425 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013426 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013427 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13428 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013429 enforceSatelliteCommunicationPermission("sendDatagram");
13430 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13431 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013432 }
13433
Sarah Chindf715ec2023-02-13 13:46:24 -080013434 /**
13435 * Request to get whether satellite communication is allowed for the current location.
13436 *
13437 * @param subId The subId of the subscription to check whether satellite communication is
13438 * allowed for the current location for.
13439 * @param result The result receiver that returns whether satellite communication is allowed
13440 * for the current location if the request is successful or an error code
13441 * if the request failed.
13442 *
13443 * @throws SecurityException if the caller doesn't have the required permission.
13444 */
13445 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013446 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013447 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013448 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13449 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13450 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013451 }
13452
13453 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013454 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013455 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013456 * @param subId The subId to get the time after which the satellite will be visible for.
13457 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013458 * be visible if the request is successful or an error code if the request failed.
13459 *
13460 * @throws SecurityException if the caller doesn't have the required permission.
13461 */
13462 @Override
13463 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13464 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013465 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013466 }
13467
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013468 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013469 * Inform that Device is aligned to satellite for demo mode.
13470 *
13471 * @param subId The subId to get the time after which the satellite will be visible for.
13472 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13473 * {@code false} Device fails to align with the satellite for demo mode.
13474 *
13475 * @throws SecurityException if the caller doesn't have required permission.
13476 */
13477 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13478
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013479 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013480 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013481 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013482 }
13483
13484 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013485 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13486 * by modem.
13487 *
13488 * @param subId The subId of the subscription to request for.
13489 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013490 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013491 * operation.
13492 *
13493 * @throws SecurityException if the caller doesn't have required permission.
13494 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013495 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013496 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13497 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013498 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013499 final long identity = Binder.clearCallingIdentity();
13500 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013501 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013502 } finally {
13503 Binder.restoreCallingIdentity(identity);
13504 }
13505 }
13506
13507 /**
13508 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13509 * by modem.
13510 *
13511 * @param subId The subId of the subscription to request for.
13512 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013513 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013514 * operation.
13515 *
13516 * @throws SecurityException if the caller doesn't have required permission.
13517 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013518 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013519 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13520 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013521 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013522 final long identity = Binder.clearCallingIdentity();
13523 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013524 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013525 } finally {
13526 Binder.restoreCallingIdentity(identity);
13527 }
13528 }
13529
13530 /**
13531 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013532 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013533 *
13534 * @param subId The subId of the subscription to request for.
13535 *
13536 * @return Integer array of reasons for disallowing satellite communication.
13537 *
13538 * @throws SecurityException if the caller doesn't have the required permission.
13539 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013540 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013541 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013542 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013543 final long identity = Binder.clearCallingIdentity();
13544 try {
13545 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013546 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013547 return reasonSet.stream().mapToInt(i->i).toArray();
13548 } finally {
13549 Binder.restoreCallingIdentity(identity);
13550 }
13551 }
13552
13553 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013554 * Request to get the signal strength of the satellite connection.
13555 *
13556 * @param subId The subId of the subscription to request for.
13557 * @param result Result receiver to get the error code of the request and the current signal
13558 * strength of the satellite connection.
13559 *
13560 * @throws SecurityException if the caller doesn't have required permission.
13561 */
13562 @Override
13563 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13564 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13565 final long identity = Binder.clearCallingIdentity();
13566 try {
13567 mSatelliteController.requestNtnSignalStrength(subId, result);
13568 } finally {
13569 Binder.restoreCallingIdentity(identity);
13570 }
13571 }
13572
13573 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013574 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13575 * is not successful, a {@link ServiceSpecificException} that contains
13576 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013577 *
13578 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013579 * @param callback The callback to handle the NTN signal strength changed event. If the
13580 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13581 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13582 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13583 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013584 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013585 * @throws SecurityException If the caller doesn't have the required permission.
13586 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013587 */
13588 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013589 public void registerForNtnSignalStrengthChanged(int subId,
13590 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013591 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13592 final long identity = Binder.clearCallingIdentity();
13593 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013594 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013595 } finally {
13596 Binder.restoreCallingIdentity(identity);
13597 }
13598 }
13599
13600 /**
13601 * Unregisters for NTN signal strength changed from satellite modem.
13602 * If callback was not registered before, the request will be ignored.
13603 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013604 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13605 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013606 * @param callback The callback that was passed to
13607 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13608 *
13609 * @throws SecurityException if the caller doesn't have the required permission.
13610 */
13611 @Override
13612 public void unregisterForNtnSignalStrengthChanged(
13613 int subId, @NonNull INtnSignalStrengthCallback callback) {
13614 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13615 final long identity = Binder.clearCallingIdentity();
13616 try {
13617 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13618 } finally {
13619 Binder.restoreCallingIdentity(identity);
13620 }
13621 }
13622
13623 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013624 * Registers for satellite capabilities change event from the satellite service.
13625 *
13626 * @param subId The subId of the subscription to request for.
13627 * @param callback The callback to handle the satellite capabilities changed event.
13628 *
13629 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13630 *
13631 * @throws SecurityException if the caller doesn't have required permission.
13632 */
13633 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013634 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013635 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013636 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013637 final long identity = Binder.clearCallingIdentity();
13638 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013639 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013640 } finally {
13641 Binder.restoreCallingIdentity(identity);
13642 }
13643 }
13644
13645 /**
13646 * Unregisters for satellite capabilities change event from the satellite service.
13647 * If callback was not registered before, the request will be ignored.
13648 *
13649 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13650 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013651 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013652 *
13653 * @throws SecurityException if the caller doesn't have required permission.
13654 */
13655 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013656 public void unregisterForCapabilitiesChanged(int subId,
13657 @NonNull ISatelliteCapabilitiesCallback callback) {
13658 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013659 final long identity = Binder.clearCallingIdentity();
13660 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013661 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013662 } finally {
13663 Binder.restoreCallingIdentity(identity);
13664 }
13665 }
13666
13667 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013668 * Registers for the satellite supported state changed.
13669 *
13670 * @param subId The subId of the subscription to register for supported state changed.
13671 * @param callback The callback to handle the satellite supported state changed event.
13672 *
13673 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13674 *
13675 * @throws SecurityException if the caller doesn't have the required permission.
13676 */
13677 @Override
13678 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13679 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13680 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13681 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13682 }
13683
13684 /**
13685 * Unregisters for the satellite supported state changed.
13686 * If callback was not registered before, the request will be ignored.
13687 *
13688 * @param subId The subId of the subscription to unregister for supported state changed.
13689 * @param callback The callback that was passed to
13690 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13691 *
13692 * @throws SecurityException if the caller doesn't have the required permission.
13693 */
13694 @Override
13695 public void unregisterForSatelliteSupportedStateChanged(
13696 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13697 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13698 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13699 }
13700
13701 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013702 * This API can be used by only CTS to update satellite vendor service package name.
13703 *
13704 * @param servicePackageName The package name of the satellite vendor service.
13705 * @return {@code true} if the satellite vendor service is set successfully,
13706 * {@code false} otherwise.
13707 */
13708 public boolean setSatelliteServicePackageName(String servicePackageName) {
13709 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13710 TelephonyPermissions.enforceShellOnly(
13711 Binder.getCallingUid(), "setSatelliteServicePackageName");
13712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13713 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13714 "setSatelliteServicePackageName");
13715 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13716 }
13717
13718 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013719 * This API can be used by only CTS to update satellite gateway service package name.
13720 *
13721 * @param servicePackageName The package name of the satellite gateway service.
13722 * @return {@code true} if the satellite gateway service is set successfully,
13723 * {@code false} otherwise.
13724 */
13725 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13726 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13727 TelephonyPermissions.enforceShellOnly(
13728 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13730 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13731 "setSatelliteGatewayServicePackageName");
13732 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13733 }
13734
13735 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013736 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13737 *
13738 * @param packageName The package name of the satellite pointing UI app.
13739 * @param className The class name of the satellite pointing UI app.
13740 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13741 * {@code false} otherwise.
13742 */
13743 public boolean setSatellitePointingUiClassName(
13744 @Nullable String packageName, @Nullable String className) {
13745 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13746 + ", className=" + className);
13747 TelephonyPermissions.enforceShellOnly(
13748 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13750 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13751 "setSatelliteGatewayServicePackageName");
13752 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13753 }
13754
13755 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013756 * This API can be used by only CTS to update the timeout duration in milliseconds that
13757 * satellite should stay at listening mode to wait for the next incoming page before disabling
13758 * listening mode.
13759 *
13760 * @param timeoutMillis The timeout duration in millisecond.
13761 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13762 */
13763 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13764 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13765 TelephonyPermissions.enforceShellOnly(
13766 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13768 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13769 "setSatelliteListeningTimeoutDuration");
13770 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13771 }
13772
13773 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013774 * This API can be used by only CTS to override the timeout durations used by the
13775 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013776 *
13777 * @param timeoutMillis The timeout duration in millisecond.
13778 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13779 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013780 public boolean setDatagramControllerTimeoutDuration(
13781 boolean reset, int timeoutType, long timeoutMillis) {
13782 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13783 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013784 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013785 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13787 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013788 "setDatagramControllerTimeoutDuration");
13789 return mSatelliteController.setDatagramControllerTimeoutDuration(
13790 reset, timeoutType, timeoutMillis);
13791 }
13792
13793 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013794 * This API can be used by only CTS to override the boolean configs used by the
13795 * DatagramController module.
13796 *
13797 * @param enable Whether to enable or disable boolean config.
13798 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13799 */
13800 public boolean setDatagramControllerBooleanConfig(
13801 boolean reset, int booleanType, boolean enable) {
13802 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13803 + ", reset=" + reset + ", enable=" + enable);
13804 TelephonyPermissions.enforceShellOnly(
13805 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13807 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13808 "ssetDatagramControllerBooleanConfig");
13809 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13810 }
13811
13812
13813 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013814 * This API can be used by only CTS to override the timeout durations used by the
13815 * SatelliteController module.
13816 *
13817 * @param timeoutMillis The timeout duration in millisecond.
13818 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13819 */
13820 public boolean setSatelliteControllerTimeoutDuration(
13821 boolean reset, int timeoutType, long timeoutMillis) {
13822 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13823 + reset + ", timeoutMillis=" + timeoutMillis);
13824 TelephonyPermissions.enforceShellOnly(
13825 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13827 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13828 "setSatelliteControllerTimeoutDuration");
13829 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13830 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013831 }
13832
13833 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013834 * This API can be used in only testing to override connectivity status in monitoring emergency
13835 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13836 *
13837 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13838 * of the following values to enable the override:
13839 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13840 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13841 * To disable the override, use -1 for handoverType.
13842 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13843 * delaySeconds after the emergency call starts.
13844 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13845 */
13846 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13847 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13848 TelephonyPermissions.enforceShellOnly(
13849 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13851 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13852 "setEmergencyCallToSatelliteHandoverType");
13853 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13854 handoverType, delaySeconds);
13855 }
13856
13857 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013858 * This API can be used in only testing to override oem-enabled satellite provision status.
13859 *
13860 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13861 * otherwise.
13862 * @param isProvisioned The overriding provision status.
13863 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13864 */
13865 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13866 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13867 + ", isProvisioned=" + isProvisioned);
13868 TelephonyPermissions.enforceShellOnly(
13869 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13871 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13872 "setOemEnabledSatelliteProvisionStatus");
13873 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13874 }
13875
13876 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013877 * This API should be used by only CTS tests to forcefully set telephony country codes.
13878 *
13879 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13880 */
13881 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13882 Map cachedNetworkCountryCodes, String locationCountryCode,
13883 long locationCountryCodeTimestampNanos) {
13884 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13885 + String.join(", ", currentNetworkCountryCodes)
13886 + ", locationCountryCode=" + locationCountryCode
13887 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13888 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13889 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13890 TelephonyPermissions.enforceShellOnly(
13891 Binder.getCallingUid(), "setCachedLocationCountryCode");
13892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13893 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13894 "setCachedLocationCountryCode");
13895 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13896 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13897 locationCountryCodeTimestampNanos);
13898 }
13899
13900 /**
13901 * This API should be used by only CTS tests to override the overlay configs of satellite
13902 * access controller.
13903 *
13904 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13905 * otherwise.
13906 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13907 */
13908 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13909 String s2CellFile, long locationFreshDurationNanos,
13910 List<String> satelliteCountryCodes) {
13911 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13912 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13913 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13914 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13915 ? String.join(", ", satelliteCountryCodes) : null));
13916 TelephonyPermissions.enforceShellOnly(
13917 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13919 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13920 "setSatelliteAccessControlOverlayConfigs");
13921 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13922 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13923 }
13924
13925 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013926 * This API can be used by only CTS to override the cached value for the device overlay config
13927 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13928 * outgoing satellite datagrams should be sent to modem in demo mode.
13929 *
13930 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13931 * satellite modem or not.
13932 *
13933 * @return {@code true} if the operation is successful, {@code false} otherwise.
13934 */
13935 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13936 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13937 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13938 + "disabled");
13939 return false;
13940 }
13941 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13942 TelephonyPermissions.enforceShellOnly(
13943 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13945 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13946 "setShouldSendDatagramToModemInDemoMode");
13947 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13948 shouldSendToModemInDemoMode);
13949 }
13950
13951 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000013952 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
13953 *
13954 * @param state a state indicates whether satellite access allowed state should be cached and
13955 * the allowed state.
13956 * @return {@code true} if the setting is successful, {@code false} otherwise.
13957 */
13958 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
13959 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13960 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13961 + "oemEnabledSatelliteFlag is disabled");
13962 return false;
13963 }
13964
13965 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13966 + "state=" + state);
13967 TelephonyPermissions.enforceShellOnly(
13968 Binder.getCallingUid(),
13969 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
13970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13971 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13972 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
13973 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
13974 state);
13975 }
13976
13977 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013978 * Sets the service defined in ComponentName to be bound.
13979 *
13980 * This should only be used for testing.
13981 * @return {@code true} if the DomainSelectionService to bind to was set,
13982 * {@code false} otherwise.
13983 */
13984 @Override
13985 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13986 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13987
13988 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13989 "setDomainSelectionServiceOverride");
13990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13991 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13992
13993 final long identity = Binder.clearCallingIdentity();
13994 try {
13995 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13996 return DomainSelectionResolver.getInstance()
13997 .setDomainSelectionServiceOverride(componentName);
13998 }
13999 } finally {
14000 Binder.restoreCallingIdentity(identity);
14001 }
14002 return false;
14003 }
14004
14005 /**
14006 * Clears the DomainSelectionService override.
14007 *
14008 * This should only be used for testing.
14009 * @return {@code true} if the DomainSelectionService override was cleared,
14010 * {@code false} otherwise.
14011 */
14012 @Override
14013 public boolean clearDomainSelectionServiceOverride() {
14014 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14015
14016 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14017 "clearDomainSelectionServiceOverride");
14018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14019 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14020
14021 final long identity = Binder.clearCallingIdentity();
14022 try {
14023 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14024 return DomainSelectionResolver.getInstance()
14025 .clearDomainSelectionServiceOverride();
14026 }
14027 } finally {
14028 Binder.restoreCallingIdentity(identity);
14029 }
14030 return false;
14031 }
14032
14033 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014034 * Enable or disable notifications sent for cellular identifier disclosure events.
14035 *
14036 * Disclosure events are defined as instances where a device has sent a cellular identifier
14037 * on the Non-access stratum (NAS) before a security context is established. As a result the
14038 * identifier is sent in the clear, which has privacy implications for the user.
14039 *
14040 * @param enable if notifications about disclosure events should be enabled
14041 * @throws SecurityException if the caller does not have the required privileges
14042 * @throws UnsupportedOperationException if the modem does not support this feature.
14043 */
14044 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014045 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014046 enforceModifyPermission();
14047 checkForIdentifierDisclosureNotificationSupport();
14048
14049 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14050 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14051 editor.apply();
14052
14053 // Each phone instance is responsible for updating its respective modem immediately
14054 // after we've made a preference change.
14055 for (Phone phone : PhoneFactory.getPhones()) {
14056 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14057 }
14058 }
14059
14060 /**
14061 * Get whether or not cellular identifier disclosure notifications are enabled.
14062 *
14063 * @throws SecurityException if the caller does not have the required privileges
14064 * @throws UnsupportedOperationException if the modem does not support this feature.
14065 */
14066 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014067 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014068 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14069 checkForIdentifierDisclosureNotificationSupport();
14070 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14071 }
14072
14073 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014074 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14075 * are in use by the cellular modem.
14076 *
14077 * @throws IllegalStateException if the Telephony process is not currently available
14078 * @throws SecurityException if the caller does not have the required privileges
14079 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14080 * and integrity algorithms in use
14081 * @hide
14082 */
14083 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014084 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014085 enforceModifyPermission();
14086 checkForNullCipherNotificationSupport();
14087
14088 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14089 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14090 editor.apply();
14091
14092 // Each phone instance is responsible for updating its respective modem immediately
14093 // after a preference change.
14094 for (Phone phone : PhoneFactory.getPhones()) {
14095 phone.handleNullCipherNotificationPreferenceChanged();
14096 }
14097 }
14098
14099 /**
14100 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14101 * cellular modem.
14102 *
14103 * @throws IllegalStateException if the Telephony process is not currently available
14104 * @throws SecurityException if the caller does not have the required privileges
14105 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14106 * and integrity algorithms in use
14107 * @hide
14108 */
14109 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14110 public boolean isNullCipherNotificationsEnabled() {
14111 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14112 checkForNullCipherNotificationSupport();
14113 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14114 }
14115
14116 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014117 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14118 *
14119 * <p>This method behaves in one of the following ways:
14120 * <ul>
14121 * <li>return true : if the calling package has the appop permission {@link
14122 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14123 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14124 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14125 * Owner device identifier access check, or the calling package has carrier privileges</>
14126 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14127 * </ul>
14128 */
14129 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14130 String callingPackage, @Nullable String callingFeatureId, String message) {
14131 for (Phone phone : PhoneFactory.getPhones()) {
14132 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14133 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14134 return true;
14135 }
14136 }
14137 return false;
14138 }
arunvoddud7401012022-12-15 16:08:12 +000014139
14140 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014141 * @return The subscription manager service instance.
14142 */
14143 public SubscriptionManagerService getSubscriptionManagerService() {
14144 return SubscriptionManagerService.getInstance();
14145 }
14146
14147 /**
arunvoddud7401012022-12-15 16:08:12 +000014148 * Class binds the consumer[callback] and carrierId.
14149 */
14150 private static class CallerCallbackInfo {
14151 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014152 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014153
Steve Statia28b7cb32024-03-11 23:58:50 +000014154 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014155 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014156 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014157 }
14158
14159 public Consumer<Integer> getConsumer() {
14160 return mConsumer;
14161 }
14162
Steve Statia28b7cb32024-03-11 23:58:50 +000014163 public Set<Integer> getCarrierIds() {
14164 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014165 }
14166 }
joonhunshin4ac60942023-11-15 15:23:39 +000014167
14168 /*
14169 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14170 * But the context that is passed in is unused if the phone app is already alive.
14171 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14172 */
14173 @VisibleForTesting
14174 public void setPackageManager(PackageManager packageManager) {
14175 mPackageManager = packageManager;
14176 }
14177
14178 /*
Nate Myren453c3472024-03-13 11:28:11 -070014179 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14180 * But the context that is passed in is unused if the phone app is already alive.
14181 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14182 */
14183 @VisibleForTesting
14184 public void setAppOpsManager(AppOpsManager appOps) {
14185 mAppOps = appOps;
14186 }
14187
14188 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014189 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14190 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14191 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14192 */
14193 @VisibleForTesting
14194 public void setFeatureFlags(FeatureFlags featureFlags) {
14195 mFeatureFlags = featureFlags;
14196 }
14197
14198 /**
14199 * Make sure the device has required telephony feature
14200 *
14201 * @throws UnsupportedOperationException if the device does not have required telephony feature
14202 */
14203 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14204 @NonNull String telephonyFeature, @NonNull String methodName) {
14205 if (callingPackage == null || mPackageManager == null) {
14206 return;
14207 }
14208
14209 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14210 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014211 Binder.getCallingUserHandle())
14212 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14213 // Skip to check associated telephony feature,
14214 // if compatibility change is not enabled for the current process or
14215 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014216 return;
14217 }
14218
14219 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14220 throw new UnsupportedOperationException(
14221 methodName + " is unsupported without " + telephonyFeature);
14222 }
14223 }
youngtaecha5d483d52024-04-29 17:05:45 +000014224
14225 /**
14226 * Registers for the satellite communication allowed state changed.
14227 *
14228 * @param subId The subId of the subscription to register for the satellite communication
14229 * allowed state changed.
14230 * @param callback The callback to handle the satellite communication allowed
14231 * state changed event.
14232 *
14233 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14234 *
14235 * @throws SecurityException if the caller doesn't have the required permission.
14236 */
14237 @Override
14238 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14239 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14240 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14241 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14242 subId, callback);
14243 }
14244
14245 /**
14246 * Unregisters for the satellite communication allowed state changed.
14247 * If callback was not registered before, the request will be ignored.
14248 *
14249 * @param subId The subId of the subscription to unregister for the satellite communication
14250 * allowed state changed.
14251 * @param callback The callback that was passed to
14252 * {@link #registerForCommunicationAllowedStateChanged(int,
14253 * ISatelliteCommunicationAllowedStateCallback)}. *
14254 * @throws SecurityException if the caller doesn't have the required permission.
14255 */
14256 @Override
14257 public void unregisterForCommunicationAllowedStateChanged(
14258 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14259 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14260 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14261 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014262
14263 /**
14264 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14265 *
14266 * @param subId The subId of the subscription to the satellite session stats for.
14267 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14268 * if the request is successful or an error code if the request failed.
14269 *
14270 * @throws SecurityException if the caller doesn't have required permission.
14271 */
14272 @Override
14273 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14274 enforceModifyPermission();
14275 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
14276 mSatelliteController.requestSatelliteSessionStats(subId, result);
14277 }
Jack Yufa8ed012023-02-11 15:42:28 -080014278}