blob: d7eb4b83d432d291f7a29b02682aba9114211587 [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;
2734
Michele Berionne5e411512020-11-13 02:36:59 +00002735 UnlockSim(int phoneId, IccCard simCard) {
2736 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 mSimCard = simCard;
2738 }
2739
2740 @Override
2741 public void run() {
2742 Looper.prepare();
2743 synchronized (UnlockSim.this) {
2744 mHandler = new Handler() {
2745 @Override
2746 public void handleMessage(Message msg) {
2747 AsyncResult ar = (AsyncResult) msg.obj;
2748 switch (msg.what) {
2749 case SUPPLY_PIN_COMPLETE:
2750 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2751 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002752 mRetryCount = msg.arg1;
2753 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002754 CommandException.Error error = null;
2755 if (ar.exception instanceof CommandException) {
2756 error = ((CommandException) (ar.exception))
2757 .getCommandError();
2758 }
2759 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002760 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002761 } else if (error == CommandException.Error.ABORTED) {
2762 /* When UiccCardApp dispose, handle message and return
2763 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002764 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002765 } else {
2766 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2767 }
2768 } else {
2769 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 mDone = true;
2772 UnlockSim.this.notifyAll();
2773 }
2774 break;
2775 }
2776 }
2777 };
2778 UnlockSim.this.notifyAll();
2779 }
2780 Looper.loop();
2781 }
2782
2783 /*
2784 * Use PIN or PUK to unlock SIM card
2785 *
2786 * If PUK is null, unlock SIM card with PIN
2787 *
2788 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302789 *
2790 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2791 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 */
Wink Saville9de0f752013-10-22 19:04:03 -07002793 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794
2795 while (mHandler == null) {
2796 try {
2797 wait();
2798 } catch (InterruptedException e) {
2799 Thread.currentThread().interrupt();
2800 }
2801 }
2802 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2803
2804 if (puk == null) {
2805 mSimCard.supplyPin(pin, callback);
2806 } else {
2807 mSimCard.supplyPuk(puk, pin, callback);
2808 }
2809
2810 while (!mDone) {
2811 try {
2812 Log.d(LOG_TAG, "wait for done");
2813 wait();
2814 } catch (InterruptedException e) {
2815 // Restore the interrupted status
2816 Thread.currentThread().interrupt();
2817 }
2818 }
2819 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002820 int[] resultArray = new int[2];
2821 resultArray[0] = mResult;
2822 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002823
2824 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002825 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002826 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302827 // This instance is no longer reused, so quit its thread's looper.
2828 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002829
Wink Saville9de0f752013-10-22 19:04:03 -07002830 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 }
2832 }
2833
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002834 /**
2835 * This method has been removed due to privacy and stability concerns.
2836 */
2837 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002839 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2840 return;
Wink Saville36469e72014-06-11 15:17:00 -07002841 }
2842
Nathan Harold1f889d82020-06-04 17:05:26 -07002843 @Override
2844 public void updateServiceLocationWithPackageName(String callingPackage) {
2845 mApp.getSystemService(AppOpsManager.class)
2846 .checkPackage(Binder.getCallingUid(), callingPackage);
2847
Nathan Haroldf096d982020-11-18 17:18:06 -08002848 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002849 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2850 // Callers targeting S have no business invoking this method.
2851 return;
2852 }
2853
2854 LocationAccessPolicy.LocationPermissionResult locationResult =
2855 LocationAccessPolicy.checkLocationPermission(mApp,
2856 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2857 .setCallingPackage(callingPackage)
2858 .setCallingFeatureId(null)
2859 .setCallingPid(Binder.getCallingPid())
2860 .setCallingUid(Binder.getCallingUid())
2861 .setMethod("updateServiceLocation")
2862 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2863 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2864 .build());
2865 // Apps that lack location permission have no business calling this method;
2866 // however, because no permission was declared in the public API, denials must
2867 // all be "soft".
2868 switch (locationResult) {
2869 case DENIED_HARD: /* fall through */
2870 case DENIED_SOFT:
2871 return;
2872 }
2873
2874 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875 final long identity = Binder.clearCallingIdentity();
2876 try {
Ling Mac28f0212023-03-24 16:07:15 -07002877 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 } finally {
2879 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881 }
2882
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002883 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002884 @Override
2885 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002886 return isRadioOnWithFeature(callingPackage, null);
2887 }
2888
2889
2890 @Override
2891 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2892 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2893 callingFeatureId);
2894 }
2895
2896 @Deprecated
2897 @Override
2898 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2899 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002900 }
2901
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002902 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002903 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2904 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002906 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002907 return false;
2908 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909
joonhunshin4ac60942023-11-15 15:23:39 +00002910 enforceTelephonyFeatureWithException(callingPackage,
2911 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 return isRadioOnForSubscriber(subId);
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
2918 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002919 }
2920
2921 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 final Phone phone = getPhone(subId);
2925 if (phone != null) {
2926 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2927 } else {
2928 return false;
2929 }
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
2934
2935 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002936 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002937 }
Wink Saville36469e72014-06-11 15:17:00 -07002938
Wink Savilleb564aae2014-10-23 10:18:09 -07002939 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941
joonhunshin4ac60942023-11-15 15:23:39 +00002942 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2943 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 final long identity = Binder.clearCallingIdentity();
2946 try {
2947 final Phone phone = getPhone(subId);
2948 if (phone != null) {
2949 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2950 }
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002953 }
Wink Saville36469e72014-06-11 15:17:00 -07002954 }
2955
2956 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002957 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002958 }
2959
Wink Savilleb564aae2014-10-23 10:18:09 -07002960 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002961 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962
2963 final long identity = Binder.clearCallingIdentity();
2964 try {
2965 final Phone phone = getPhone(subId);
2966 if (phone == null) {
2967 return false;
2968 }
2969 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2970 toggleRadioOnOffForSubscriber(subId);
2971 }
2972 return true;
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002976 }
Wink Saville36469e72014-06-11 15:17:00 -07002977
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002978 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002979 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002980
2981 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2982 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2983
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002984 /*
2985 * If any of the Radios are available, it will need to be
2986 * shutdown. So return true if any Radio is available.
2987 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2991 Phone phone = PhoneFactory.getPhone(i);
2992 if (phone != null && phone.isRadioAvailable()) return true;
2993 }
2994 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2995 return false;
2996 } finally {
2997 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002998 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002999 }
3000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003002 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 enforceModifyPermission();
3004
joonhunshin4ac60942023-11-15 15:23:39 +00003005 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3006 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3011 logv("Shutting down Phone " + i);
3012 shutdownRadioUsingPhoneId(i);
3013 }
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003016 }
3017 }
3018
3019 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003020 Phone phone = PhoneFactory.getPhone(phoneId);
3021 if (phone != null && phone.isRadioAvailable()) {
3022 phone.shutdownRadio();
3023 }
3024 }
3025
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003026 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003027 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028
Ling Ma83dc5ea2023-01-12 15:06:04 -08003029 if (!turnOn) {
3030 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3031 }
3032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3036 if (defaultPhone != null) {
3037 defaultPhone.setRadioPower(turnOn);
3038 return true;
3039 } else {
3040 loge("There's no default phone.");
3041 return false;
3042 }
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003045 }
Wink Saville36469e72014-06-11 15:17:00 -07003046 }
3047
Wink Savilleb564aae2014-10-23 10:18:09 -07003048 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003049 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050
Ling Ma83dc5ea2023-01-12 15:06:04 -08003051 if (!turnOn) {
3052 log("setRadioPowerForSubscriber off: subId=" + subId
3053 + ",callingPackage=" + getCurrentPackageName());
3054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 final Phone phone = getPhone(subId);
3058 if (phone != null) {
3059 phone.setRadioPower(turnOn);
3060 return true;
3061 } else {
3062 return false;
3063 }
3064 } finally {
3065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067 }
3068
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003069 /**
3070 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3071 * no reason to power it off. When any of the voters want to power it off, it will be turned
3072 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3073 * powering it off, and these radio off votes will be cleared.
3074 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3075 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3076 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3077 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3078 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3079 * check its vote.
3080 *
3081 * @param subId The subscription ID.
3082 * @param reason The reason for powering off radio.
3083 * @return true on success and false on failure.
3084 */
3085 public boolean requestRadioPowerOffForReason(int subId,
3086 @TelephonyManager.RadioPowerReason int reason) {
3087 enforceModifyPermission();
3088
joonhunshin4ac60942023-11-15 15:23:39 +00003089 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3090 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3091
Ling Ma83dc5ea2023-01-12 15:06:04 -08003092 log("requestRadioPowerOffForReason: subId=" + subId
3093 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003094 final long identity = Binder.clearCallingIdentity();
3095 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003096 boolean result = false;
3097 for (Phone phone : PhoneFactory.getPhones()) {
3098 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003099 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003100 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003101 if (!result) {
3102 loge("requestRadioPowerOffForReason: no phone exists");
3103 }
3104 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
3108 }
3109
3110 /**
3111 * Remove the vote on powering off the radio for a reason, as requested by
3112 * {@link requestRadioPowerOffForReason}.
3113 *
3114 * @param subId The subscription ID.
3115 * @param reason The reason for powering off radio.
3116 * @return true on success and false on failure.
3117 */
3118 public boolean clearRadioPowerOffForReason(int subId,
3119 @TelephonyManager.RadioPowerReason int reason) {
3120 enforceModifyPermission();
3121
joonhunshin4ac60942023-11-15 15:23:39 +00003122 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3123 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3124
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003125 final long identity = Binder.clearCallingIdentity();
3126 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003127 boolean result = false;
3128 for (Phone phone : PhoneFactory.getPhones()) {
3129 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003130 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003131 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003132 if (!result) {
3133 loge("clearRadioPowerOffForReason: no phone exists");
3134 }
3135 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003136 } finally {
3137 Binder.restoreCallingIdentity(identity);
3138 }
3139 }
3140
3141 /**
3142 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3143 *
3144 * @param subId The subscription ID.
3145 * @param callingPackage The package making the call.
3146 * @param callingFeatureId The feature in the package.
3147 * @return List of reasons for powering off radio.
3148 */
3149 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3150 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3151
joonhunshin4ac60942023-11-15 15:23:39 +00003152 enforceTelephonyFeatureWithException(callingPackage,
3153 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3154
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003155 final long identity = Binder.clearCallingIdentity();
3156 List result = new ArrayList();
3157 try {
3158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3159 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3160 return result;
3161 }
3162
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003163 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003164 if (phone != null) {
3165 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003166 } else {
3167 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003168 }
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
3172 return result;
3173 }
3174
Wink Saville36469e72014-06-11 15:17:00 -07003175 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003176 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003177 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003178 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179
joonhunshin4ac60942023-11-15 15:23:39 +00003180 enforceTelephonyFeatureWithException(callingPackage,
3181 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003183 final long identity = Binder.clearCallingIdentity();
3184 try {
Jack Yu285100e2022-12-02 22:48:35 -08003185 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186 final Phone phone = getPhone(subId);
3187 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003188 phone.getDataSettingsManager().setDataEnabled(
3189 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190 return true;
3191 } else {
3192 return false;
3193 }
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198
Wink Saville36469e72014-06-11 15:17:00 -07003199 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003200 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003201 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003202 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203
joonhunshin4ac60942023-11-15 15:23:39 +00003204 enforceTelephonyFeatureWithException(callingPackage,
3205 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 final long identity = Binder.clearCallingIdentity();
3208 try {
Jack Yu285100e2022-12-02 22:48:35 -08003209 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 final Phone phone = getPhone(subId);
3211 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003212 phone.getDataSettingsManager().setDataEnabled(
3213 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 return true;
3215 } else {
3216 return false;
3217 }
3218 } finally {
3219 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 }
3222
Sanket Padawe356d7632015-06-22 14:03:32 -07003223 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003224 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003225 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3226 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 final Phone phone = getPhone(subId);
3231 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003232 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233 } else {
3234 return false;
3235 }
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003239 }
3240
3241 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003242 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003243 }
3244
pkanwarae03a6b2016-11-06 20:37:09 -08003245 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003246 enforceCallPermission();
3247
joonhunshin4ac60942023-11-15 15:23:39 +00003248 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3249 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 final long identity = Binder.clearCallingIdentity();
3252 try {
3253 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3254 return;
3255 }
3256 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3257 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
pkanwar32d516d2016-10-14 19:37:38 -07003261 };
3262
Wink Savilleb564aae2014-10-23 10:18:09 -07003263 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003264 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265
joonhunshin4ac60942023-11-15 15:23:39 +00003266 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3267 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3272 return false;
3273 }
3274 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 }
3279
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003280 /**
3281 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3282 * tag on getCallState Binder call.
3283 */
3284 @Deprecated
3285 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003287 if (CompatChanges.isChangeEnabled(
3288 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3289 Binder.getCallingUid())) {
3290 // Do not allow this API to be called on API version 31+, it should only be
3291 // called on old apps using this Binder call directly.
3292 throw new SecurityException("This method can only be used for applications "
3293 + "targeting API version 30 or less.");
3294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003295 final long identity = Binder.clearCallingIdentity();
3296 try {
Ling Mac28f0212023-03-24 16:07:15 -07003297 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3298 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
3302 }
3303
3304 @Override
3305 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3306 if (CompatChanges.isChangeEnabled(
3307 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3308 Binder.getCallingUid())) {
3309 // Check READ_PHONE_STATE for API version 31+
3310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3311 featureId, "getCallStateForSubscription")) {
3312 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3313 + "targeting API level 31+.");
3314 }
3315 }
joonhunshin4ac60942023-11-15 15:23:39 +00003316
3317 enforceTelephonyFeatureWithException(callingPackage,
3318 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3319
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003320 final long identity = Binder.clearCallingIdentity();
3321 try {
3322 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003323 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3324 PhoneConstantConversions.convertCallState(phone.getState());
3325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003328 }
3329
Sanket Padawe356d7632015-06-22 14:03:32 -07003330 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003331 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003332 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003333 }
3334
3335 @Override
3336 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003337 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3338 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 final long identity = Binder.clearCallingIdentity();
3341 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003342 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003344 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003345 } else {
3346 return PhoneConstantConversions.convertDataState(
3347 PhoneConstants.DataState.DISCONNECTED);
3348 }
3349 } finally {
3350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 }
3353
Sanket Padawe356d7632015-06-22 14:03:32 -07003354 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003355 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003356 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003357 }
3358
3359 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003360 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003361 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3362 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364 final long identity = Binder.clearCallingIdentity();
3365 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003366 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003368 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003369 } else {
3370 return TelephonyManager.DATA_ACTIVITY_NONE;
3371 }
3372 } finally {
3373 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003375 }
3376
3377 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003378 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003380 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003381
3382 LocationAccessPolicy.LocationPermissionResult locationResult =
3383 LocationAccessPolicy.checkLocationPermission(mApp,
3384 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3385 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003386 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003387 .setCallingPid(Binder.getCallingPid())
3388 .setCallingUid(Binder.getCallingUid())
3389 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003390 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003391 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3392 .build());
3393 switch (locationResult) {
3394 case DENIED_HARD:
3395 throw new SecurityException("Not allowed to access cell location");
3396 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003397 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3398 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003399 }
3400
joonhunshin4ac60942023-11-15 15:23:39 +00003401 enforceTelephonyFeatureWithException(callingPackage,
3402 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3403
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003404 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405 final long identity = Binder.clearCallingIdentity();
3406 try {
3407 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003408 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003409 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003410 } finally {
3411 Binder.restoreCallingIdentity(identity);
3412 }
Svetoslav64fad262015-04-14 14:35:21 -07003413 }
3414
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003415 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003416 public String getNetworkCountryIsoForPhone(int phoneId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003417 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3418 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3419
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003420 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3421 // registered cell info, so return a NULL country instead.
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003424 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3425 // Get default phone in this case.
3426 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3427 }
Jack Yu285100e2022-12-02 22:48:35 -08003428 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003430 if (phone == null) return "";
3431 ServiceStateTracker sst = phone.getServiceStateTracker();
3432 if (sst == null) return "";
3433 LocaleTracker lt = sst.getLocaleTracker();
3434 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003435 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003436 } finally {
3437 Binder.restoreCallingIdentity(identity);
3438 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003439 }
3440
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003441 /**
3442 * This method was removed due to potential issues caused by performing partial
3443 * updates of service state, and lack of a credible use case.
3444 *
3445 * This has the ability to break the telephony implementation by disabling notification of
3446 * changes in device connectivity. DO NOT USE THIS!
3447 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003448 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003449 public void enableLocationUpdates() {
3450 mApp.enforceCallingOrSelfPermission(
3451 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 }
3453
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003454 /**
3455 * This method was removed due to potential issues caused by performing partial
3456 * updates of service state, and lack of a credible use case.
3457 *
3458 * This has the ability to break the telephony implementation by disabling notification of
3459 * changes in device connectivity. DO NOT USE THIS!
3460 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003461 @Override
3462 public void disableLocationUpdates() {
3463 mApp.enforceCallingOrSelfPermission(
3464 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003465 }
3466
3467 @Override
3468 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003469 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3470 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003471 try {
3472 mApp.getSystemService(AppOpsManager.class)
3473 .checkPackage(Binder.getCallingUid(), callingPackage);
3474 } catch (SecurityException e) {
3475 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3476 throw e;
3477 }
3478
Nathan Haroldf096d982020-11-18 17:18:06 -08003479 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003480 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3481 throw new SecurityException(
3482 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3483 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003484
Jordan Liu1617b712019-07-10 15:06:26 -07003485 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003486 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3487 return null;
3488 }
Svetoslav64fad262015-04-14 14:35:21 -07003489
joonhunshin4ac60942023-11-15 15:23:39 +00003490 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3491 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3492
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003493 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003494
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003495 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003496 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497
Nathan Haroldf180aac2018-06-01 18:43:55 -07003498 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3499 for (CellInfo ci : info) {
3500 if (ci instanceof CellInfoGsm) {
3501 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3502 } else if (ci instanceof CellInfoWcdma) {
3503 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003505 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003506 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003507 }
3508
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003509 private List<CellInfo> getCachedCellInfo() {
3510 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3511 for (Phone phone : PhoneFactory.getPhones()) {
3512 List<CellInfo> info = phone.getAllCellInfo();
3513 if (info != null) cellInfos.addAll(info);
3514 }
3515 return cellInfos;
3516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003517
3518 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003519 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003520 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003521 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003522
3523 LocationAccessPolicy.LocationPermissionResult locationResult =
3524 LocationAccessPolicy.checkLocationPermission(mApp,
3525 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3526 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003527 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003528 .setCallingPid(Binder.getCallingPid())
3529 .setCallingUid(Binder.getCallingUid())
3530 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003531 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003532 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3533 .build());
3534 switch (locationResult) {
3535 case DENIED_HARD:
3536 throw new SecurityException("Not allowed to access cell info");
3537 case DENIED_SOFT:
3538 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003539 }
3540
Nathan Haroldf096d982020-11-18 17:18:06 -08003541 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003542 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3543 return getCachedCellInfo();
3544 }
3545
joonhunshin4ac60942023-11-15 15:23:39 +00003546 enforceTelephonyFeatureWithException(callingPackage,
3547 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3548
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003549 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003550 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3554 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003555 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003556 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557 if (info != null) cellInfos.addAll(info);
3558 }
3559 return cellInfos;
3560 } finally {
3561 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003562 }
3563 }
3564
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003565 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003566 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3567 String callingFeatureId) {
3568 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3569 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003570 }
3571
3572 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003573 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3574 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003575 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003576 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003577 }
3578
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003579 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3580 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003581 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003582 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003583
3584 LocationAccessPolicy.LocationPermissionResult locationResult =
3585 LocationAccessPolicy.checkLocationPermission(mApp,
3586 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3587 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003588 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003589 .setCallingPid(Binder.getCallingPid())
3590 .setCallingUid(Binder.getCallingUid())
3591 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003592 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3593 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003594 .build());
3595 switch (locationResult) {
3596 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003597 if (TelephonyPermissions
3598 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003599 // Safetynet logging for b/154934934
3600 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3601 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003602 throw new SecurityException("Not allowed to access cell info");
3603 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003604 if (TelephonyPermissions
3605 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003606 // Safetynet logging for b/154934934
3607 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3608 }
Nathan Harold5320c422019-05-09 10:26:08 -07003609 try {
3610 cb.onCellInfo(new ArrayList<CellInfo>());
3611 } catch (RemoteException re) {
3612 // Drop without consequences
3613 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003614 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003615 }
3616
joonhunshin4ac60942023-11-15 15:23:39 +00003617 enforceTelephonyFeatureWithException(callingPackage,
3618 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003619
3620 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003621 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3622
3623 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3624 }
3625
3626 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003627 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003628 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003629 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630
3631 final long identity = Binder.clearCallingIdentity();
3632 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003633 Phone phone = getPhone(subId);
3634 if (phone == null) {
3635 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3636 } else {
3637 phone.setCellInfoListRate(rateInMillis, workSource);
3638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639 } finally {
3640 Binder.restoreCallingIdentity(identity);
3641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003642 }
3643
Shishir Agrawala9f32182016-04-12 12:00:16 -07003644 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003645 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003646 Phone phone = PhoneFactory.getPhone(slotIndex);
3647 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003648 return null;
3649 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003650 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003651 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003652 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003653 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003654 return null;
3655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656
joonhunshin4ac60942023-11-15 15:23:39 +00003657 enforceTelephonyFeatureWithException(callingPackage,
3658 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660 final long identity = Binder.clearCallingIdentity();
3661 try {
3662 return phone.getImei();
3663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003666 }
3667
3668 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003669 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3670 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3671 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3672 callingFeatureId, "getPrimaryImei")) {
3673 throw new SecurityException("Caller does not have permission");
3674 }
joonhunshin4ac60942023-11-15 15:23:39 +00003675
3676 enforceTelephonyFeatureWithException(callingPackage,
3677 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3678
arunvoddud5c6ce02022-12-11 06:03:12 +00003679 final long identity = Binder.clearCallingIdentity();
3680 try {
3681 for (Phone phone : PhoneFactory.getPhones()) {
3682 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3683 return phone.getImei();
3684 }
3685 }
3686 throw new UnsupportedOperationException("Operation not supported");
3687 } finally {
3688 Binder.restoreCallingIdentity(identity);
3689 }
3690 }
3691
3692 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003693 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003694 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3695 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3696
David Kelly5e06a7f2018-03-12 14:10:59 +00003697 Phone phone = PhoneFactory.getPhone(slotIndex);
3698 String tac = null;
3699 if (phone != null) {
3700 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003701 try {
3702 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3703 } catch (IndexOutOfBoundsException e) {
3704 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3705 return null;
3706 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003707 }
3708 return tac;
3709 }
3710
3711 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003712 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003713 try {
3714 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3715 } catch (SecurityException se) {
3716 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3717 throw new SecurityException("Package " + callingPackage + " does not belong to "
3718 + Binder.getCallingUid());
3719 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003720 Phone phone = PhoneFactory.getPhone(slotIndex);
3721 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003722 return null;
3723 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003724
Jeff Davidson913390f2018-02-23 17:11:49 -08003725 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003726 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003727 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003728 return null;
3729 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730
joonhunshin4ac60942023-11-15 15:23:39 +00003731 enforceTelephonyFeatureWithException(callingPackage,
3732 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 return phone.getMeid();
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
Jack Yu2af8d712017-03-15 17:14:14 -07003740 }
3741
3742 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003743 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003744 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3745 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3746
David Kelly5e06a7f2018-03-12 14:10:59 +00003747 Phone phone = PhoneFactory.getPhone(slotIndex);
3748 String manufacturerCode = null;
3749 if (phone != null) {
3750 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003751 try {
3752 manufacturerCode =
3753 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3754 } catch (IndexOutOfBoundsException e) {
3755 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3756 return null;
3757 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003758 }
3759 return manufacturerCode;
3760 }
3761
3762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3764 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003765 Phone phone = PhoneFactory.getPhone(slotIndex);
3766 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003767 return null;
3768 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003769 int subId = phone.getSubId();
3770 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003771 mApp, subId, callingPackage, callingFeatureId,
3772 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003773 return null;
3774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003775
joonhunshin4ac60942023-11-15 15:23:39 +00003776 enforceTelephonyFeatureWithException(callingPackage,
3777 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003779 final long identity = Binder.clearCallingIdentity();
3780 try {
3781 return phone.getDeviceSvn();
3782 } finally {
3783 Binder.restoreCallingIdentity(identity);
3784 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003785 }
3786
fionaxu43304da2017-11-27 22:51:16 -08003787 @Override
3788 public int getSubscriptionCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003789 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3790 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 final Phone phone = getPhone(subId);
3795 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
fionaxu43304da2017-11-27 22:51:16 -08003799 }
3800
3801 @Override
3802 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003803 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3804 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
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 ? null : phone.getCarrierName();
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
3812 }
fionaxu43304da2017-11-27 22:51:16 -08003813 }
3814
calvinpanffe225e2018-11-01 19:43:06 +08003815 @Override
chen xu0026ca62019-03-06 15:28:50 -08003816 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003817 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3818 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3819
chen xu25637222018-11-04 17:17:00 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 final Phone phone = getPhone(subId);
3823 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003824 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003825 } finally {
3826 Binder.restoreCallingIdentity(identity);
3827 }
3828 }
3829
3830 @Override
chen xu0026ca62019-03-06 15:28:50 -08003831 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003832 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3833 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3834 "getSubscriptionSpecificCarrierName");
3835
chen xu25637222018-11-04 17:17:00 -08003836 final long identity = Binder.clearCallingIdentity();
3837 try {
3838 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003839 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003840 } finally {
3841 Binder.restoreCallingIdentity(identity);
3842 }
3843 }
3844
chen xu651eec72018-11-11 19:03:44 -08003845 @Override
chen xu864e11c2018-12-06 22:10:03 -08003846 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3847 if (!isSubscriptionMccMnc) {
3848 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3849 }
chen xu651eec72018-11-11 19:03:44 -08003850 final Phone phone = PhoneFactory.getPhone(slotIndex);
3851 if (phone == null) {
3852 return TelephonyManager.UNKNOWN_CARRIER_ID;
3853 }
joonhunshin4ac60942023-11-15 15:23:39 +00003854
3855 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3856 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3857
chen xu651eec72018-11-11 19:03:44 -08003858 final long identity = Binder.clearCallingIdentity();
3859 try {
3860 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3861 } finally {
3862 Binder.restoreCallingIdentity(identity);
3863 }
3864 }
3865
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003866 //
3867 // Internal helper methods.
3868 //
3869
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003870 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003871 * Make sure the caller is the calling package itself
3872 *
3873 * @throws SecurityException if the caller is not the calling package
3874 */
3875 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3876 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003877 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3878 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003879 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003880 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003881 } catch (PackageManager.NameNotFoundException e) {
3882 // packageUid is -1
3883 }
3884 if (packageUid != callingUid) {
3885 throw new SecurityException(message + ": Package " + callingPackage
3886 + " does not belong to " + callingUid);
3887 }
3888 }
3889
3890 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003891 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3892 *
3893 * @throws SecurityException if the caller does not have the required permission
3894 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003895 @VisibleForTesting
3896 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003897 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3898 }
3899
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003900 /**
arunvoddud7401012022-12-15 16:08:12 +00003901 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003902 *
3903 * @throws SecurityException if the caller does not have the required permission
3904 */
3905 @VisibleForTesting
3906 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003907 enforceReadPermission(null);
3908 }
3909
3910 /**
3911 * Make sure the caller has the READ_PHONE_STATE permissions.
3912 *
3913 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3914 */
3915 @VisibleForTesting
3916 public void enforceReadPermission(String msg) {
3917 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003918 }
3919
Shuo Qian3b6ee772019-11-13 17:43:31 -08003920 private void enforceActiveEmergencySessionPermission() {
3921 mApp.enforceCallingOrSelfPermission(
3922 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3923 }
3924
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003925 /**
3926 * Make sure the caller has the CALL_PHONE permission.
3927 *
3928 * @throws SecurityException if the caller does not have the required permission
3929 */
3930 private void enforceCallPermission() {
3931 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3932 }
3933
paulhu5a773602019-08-23 19:17:33 +08003934 private void enforceSettingsPermission() {
3935 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003936 }
3937
Michele Berionne5e411512020-11-13 02:36:59 +00003938 private void enforceRebootPermission() {
3939 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3940 }
3941
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003942 /**
3943 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3944 * @param message - log message to print.
3945 * @throws SecurityException if the caller does not have the required permission
3946 */
3947 private void enforceSatelliteCommunicationPermission(String message) {
3948 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3949 }
3950
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003951 private String createTelUrl(String number) {
3952 if (TextUtils.isEmpty(number)) {
3953 return null;
3954 }
3955
Jake Hambye994d462014-02-03 13:10:13 -08003956 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003957 }
3958
Ihab Awadf9e92732013-12-05 18:02:52 -08003959 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003960 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003961 }
3962
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003963 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003964 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003965 }
3966
Ihab Awadf9e92732013-12-05 18:02:52 -08003967 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003968 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003969 }
3970
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003971 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003972 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003973 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003974 }
3975
Sanket Padawe356d7632015-06-22 14:03:32 -07003976 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003977 public int getActivePhoneTypeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003978 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3979 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
3980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 final Phone phone = PhoneFactory.getPhone(slotIndex);
3984 if (phone == null) {
3985 return PhoneConstants.PHONE_TYPE_NONE;
3986 } else {
3987 return phone.getPhoneType();
3988 }
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003992 }
3993
3994 /**
3995 * Returns the CDMA ERI icon index to display
3996 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003997 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003998 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3999 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4000 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004001 }
4002
Sanket Padawe356d7632015-06-22 14:03:32 -07004003 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004004 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4005 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004007 mApp, subId, callingPackage, callingFeatureId,
4008 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004009 return -1;
4010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004011
joonhunshin4ac60942023-11-15 15:23:39 +00004012 enforceTelephonyFeatureWithException(callingPackage,
4013 PackageManager.FEATURE_TELEPHONY_CDMA,
4014 "getCdmaEriIconIndexForSubscriber");
4015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 final Phone phone = getPhone(subId);
4019 if (phone != null) {
4020 return phone.getCdmaEriIconIndex();
4021 } else {
4022 return -1;
4023 }
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004027 }
4028
4029 /**
4030 * Returns the CDMA ERI icon mode,
4031 * 0 - ON
4032 * 1 - FLASHING
4033 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004034 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004035 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4036 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4037 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004038 }
4039
Sanket Padawe356d7632015-06-22 14:03:32 -07004040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004041 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4042 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004043 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004044 mApp, subId, callingPackage, callingFeatureId,
4045 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004046 return -1;
4047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048
4049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 final Phone phone = getPhone(subId);
4052 if (phone != null) {
4053 return phone.getCdmaEriIconMode();
4054 } else {
4055 return -1;
4056 }
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004060 }
4061
4062 /**
4063 * Returns the CDMA ERI text,
4064 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004065 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004066 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4067 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4068 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004069 }
4070
Sanket Padawe356d7632015-06-22 14:03:32 -07004071 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004072 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4073 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004075 mApp, subId, callingPackage, callingFeatureId,
4076 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004077 return null;
4078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079
4080 final long identity = Binder.clearCallingIdentity();
4081 try {
4082 final Phone phone = getPhone(subId);
4083 if (phone != null) {
4084 return phone.getCdmaEriText();
4085 } else {
4086 return null;
4087 }
4088 } finally {
4089 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004091 }
4092
4093 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004094 * Returns the CDMA MDN.
4095 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004096 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004097 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4099 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100
joonhunshin4ac60942023-11-15 15:23:39 +00004101 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4102 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004107 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004108 return phone.getLine1Number();
4109 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004110 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004111 return null;
4112 }
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004115 }
4116 }
4117
4118 /**
4119 * Returns the CDMA MIN.
4120 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004121 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004122 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4124 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125
joonhunshin4ac60942023-11-15 15:23:39 +00004126 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4127 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4128
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004129 final long identity = Binder.clearCallingIdentity();
4130 try {
4131 final Phone phone = getPhone(subId);
4132 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4133 return phone.getCdmaMin();
4134 } else {
4135 return null;
4136 }
4137 } finally {
4138 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004139 }
4140 }
4141
Hall Liud892bec2018-11-30 14:51:45 -08004142 @Override
4143 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4144 INumberVerificationCallback callback, String callingPackage) {
4145 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4146 != PERMISSION_GRANTED) {
4147 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4148 }
4149 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4150
4151 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4152 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004153 throw new SecurityException("Calling package must be configured in the device config: "
4154 + "calling package: " + callingPackage
4155 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004156 }
4157
joonhunshin4ac60942023-11-15 15:23:39 +00004158 enforceTelephonyFeatureWithException(callingPackage,
4159 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4160
Hall Liud892bec2018-11-30 14:51:45 -08004161 if (range == null) {
4162 throw new NullPointerException("Range must be non-null");
4163 }
4164
4165 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004166 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004167
4168 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4169 }
4170
Junda Liuca05d5d2014-08-14 22:36:34 -07004171 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004172 * Returns true if CDMA provisioning needs to run.
4173 */
4174 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004175 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4176 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004178 final long identity = Binder.clearCallingIdentity();
4179 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004180 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004184 }
4185
4186 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004187 * Sets the voice mail number of a given subId.
4188 */
4189 @Override
4190 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004191 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4192 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193
joonhunshin4ac60942023-11-15 15:23:39 +00004194 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4195 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 final long identity = Binder.clearCallingIdentity();
4198 try {
4199 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4200 new Pair<String, String>(alphaTag, number), new Integer(subId));
4201 return success;
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
4204 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004205 }
4206
Ta-wei Yen87c49842016-05-13 21:19:52 -07004207 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004208 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4209 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004210 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4211 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004212 if (!TextUtils.equals(callingPackage, systemDialer)) {
4213 throw new SecurityException("caller must be system dialer");
4214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215
joonhunshin4ac60942023-11-15 15:23:39 +00004216 enforceTelephonyFeatureWithException(callingPackage,
4217 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219 final long identity = Binder.clearCallingIdentity();
4220 try {
4221 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4222 if (phoneAccountHandle == null) {
4223 return null;
4224 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004225 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226 } finally {
4227 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004228 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004229 }
4230
4231 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004232 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4233 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004234 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004236 mApp, subId, callingPackage, callingFeatureId,
4237 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004238 return null;
4239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240
joonhunshin4ac60942023-11-15 15:23:39 +00004241 enforceTelephonyFeatureWithException(callingPackage,
4242 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4243
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004244 final long identity = Binder.clearCallingIdentity();
4245 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004246 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004247 } finally {
4248 Binder.restoreCallingIdentity(identity);
4249 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004250 }
4251
4252 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004253 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4254 VisualVoicemailSmsFilterSettings settings) {
4255 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256
joonhunshin4ac60942023-11-15 15:23:39 +00004257 enforceTelephonyFeatureWithException(callingPackage,
4258 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
4259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 final long identity = Binder.clearCallingIdentity();
4261 try {
4262 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004263 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004267 }
4268
4269 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004270 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4271 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004272
joonhunshin4ac60942023-11-15 15:23:39 +00004273 enforceTelephonyFeatureWithException(callingPackage,
4274 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004279 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004283 }
4284
4285 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004286 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4287 String callingPackage, int subId) {
4288 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289
4290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004293 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004294 } finally {
4295 Binder.restoreCallingIdentity(identity);
4296 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004297 }
4298
4299 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004300 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004302
4303 final long identity = Binder.clearCallingIdentity();
4304 try {
4305 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004306 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004310 }
4311
4312 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004313 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4314 String callingAttributionTag, int subId, String number, int port, String text,
4315 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004317 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004318 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004319
4320 enforceTelephonyFeatureWithException(callingPackage,
4321 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4322
Amit Mahajandccb3f12019-05-13 13:48:32 -07004323 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004324 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4325 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004326 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004327
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004328 /**
fionaxu0152e512016-11-14 13:36:14 -08004329 * Sets the voice activation state of a given subId.
4330 */
4331 @Override
4332 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4334 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335
joonhunshin4ac60942023-11-15 15:23:39 +00004336 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4337 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4338
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004339 final long identity = Binder.clearCallingIdentity();
4340 try {
4341 final Phone phone = getPhone(subId);
4342 if (phone != null) {
4343 phone.setVoiceActivationState(activationState);
4344 } else {
4345 loge("setVoiceActivationState fails with invalid subId: " + subId);
4346 }
4347 } finally {
4348 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004349 }
4350 }
4351
4352 /**
4353 * Sets the data activation state of a given subId.
4354 */
4355 @Override
4356 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4358 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359
joonhunshin4ac60942023-11-15 15:23:39 +00004360 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4361 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004363 final long identity = Binder.clearCallingIdentity();
4364 try {
4365 final Phone phone = getPhone(subId);
4366 if (phone != null) {
4367 phone.setDataActivationState(activationState);
4368 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004369 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370 }
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004373 }
4374 }
4375
4376 /**
4377 * Returns the voice activation state of a given subId.
4378 */
4379 @Override
4380 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382
joonhunshin4ac60942023-11-15 15:23:39 +00004383 enforceTelephonyFeatureWithException(callingPackage,
4384 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4385
fionaxu0152e512016-11-14 13:36:14 -08004386 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 final long identity = Binder.clearCallingIdentity();
4388 try {
4389 if (phone != null) {
4390 return phone.getVoiceActivationState();
4391 } else {
4392 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4393 }
4394 } finally {
4395 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004396 }
4397 }
4398
4399 /**
4400 * Returns the data activation state of a given subId.
4401 */
4402 @Override
4403 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004404 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405
joonhunshin4ac60942023-11-15 15:23:39 +00004406 enforceTelephonyFeatureWithException(callingPackage,
4407 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
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.getDataActivationState();
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 /**
Wink Saville36469e72014-06-11 15:17:00 -07004423 * Returns the unread count of voicemails for a subId
4424 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004425 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004426 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4427 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004428 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004429 mApp, subId, callingPackage, callingFeatureId,
4430 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004431 return 0;
4432 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 final long identity = Binder.clearCallingIdentity();
4434 try {
4435 final Phone phone = getPhone(subId);
4436 if (phone != null) {
4437 return phone.getVoiceMessageCount();
4438 } else {
4439 return 0;
4440 }
4441 } finally {
4442 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004444 }
4445
4446 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004447 * returns true, if the device is in a state where both voice and data
4448 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004449 */
4450 @Override
4451 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004452 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4453 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4454
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 final long identity = Binder.clearCallingIdentity();
4456 try {
Ling Mac28f0212023-03-24 16:07:15 -07004457 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 } finally {
4459 Binder.restoreCallingIdentity(identity);
4460 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004461 }
4462
4463 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004464 * Send the dialer code if called from the current default dialer or the caller has
4465 * carrier privilege.
4466 * @param inputCode The dialer code to send
4467 */
4468 @Override
4469 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004470 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004472 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4473 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004474 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004475 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004476 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478
joonhunshin4ac60942023-11-15 15:23:39 +00004479 enforceTelephonyFeatureWithException(callingPackage,
4480 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 final long identity = Binder.clearCallingIdentity();
4483 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004484 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 } finally {
4486 Binder.restoreCallingIdentity(identity);
4487 }
fionaxu235cc5e2017-03-06 22:25:57 -08004488 }
4489
Pengquan Menga1bb6272018-09-06 09:59:22 -07004490 @Override
4491 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004492 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004493 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4494 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004495
4496 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4497 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4498
shilufc958392020-01-20 11:36:01 -08004499 final long identity = Binder.clearCallingIdentity();
4500 try {
4501 if (!isActiveSubscription(subId)) {
4502 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4503 }
4504 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4505 } finally {
4506 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004507 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004508 }
4509
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004511 public boolean isInEmergencySmsMode() {
4512 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004513
4514 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4515 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4516
Brad Ebingerb2b65522019-03-15 13:48:47 -07004517 final long identity = Binder.clearCallingIdentity();
4518 try {
4519 for (Phone phone : PhoneFactory.getPhones()) {
4520 if (phone.isInEmergencySmsMode()) {
4521 return true;
4522 }
4523 }
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
4527 return false;
4528 }
4529
shilu366312e2019-12-17 09:28:10 -08004530 /**
4531 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4532 * @param subId The subscription to use to check the configuration.
4533 * @param c The callback that will be used to send the result.
4534 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004535 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004536 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4537 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004538 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004539 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004540
4541 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4542 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4543 "IMS not available on device.");
4544 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004545 final long token = Binder.clearCallingIdentity();
4546 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004547 int slotId = getSlotIndexOrException(subId);
4548 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004549
4550 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4551 if (controller != null) {
4552 ImsManager imsManager = controller.getImsManager(subId);
4553 if (imsManager != null) {
4554 imsManager.addRegistrationCallbackForSubscription(c, subId);
4555 } else {
4556 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4557 }
4558 } else {
4559 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4560 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004561 } catch (ImsException e) {
4562 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004563 } finally {
4564 Binder.restoreCallingIdentity(token);
4565 }
4566 }
4567
shilu366312e2019-12-17 09:28:10 -08004568 /**
4569 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4570 * @param subId The subscription to use to check the configuration.
4571 * @param c The callback that will be used to send the result.
4572 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004573 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004574 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004575 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004576 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004577 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4578 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4579 }
Meng Wangafbc5852019-09-19 17:37:13 -07004580 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004581
Meng Wangafbc5852019-09-19 17:37:13 -07004582 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004583 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4584 if (controller != null) {
4585 ImsManager imsManager = controller.getImsManager(subId);
4586 if (imsManager != null) {
4587 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4588 } else {
4589 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4590 + "is inactive, ignoring unregister.");
4591 // If the ImsManager is not valid, just return, since the callback
4592 // will already have been removed internally.
4593 }
4594 }
Meng Wangafbc5852019-09-19 17:37:13 -07004595 } finally {
4596 Binder.restoreCallingIdentity(token);
4597 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 }
4599
Brad Ebingera34a6c22019-10-22 17:36:18 -07004600 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004601 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4602 * @param subId The subscription to use to check the configuration.
4603 * @param c The callback that will be used to send the result.
4604 */
4605 @Override
4606 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4607 throws RemoteException {
4608 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4609 mApp, subId, "registerImsEmergencyRegistrationCallback");
4610
4611 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4612 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4613 "IMS not available on device.");
4614 }
4615 final long token = Binder.clearCallingIdentity();
4616 try {
4617 int slotId = getSlotIndexOrException(subId);
4618 verifyImsMmTelConfiguredOrThrow(slotId);
4619
4620 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4621 if (controller != null) {
4622 ImsManager imsManager = controller.getImsManager(subId);
4623 if (imsManager != null) {
4624 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4625 } else {
4626 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4627 }
4628 } else {
4629 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4630 }
4631 } catch (ImsException e) {
4632 throw new ServiceSpecificException(e.getCode());
4633 } finally {
4634 Binder.restoreCallingIdentity(token);
4635 }
4636 }
4637
4638 /**
4639 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4640 * @param subId The subscription to use to check the configuration.
4641 * @param c The callback that will be used to send the result.
4642 */
4643 @Override
4644 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4645 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4646 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4647 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4648 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4649 }
4650 final long token = Binder.clearCallingIdentity();
4651
4652 try {
4653 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4654 if (controller != null) {
4655 ImsManager imsManager = controller.getImsManager(subId);
4656 if (imsManager != null) {
4657 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4658 } else {
4659 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4660 + "is inactive, ignoring unregister.");
4661 // If the ImsManager is not valid, just return, since the callback
4662 // will already have been removed internally.
4663 }
4664 }
4665 } finally {
4666 Binder.restoreCallingIdentity(token);
4667 }
4668 }
4669
4670 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004671 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4672 */
4673 @Override
4674 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4675 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4676 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4677 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4678 "IMS not available on device.");
4679 }
4680 final long token = Binder.clearCallingIdentity();
4681 try {
4682 Phone phone = getPhone(subId);
4683 if (phone == null) {
4684 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4685 + subId + "'");
4686 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4687 }
4688 phone.getImsRegistrationState(regState -> {
4689 try {
4690 consumer.accept((regState == null)
4691 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4692 } catch (RemoteException e) {
4693 // Ignore if the remote process is no longer available to call back.
4694 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4695 }
4696 });
4697 } finally {
4698 Binder.restoreCallingIdentity(token);
4699 }
4700 }
4701
4702 /**
4703 * Get the transport type for the IMS service registration state.
4704 */
4705 @Override
4706 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004707 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004708 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004709 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4710 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4711 "IMS not available on device.");
4712 }
4713 final long token = Binder.clearCallingIdentity();
4714 try {
4715 Phone phone = getPhone(subId);
4716 if (phone == null) {
4717 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4718 + subId + "'");
4719 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4720 }
4721 phone.getImsRegistrationTech(regTech -> {
4722 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4723 int regTechConverted = (regTech == null)
4724 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4725 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4726 regTechConverted);
4727 try {
4728 consumer.accept(regTechConverted);
4729 } catch (RemoteException e) {
4730 // Ignore if the remote process is no longer available to call back.
4731 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4732 }
4733 });
4734 } finally {
4735 Binder.restoreCallingIdentity(token);
4736 }
4737 }
4738
shilu366312e2019-12-17 09:28:10 -08004739 /**
4740 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4741 * @param subId The subscription to use to check the configuration.
4742 * @param c The callback that will be used to send the result.
4743 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004744 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004745 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4746 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004747 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004748 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004749 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4750 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4751 "IMS not available on device.");
4752 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004753 final long token = Binder.clearCallingIdentity();
4754 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004755 int slotId = getSlotIndexOrException(subId);
4756 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004757
4758 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4759 if (controller != null) {
4760 ImsManager imsManager = controller.getImsManager(subId);
4761 if (imsManager != null) {
4762 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4763 } else {
4764 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4765 }
4766 } else {
4767 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4768 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004769 } catch (ImsException e) {
4770 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004771 } finally {
4772 Binder.restoreCallingIdentity(token);
4773 }
4774 }
4775
shilu366312e2019-12-17 09:28:10 -08004776 /**
4777 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4778 * @param subId The subscription to use to check the configuration.
4779 * @param c The callback that will be used to send the result.
4780 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004781 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004782 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004783 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004784 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4786 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4787 }
Meng Wangafbc5852019-09-19 17:37:13 -07004788
4789 final long token = Binder.clearCallingIdentity();
4790 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004791 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4792 if (controller != null) {
4793 ImsManager imsManager = controller.getImsManager(subId);
4794 if (imsManager != null) {
4795 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4796 } else {
4797 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4798 + " is inactive, ignoring unregister.");
4799 // If the ImsManager is not valid, just return, since the callback
4800 // will already have been removed internally.
4801 }
4802 }
Meng Wangafbc5852019-09-19 17:37:13 -07004803 } finally {
4804 Binder.restoreCallingIdentity(token);
4805 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004806 }
4807
4808 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004809 public boolean isCapable(int subId, int capability, int regTech) {
4810 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004811
4812 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4813 FEATURE_TELEPHONY_IMS, "isCapable");
4814
Brad Ebinger35c841c2018-10-01 10:40:55 -07004815 final long token = Binder.clearCallingIdentity();
4816 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004817 int slotId = getSlotIndexOrException(subId);
4818 verifyImsMmTelConfiguredOrThrow(slotId);
4819 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4820 } catch (com.android.ims.ImsException e) {
4821 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4822 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004823 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004824 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4825 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004826 } finally {
4827 Binder.restoreCallingIdentity(token);
4828 }
4829 }
4830
4831 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004832 public boolean isAvailable(int subId, int capability, int regTech) {
4833 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004834
4835 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4836 FEATURE_TELEPHONY_IMS, "isAvailable");
4837
Brad Ebinger35c841c2018-10-01 10:40:55 -07004838 final long token = Binder.clearCallingIdentity();
4839 try {
4840 Phone phone = getPhone(subId);
4841 if (phone == null) return false;
4842 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004843 } catch (com.android.ims.ImsException e) {
4844 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4845 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004846 } finally {
4847 Binder.restoreCallingIdentity(token);
4848 }
4849 }
4850
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004851 /**
4852 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4853 * subscription.
4854 * @param subId The subscription to use to check the configuration.
4855 * @param callback The callback that will be used to send the result.
4856 * @param capability The MmTelFeature capability that will be used to send the result.
4857 * @param transportType The transport type of the MmTelFeature capability.
4858 */
4859 @Override
4860 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4861 int transportType) {
4862 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004863 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4864 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4865 "IMS not available on device.");
4866 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004867 final long token = Binder.clearCallingIdentity();
4868 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004869 int slotId = getSlotIndex(subId);
4870 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4871 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4872 + subId + "'");
4873 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4874 }
4875 verifyImsMmTelConfiguredOrThrow(slotId);
4876 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4877 transportType, aBoolean -> {
4878 try {
4879 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4880 } catch (RemoteException e) {
4881 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4882 + "running. Ignore");
4883 }
4884 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004885 } catch (ImsException e) {
4886 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004887 } finally {
4888 Binder.restoreCallingIdentity(token);
4889 }
4890 }
4891
shilu366312e2019-12-17 09:28:10 -08004892 /**
4893 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4894 * @param subId The subscription to use to check the configuration.
4895 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004896 @Override
4897 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004898 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004899 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004900
joonhunshin4ac60942023-11-15 15:23:39 +00004901 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4902 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4903
Brad Ebinger35c841c2018-10-01 10:40:55 -07004904 final long token = Binder.clearCallingIdentity();
4905 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004906 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004907 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004908 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004909 } catch (ImsException e) {
4910 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004911 } finally {
4912 Binder.restoreCallingIdentity(token);
4913 }
4914 }
4915
4916 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004917 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004919 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004920
4921 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4922 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4923
Brad Ebinger35c841c2018-10-01 10:40:55 -07004924 final long identity = Binder.clearCallingIdentity();
4925 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004926 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004927 // This setting doesn't require an active ImsService connection, so do not verify. The
4928 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004929 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004930 } catch (ImsException e) {
4931 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
shilu366312e2019-12-17 09:28:10 -08004937 /**
4938 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4939 * @param subId The subscription to use to check the configuration.
4940 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004941 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004942 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004943 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004944 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004945
4946 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4947 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4948
Brad Ebinger35c841c2018-10-01 10:40:55 -07004949 final long identity = Binder.clearCallingIdentity();
4950 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004951 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004952 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004953 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004954 } catch (ImsException e) {
4955 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004956 } finally {
4957 Binder.restoreCallingIdentity(identity);
4958 }
4959 }
4960
4961 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004962 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004964 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004965
4966 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4967 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
4968
Brad Ebinger35c841c2018-10-01 10:40:55 -07004969 final long identity = Binder.clearCallingIdentity();
4970 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004971 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004972 // This setting doesn't require an active ImsService connection, so do not verify. The
4973 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004974 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004975 } catch (ImsException e) {
4976 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004977 } finally {
4978 Binder.restoreCallingIdentity(identity);
4979 }
4980 }
4981
shilu366312e2019-12-17 09:28:10 -08004982 /**
4983 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4984 * @param subId The subscription to use to check the configuration.
4985 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004986 @Override
4987 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004988 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004989 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004990
4991 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4992 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
4993
Brad Ebinger35c841c2018-10-01 10:40:55 -07004994 final long identity = Binder.clearCallingIdentity();
4995 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004996 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004997 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004998 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004999 } catch (ImsException e) {
5000 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005001 } finally {
5002 Binder.restoreCallingIdentity(identity);
5003 }
5004 }
5005
5006 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005007 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005009 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005010
5011 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5012 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5013
Brad Ebinger35c841c2018-10-01 10:40:55 -07005014 final long identity = Binder.clearCallingIdentity();
5015 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005016 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005017 // This setting doesn't require an active ImsService connection, so do not verify. The
5018 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005019 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005020 } catch (ImsException e) {
5021 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005022 } finally {
5023 Binder.restoreCallingIdentity(identity);
5024 }
5025 }
5026
shilu366312e2019-12-17 09:28:10 -08005027 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005028 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5029 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5030 * @param subId The subscription to use to check the configuration.
5031 */
5032 @Override
5033 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005034 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005035 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005036
5037 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5038 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5039
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005040 final long identity = Binder.clearCallingIdentity();
5041 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005042 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005043 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005044 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005045 } catch (ImsException e) {
5046 throw new ServiceSpecificException(e.getCode());
5047 } finally {
5048 Binder.restoreCallingIdentity(identity);
5049 }
5050 }
5051
5052 /**
5053 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5054 * Requires MODIFY_PHONE_STATE permission.
5055 * @param subId The subscription to use to check the configuration.
5056 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5057 * false otherwise
5058 */
5059 @Override
5060 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5062 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005063
5064 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5065 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5066
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005067 final long identity = Binder.clearCallingIdentity();
5068 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005069 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005070 // This setting doesn't require an active ImsService connection, so do not verify. The
5071 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005072 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005073 } catch (ImsException e) {
5074 throw new ServiceSpecificException(e.getCode());
5075 } finally {
5076 Binder.restoreCallingIdentity(identity);
5077 }
5078 }
5079
5080 /**
shilu366312e2019-12-17 09:28:10 -08005081 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5082 * @param subId The subscription to use to check the configuration.
5083 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005084 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005085
Brad Ebinger35c841c2018-10-01 10:40:55 -07005086 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005087 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005088 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005089
5090 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5091 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5092
Brad Ebinger35c841c2018-10-01 10:40:55 -07005093 final long identity = Binder.clearCallingIdentity();
5094 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005095 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005096 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005097 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005098 } catch (ImsException e) {
5099 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
5103 }
5104
5105 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005106 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005108 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005109
5110 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5111 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5112
Brad Ebinger35c841c2018-10-01 10:40:55 -07005113 final long identity = Binder.clearCallingIdentity();
5114 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005115 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005116 // This setting doesn't require an active ImsService connection, so do not verify. The
5117 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005118 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005119 } catch (ImsException e) {
5120 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005121 } finally {
5122 Binder.restoreCallingIdentity(identity);
5123 }
5124 }
5125
5126 @Override
5127 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5129 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005130
5131 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5132 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5133
Brad Ebinger35c841c2018-10-01 10:40:55 -07005134 final long identity = Binder.clearCallingIdentity();
5135 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005136 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005137 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005138 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005139 } catch (ImsException e) {
5140 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005141 } finally {
5142 Binder.restoreCallingIdentity(identity);
5143 }
5144 }
5145
shilu366312e2019-12-17 09:28:10 -08005146 /**
5147 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5148 * @param subId The subscription to use to check the configuration.
5149 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005150 @Override
5151 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005152 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005153 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005154
5155 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5156 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5157
Brad Ebinger35c841c2018-10-01 10:40:55 -07005158 final long identity = Binder.clearCallingIdentity();
5159 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005160 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005161 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005162 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005163 } catch (ImsException e) {
5164 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005165 } finally {
5166 Binder.restoreCallingIdentity(identity);
5167 }
5168 }
5169
5170 @Override
5171 public void setVoWiFiModeSetting(int subId, int mode) {
5172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5173 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005174
5175 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5176 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5177
Brad Ebinger35c841c2018-10-01 10:40:55 -07005178 final long identity = Binder.clearCallingIdentity();
5179 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005180 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005181 // This setting doesn't require an active ImsService connection, so do not verify. The
5182 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005183 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005184 } catch (ImsException e) {
5185 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005186 } finally {
5187 Binder.restoreCallingIdentity(identity);
5188 }
5189 }
5190
5191 @Override
5192 public int getVoWiFiRoamingModeSetting(int subId) {
5193 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005194
5195 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5196 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5197
Brad Ebinger35c841c2018-10-01 10:40:55 -07005198 final long identity = Binder.clearCallingIdentity();
5199 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005200 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005201 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005202 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005203 } catch (ImsException e) {
5204 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
5208 }
5209
5210 @Override
5211 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5213 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005214
5215 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5216 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5217
Brad Ebinger35c841c2018-10-01 10:40:55 -07005218 final long identity = Binder.clearCallingIdentity();
5219 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005220 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005221 // This setting doesn't require an active ImsService connection, so do not verify. The
5222 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005223 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005224 } catch (ImsException e) {
5225 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
5229 }
5230
5231 @Override
5232 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5234 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005235
5236 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5237 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5238
Brad Ebinger35c841c2018-10-01 10:40:55 -07005239 final long identity = Binder.clearCallingIdentity();
5240 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005241 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005242 // This setting doesn't require an active ImsService connection, so do not verify. The
5243 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005244 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005245 } catch (ImsException e) {
5246 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
5250 }
5251
shilu366312e2019-12-17 09:28:10 -08005252 /**
5253 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5254 * @param subId The subscription to use to check the configuration.
5255 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005256 @Override
5257 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005258 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005259 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005260
5261 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5262 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5263
Brad Ebinger35c841c2018-10-01 10:40:55 -07005264 final long identity = Binder.clearCallingIdentity();
5265 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005266 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005267 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005268 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005269 } catch (ImsException e) {
5270 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005271 } finally {
5272 Binder.restoreCallingIdentity(identity);
5273 }
5274 }
5275
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005276 @Override
5277 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5278 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005279
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005280 final long identity = Binder.clearCallingIdentity();
5281 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005282 if (!isImsAvailableOnDevice()) {
5283 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5284 "IMS not available on device.");
5285 }
5286 int slotId = getSlotIndexOrException(subId);
5287 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005288
5289 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5290 if (controller != null) {
5291 ImsManager imsManager = controller.getImsManager(subId);
5292 if (imsManager != null) {
5293 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5294 } else {
5295 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5296 }
5297 } else {
5298 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5299 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005300 } catch (ImsException e) {
5301 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
5305 }
5306
5307 @Override
5308 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5309 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005310
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005311 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005312 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5313 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5314 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005315 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005316 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5317 if (controller != null) {
5318 ImsManager imsManager = controller.getImsManager(subId);
5319 if (imsManager != null) {
5320 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5321 } else {
5322 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5323 + " is inactive, ignoring unregister.");
5324 // If the ImsManager is not valid, just return, since the callback will already
5325 // have been removed internally.
5326 }
5327 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005328 } finally {
5329 Binder.restoreCallingIdentity(identity);
5330 }
5331 }
5332
joonhunshincffb7fc2021-11-28 07:32:01 +00005333 @Override
5334 public void registerFeatureProvisioningChangedCallback(int subId,
5335 IFeatureProvisioningCallback callback) {
5336 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5337 mApp, subId, "registerFeatureProvisioningChangedCallback");
5338
5339 final long identity = Binder.clearCallingIdentity();
5340 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5341 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5342 }
5343
joonhunshin91bc1952022-04-29 08:47:15 +00005344 try {
5345 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5346 if (controller == null) {
5347 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5348 "Device does not support IMS");
5349 }
5350 controller.addFeatureProvisioningChangedCallback(subId, callback);
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005354 }
5355
5356 @Override
5357 public void unregisterFeatureProvisioningChangedCallback(int subId,
5358 IFeatureProvisioningCallback callback) {
5359 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5360 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
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 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5371 return;
5372 }
5373 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
5376 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005377 }
allenwtsu99c623b2020-01-03 18:24:23 +08005378
5379 private void checkModifyPhoneStatePermission(int subId, String message) {
5380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5381 message);
5382 }
5383
allenwtsu99c623b2020-01-03 18:24:23 +08005384 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005385 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005386 boolean isProvisioned) {
5387 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5388
joonhunshin4ac60942023-11-15 15:23:39 +00005389 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5390 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5391
allenwtsu99c623b2020-01-03 18:24:23 +08005392 final long identity = Binder.clearCallingIdentity();
5393 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005394 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5395 if (controller == null) {
5396 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5397 return;
5398 }
5399 controller.setRcsProvisioningStatusForCapability(
5400 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
allenwtsu99c623b2020-01-03 18:24:23 +08005404 }
5405
5406
5407 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005408 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5409 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5410 mApp, subId, "getRcsProvisioningStatusForCapability");
5411
joonhunshin4ac60942023-11-15 15:23:39 +00005412 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5413 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
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("getRcsProvisioningStatusForCapability: Device does not support IMS");
5420
5421 // device does not support IMS, this method will return true always.
5422 return true;
5423 }
5424 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005425 } finally {
5426 Binder.restoreCallingIdentity(identity);
5427 }
5428 }
5429
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005430 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005431 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5432 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005433 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005434
joonhunshin4ac60942023-11-15 15:23:39 +00005435 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5436 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5437
Brad Ebinger1c8542e2019-01-14 13:43:14 -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("setImsProvisioningStatusForCapability: Device does not support IMS");
5443 return;
5444 }
5445 controller.setImsProvisioningStatusForCapability(
5446 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005447 } finally {
5448 Binder.restoreCallingIdentity(identity);
5449 }
5450 }
5451
5452 @Override
5453 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005454 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5455 mApp, subId, "getProvisioningStatusForCapability");
5456
joonhunshin4ac60942023-11-15 15:23:39 +00005457 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5458 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5459
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005460 final long identity = Binder.clearCallingIdentity();
5461 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005462 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5463 if (controller == null) {
5464 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005465
joonhunshin91bc1952022-04-29 08:47:15 +00005466 // device does not support IMS, this method will return true always.
5467 return true;
5468 }
5469 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005470 } finally {
5471 Binder.restoreCallingIdentity(identity);
5472 }
5473 }
5474
5475 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005476 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5477 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5478 mApp, subId, "isProvisioningRequiredForCapability");
5479
joonhunshin4ac60942023-11-15 15:23:39 +00005480 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5481 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5482
joonhunshincffb7fc2021-11-28 07:32:01 +00005483 final long identity = Binder.clearCallingIdentity();
5484 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005485 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5486 if (controller == null) {
5487 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5488
5489 // device does not support IMS, this method will return false
5490 return false;
5491 }
5492 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005493 } finally {
5494 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005495 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005496 }
5497
5498 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005499 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5500 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5501 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005502
joonhunshin4ac60942023-11-15 15:23:39 +00005503 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5504 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
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("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5511
5512 // device does not support IMS, this method will return false
5513 return false;
5514 }
5515 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005519 }
5520
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005521 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005522 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005523 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5524 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5525 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005526 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5527 mApp, subId, "getImsProvisioningInt");
5528
joonhunshin4ac60942023-11-15 15:23:39 +00005529 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5530 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5531
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005532 final long identity = Binder.clearCallingIdentity();
5533 try {
5534 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005535 int slotId = getSlotIndex(subId);
5536 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5537 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5538 + subId + "' for key:" + key);
5539 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5540 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005541
joonhunshin91bc1952022-04-29 08:47:15 +00005542 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5543 if (controller == null) {
5544 loge("getImsProvisioningInt: Device does not support IMS");
5545
5546 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5547 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5548 }
5549 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005550 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5551 return retVal;
5552 }
5553
calvinpanb5a34062021-02-08 19:59:36 +08005554 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005555 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005556 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5557 + subId + "' for key:" + key);
5558 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005559 } finally {
5560 Binder.restoreCallingIdentity(identity);
5561 }
5562 }
5563
5564 @Override
5565 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005566 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5567 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5568 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005569 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5570 mApp, subId, "getImsProvisioningString");
5571
joonhunshin4ac60942023-11-15 15:23:39 +00005572 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5573 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5574
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005575 final long identity = Binder.clearCallingIdentity();
5576 try {
5577 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005578 int slotId = getSlotIndex(subId);
5579 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5580 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5581 + subId + "' for key:" + key);
5582 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5583 }
calvinpanb5a34062021-02-08 19:59:36 +08005584 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005585 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005586 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5587 + subId + "' for key:" + key);
5588 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005589 } finally {
5590 Binder.restoreCallingIdentity(identity);
5591 }
5592 }
5593
5594 @Override
5595 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005596 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5597 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5598 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5600 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005601
joonhunshin4ac60942023-11-15 15:23:39 +00005602 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5603 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5604
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005605 final long identity = Binder.clearCallingIdentity();
5606 try {
5607 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005608 int slotId = getSlotIndex(subId);
5609 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5610 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5611 + subId + "' for key:" + key);
5612 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5613 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005614
joonhunshin91bc1952022-04-29 08:47:15 +00005615 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5616 if (controller == null) {
5617 loge("setImsProvisioningInt: Device does not support IMS");
5618
5619 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5620 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5621 }
5622 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005623 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5624 return retVal;
5625 }
5626
calvinpanb5a34062021-02-08 19:59:36 +08005627 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5628 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005629 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005630 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005631 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005632 } finally {
5633 Binder.restoreCallingIdentity(identity);
5634 }
5635 }
5636
5637 @Override
5638 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005639 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5640 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5641 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5643 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005644
5645 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5646 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5647
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005648 final long identity = Binder.clearCallingIdentity();
5649 try {
5650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005651 int slotId = getSlotIndex(subId);
5652 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5653 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5654 + subId + "' for key:" + key);
5655 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5656 }
calvinpanb5a34062021-02-08 19:59:36 +08005657 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5658 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005659 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005660 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005661 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005662 } finally {
5663 Binder.restoreCallingIdentity(identity);
5664 }
5665 }
5666
Brad Ebinger919631e2021-06-02 17:46:35 -07005667 /**
5668 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5669 * for the given slot ID or no ImsResolver instance has been created.
5670 * @param slotId The slot ID that the IMS service is created for.
5671 * @throws ImsException If there is no ImsService configured for this slot.
5672 */
5673 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5674 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5675 ImsFeature.FEATURE_MMTEL)) {
5676 throw new ImsException("This subscription does not support MMTEL over IMS",
5677 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5678 }
5679 }
5680
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005681 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005682 int slotId = SubscriptionManager.getSlotIndex(subId);
5683 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005684 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5685 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005686 }
5687 return slotId;
5688 }
5689
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005690 private int getSlotIndex(int subId) {
5691 int slotId = SubscriptionManager.getSlotIndex(subId);
5692 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5693 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5694 }
5695 return slotId;
5696 }
5697
Wink Saville36469e72014-06-11 15:17:00 -07005698 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005699 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005700 */
5701 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005702 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5703 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005704 try {
5705 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5706 } catch (SecurityException se) {
5707 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5708 throw new SecurityException("Package " + callingPackage + " does not belong to "
5709 + Binder.getCallingUid());
5710 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005711 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005712 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005713 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005714 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005715 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005716 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005717 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005718 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5719 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005720
joonhunshin4ac60942023-11-15 15:23:39 +00005721 enforceTelephonyFeatureWithException(callingPackage,
5722 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 final long identity = Binder.clearCallingIdentity();
5725 try {
5726 final Phone phone = getPhone(subId);
5727 if (phone != null) {
5728 return phone.getServiceState().getDataNetworkType();
5729 } else {
5730 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5731 }
5732 } finally {
5733 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005735 }
5736
5737 /**
5738 * Returns the data network type
5739 */
5740 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005741 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005742 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005743 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005744 }
5745
5746 /**
5747 * Returns the data network type for a subId
5748 */
5749 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005750 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5751 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005752 String functionName = "getDataNetworkTypeForSubscriber";
5753 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5754 mApp, functionName)) {
5755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5756 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5757 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5758 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005759 }
5760
joonhunshin4ac60942023-11-15 15:23:39 +00005761 enforceTelephonyFeatureWithException(callingPackage,
5762 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 final long identity = Binder.clearCallingIdentity();
5765 try {
5766 final Phone phone = getPhone(subId);
5767 if (phone != null) {
5768 return phone.getServiceState().getDataNetworkType();
5769 } else {
5770 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5771 }
5772 } finally {
5773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005775 }
5776
5777 /**
Wink Saville36469e72014-06-11 15:17:00 -07005778 * Returns the Voice network type for a subId
5779 */
5780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005781 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5782 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005783 String functionName = "getVoiceNetworkTypeForSubscriber";
5784 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5785 mApp, functionName)) {
5786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5787 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5788 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5789 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005790 }
5791
joonhunshin4ac60942023-11-15 15:23:39 +00005792 enforceTelephonyFeatureWithException(callingPackage,
5793 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 final long identity = Binder.clearCallingIdentity();
5796 try {
5797 final Phone phone = getPhone(subId);
5798 if (phone != null) {
5799 return phone.getServiceState().getVoiceNetworkType();
5800 } else {
5801 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5802 }
5803 } finally {
5804 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005805 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005806 }
5807
5808 /**
5809 * @return true if a ICC card is present
5810 */
5811 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005812 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005813 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005814 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005815 }
5816
5817 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005818 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005819 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005820 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005821 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00005822 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5823 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 final Phone phone = PhoneFactory.getPhone(slotIndex);
5828 if (phone != null) {
5829 return phone.getIccCard().hasIccCard();
5830 } else {
5831 return false;
5832 }
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005836 }
5837
5838 /**
5839 * Return if the current radio is LTE on CDMA. This
5840 * is a tri-state return value as for a period of time
5841 * the mode may be unknown.
5842 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005843 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005844 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005845 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005846 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005848 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5849 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5850 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005851 }
5852
Sanket Padawe356d7632015-06-22 14:03:32 -07005853 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005854 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5855 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005856 try {
5857 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5858 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005859 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5860 }
5861
joonhunshin4ac60942023-11-15 15:23:39 +00005862 enforceTelephonyFeatureWithException(callingPackage,
5863 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865 final long identity = Binder.clearCallingIdentity();
5866 try {
5867 final Phone phone = getPhone(subId);
5868 if (phone == null) {
5869 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5870 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005871 return TelephonyProperties.lte_on_cdma_device()
5872 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873 }
5874 } finally {
5875 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005876 }
Wink Saville36469e72014-06-11 15:17:00 -07005877 }
5878
Wink Saville36469e72014-06-11 15:17:00 -07005879 /**
5880 * {@hide}
5881 * Returns Default subId, 0 in the case of single standby.
5882 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005883 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005884 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005885 }
5886
Shishir Agrawala9f32182016-04-12 12:00:16 -07005887 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005888 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005889 }
5890
Wink Savilleb564aae2014-10-23 10:18:09 -07005891 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005892 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005893 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005894
Pengquan Menge92a50d2018-09-21 15:54:48 -07005895 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005896 return getSubscriptionManagerService().isActiveSubId(subId,
5897 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005898 }
5899
Ihab Awadf2177b72013-11-25 13:33:23 -08005900 /**
5901 * @see android.telephony.TelephonyManager.WifiCallingChoices
5902 */
5903 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904 final long identity = Binder.clearCallingIdentity();
5905 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005906 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5908 getWhenToMakeWifiCallsDefaultPreference());
5909 } finally {
5910 Binder.restoreCallingIdentity(identity);
5911 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005912 }
5913
5914 /**
5915 * @see android.telephony.TelephonyManager.WifiCallingChoices
5916 */
5917 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005921 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5923 } finally {
5924 Binder.restoreCallingIdentity(identity);
5925 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005926 }
5927
Sailesh Nepald1e68152013-12-12 19:08:02 -08005928 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005929 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005930 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005931 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005932
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005933 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5934 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5935 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005936 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005937 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005938 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005939 }
5940 return PhoneFactory.getPhone(phoneId);
5941 }
5942
Shishir Agrawal566b7612013-10-28 14:41:00 -07005943 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005944 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005945 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005946
Rambo Wanga1782702021-11-10 20:15:19 -08005947 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5948 /*message=*/ "iccOpenLogicalChannel");
5949
5950 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5951 // Verify that the callingPackage in the request belongs to the calling UID
5952 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5953
joonhunshin4ac60942023-11-15 15:23:39 +00005954 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5955 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5956
Rambo Wanga1782702021-11-10 20:15:19 -08005957 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005958 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005959
Rambo Wanga1782702021-11-10 20:15:19 -08005960 private Phone getPhoneFromValidIccLogicalChannelRequest(
5961 @NonNull IccLogicalChannelRequest request, String message) {
5962 Phone phone;
5963 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5965 mApp, request.subId, message);
5966 phone = getPhoneFromSubId(request.subId);
5967 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5968 enforceModifyPermission();
5969 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5970 } else {
5971 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005972 }
Rambo Wanga1782702021-11-10 20:15:19 -08005973 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005974 }
5975
5976 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005977 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 final long identity = Binder.clearCallingIdentity();
5979 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005980 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005982 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5983 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005984 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5985 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 loge("The calling package is not allowed to access ISD-R.");
5987 throw new SecurityException(
5988 "The calling package is not allowed to access ISD-R.");
5989 }
Derek Tan740e1672017-06-27 14:56:27 -07005990 }
Derek Tan740e1672017-06-27 14:56:27 -07005991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005993 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5994 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 return response;
5996 } finally {
5997 Binder.restoreCallingIdentity(identity);
5998 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005999 }
6000
6001 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006002 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006003 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6004 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6005
Rambo Wanga1782702021-11-10 20:15:19 -08006006 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6007 /*message=*/"iccCloseLogicalChannel");
6008
6009 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6010
6011 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006012 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006013
Rambo Wanga1782702021-11-10 20:15:19 -08006014 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6015 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006016 // before this feature is enabled, this API should only return false if
6017 // the operation fails instead of throwing runtime exception for
6018 // backward-compatibility.
6019 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6020 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 final long identity = Binder.clearCallingIdentity();
6022 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006023 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006024 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025 }
Chen Xue9d737e2022-01-01 23:41:31 -08006026 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006027 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006028 Boolean success = false;
6029 if (result instanceof RuntimeException) {
6030 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006031 if (shouldThrowExceptionOnFailure) {
6032 throw (RuntimeException) result;
6033 } else {
6034 return false;
6035 }
Chen Xue9d737e2022-01-01 23:41:31 -08006036 } else if (result instanceof Boolean) {
6037 success = (Boolean) result;
6038 } else {
6039 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6040 }
Rambo Wanga1782702021-11-10 20:15:19 -08006041 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 return success;
6043 } finally {
6044 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006045 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006046 }
6047
6048 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006049 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006050 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6052 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006053
6054 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6055 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6056
Jordan Liu4c733742019-02-28 12:03:40 -08006057 if (DBG) {
6058 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6059 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6060 + p3 + " data=" + data);
6061 }
6062 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6063 command, p1, p2, p3, data);
6064 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006065
Jordan Liu4c733742019-02-28 12:03:40 -08006066 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006067 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006068 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006069 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006070
6071 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6072 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6073 "iccTransmitApduLogicalChannelBySlot");
6074
Jordan Liu4c733742019-02-28 12:03:40 -08006075 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006076 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006077 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6078 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006079 }
6080 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006081 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6082 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006083 }
6084
6085 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6086 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 final long identity = Binder.clearCallingIdentity();
6088 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006089 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 return "";
6091 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006094 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6095 null /* workSource */);
6096 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006098 // Append the returned status code to the end of the response payload.
6099 String s = Integer.toHexString(
6100 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6101 if (response.payload != null) {
6102 s = IccUtils.bytesToHexString(response.payload) + s;
6103 }
6104 return s;
6105 } finally {
6106 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006107 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006108 }
Jake Hambye994d462014-02-03 13:10:13 -08006109
Evan Charltonc66da362014-05-16 14:06:40 -07006110 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006111 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6112 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6114 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006116
6117 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6118 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6119
Jordan Liu4c733742019-02-28 12:03:40 -08006120 if (DBG) {
6121 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6122 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6123 }
6124 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6125 cla, command, p1, p2, p3, data);
6126 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006127
Jordan Liu4c733742019-02-28 12:03:40 -08006128 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006129 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006130 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006131 enforceModifyPermission();
6132 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006133
6134 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6135 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6136
Jordan Liu4c733742019-02-28 12:03:40 -08006137 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006138 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006139 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6140 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006141 }
6142
6143 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006144 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6145 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006146 }
6147
6148 // open APDU basic channel assuming the caller has sufficient permissions
6149 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6150 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 final long identity = Binder.clearCallingIdentity();
6152 try {
6153 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6154 && TextUtils.equals(ISDR_AID, data)) {
6155 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006156 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6157 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 if (bestComponent == null
6159 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6160 loge("The calling package is not allowed to select ISD-R.");
6161 throw new SecurityException(
6162 "The calling package is not allowed to select ISD-R.");
6163 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006164 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006167 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6168 null /* workSource */);
6169 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 // Append the returned status code to the end of the response payload.
6172 String s = Integer.toHexString(
6173 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6174 if (response.payload != null) {
6175 s = IccUtils.bytesToHexString(response.payload) + s;
6176 }
6177 return s;
6178 } finally {
6179 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006180 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006181 }
6182
6183 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006184 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006185 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6187 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006188
joonhunshin4ac60942023-11-15 15:23:39 +00006189 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6190 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 final long identity = Binder.clearCallingIdentity();
6193 try {
6194 if (DBG) {
6195 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6196 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6197 }
6198
6199 IccIoResult response =
6200 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6201 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6202 subId);
6203
6204 if (DBG) {
6205 log("Exchange SIM_IO [R]" + response);
6206 }
6207
6208 byte[] result = null;
6209 int length = 2;
6210 if (response.payload != null) {
6211 length = 2 + response.payload.length;
6212 result = new byte[length];
6213 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6214 } else {
6215 result = new byte[length];
6216 }
6217
6218 result[length - 1] = (byte) response.sw2;
6219 result[length - 2] = (byte) response.sw1;
6220 return result;
6221 } finally {
6222 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006223 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006224 }
6225
Nathan Haroldb3014052017-01-25 15:57:32 -08006226 /**
6227 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6228 * on a particular subscription
6229 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006230 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6231 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006233 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006234 return null;
6235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236
joonhunshin4ac60942023-11-15 15:23:39 +00006237 enforceTelephonyFeatureWithException(callingPackage,
6238 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 final long identity = Binder.clearCallingIdentity();
6241 try {
6242 if (appType != TelephonyManager.APPTYPE_USIM
6243 && appType != TelephonyManager.APPTYPE_SIM) {
6244 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6245 return null;
6246 }
6247 Object response = sendRequest(
6248 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6249 if (response instanceof String[]) {
6250 return (String[]) response;
6251 }
yincheng zhao2737e882019-09-06 17:06:54 -07006252 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006254 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255 } finally {
6256 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006257 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006258 }
6259
yincheng zhao2737e882019-09-06 17:06:54 -07006260 /**
6261 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6262 * subscription.
6263 *
6264 * @param subId the id of the subscription.
6265 * @param appType the uicc app type, must be USIM or SIM.
6266 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6267 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006268 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006269 * @return number of fplmns that is successfully written to the SIM.
6270 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006271 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6272 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6274 mApp, subId, "setForbiddenPlmns");
6275
joonhunshin4ac60942023-11-15 15:23:39 +00006276 enforceTelephonyFeatureWithException(callingPackage,
6277 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6278
yincheng zhao2737e882019-09-06 17:06:54 -07006279 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6280 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6281 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6282 }
6283 if (fplmns == null) {
6284 throw new IllegalArgumentException("Fplmn List provided is null");
6285 }
6286 for (String fplmn : fplmns) {
6287 if (!CellIdentity.isValidPlmn(fplmn)) {
6288 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6289 }
6290 }
6291 final long identity = Binder.clearCallingIdentity();
6292 try {
6293 Object response = sendRequest(
6294 CMD_SET_FORBIDDEN_PLMNS,
6295 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6296 subId);
6297 return (int) response;
6298 } finally {
6299 Binder.restoreCallingIdentity(identity);
6300 }
6301 }
6302
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006303 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006304 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6306 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006307
joonhunshin4ac60942023-11-15 15:23:39 +00006308 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6309 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 final long identity = Binder.clearCallingIdentity();
6312 try {
6313 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6314 if (response.payload == null) {
6315 return "";
6316 }
Evan Charltonc66da362014-05-16 14:06:40 -07006317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 // Append the returned status code to the end of the response payload.
6319 String s = Integer.toHexString(
6320 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6321 s = IccUtils.bytesToHexString(response.payload) + s;
6322 return s;
6323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
Evan Charltonc66da362014-05-16 14:06:40 -07006326 }
6327
Jake Hambye994d462014-02-03 13:10:13 -08006328 /**
6329 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6330 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6331 *
6332 * @param itemID the ID of the item to read
6333 * @return the NV item as a String, or null on error.
6334 */
6335 @Override
6336 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006337 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6339 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006340
6341 final long identity = Binder.clearCallingIdentity();
6342 try {
6343 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006344 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6346 return value;
6347 } finally {
6348 Binder.restoreCallingIdentity(identity);
6349 }
Jake Hambye994d462014-02-03 13:10:13 -08006350 }
6351
6352 /**
6353 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6354 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6355 *
6356 * @param itemID the ID of the item to read
6357 * @param itemValue the value to write, as a String
6358 * @return true on success; false on any failure
6359 */
6360 @Override
6361 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006362 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6364 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365
6366 final long identity = Binder.clearCallingIdentity();
6367 try {
6368 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6369 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006370 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6372 return success;
6373 } finally {
6374 Binder.restoreCallingIdentity(identity);
6375 }
Jake Hambye994d462014-02-03 13:10:13 -08006376 }
6377
6378 /**
6379 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6380 * Used for device configuration by some CDMA operators.
6381 *
6382 * @param preferredRoamingList byte array containing the new PRL
6383 * @return true on success; false on any failure
6384 */
6385 @Override
6386 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6388 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389
6390 final long identity = Binder.clearCallingIdentity();
6391 try {
6392 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6393 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6394 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6395 return success;
6396 } finally {
6397 Binder.restoreCallingIdentity(identity);
6398 }
Jake Hambye994d462014-02-03 13:10:13 -08006399 }
6400
6401 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006402 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006403 * Used for device configuration by some CDMA operators.
6404 *
chen xu6dac5ab2018-10-26 17:39:23 -07006405 * @param slotIndex - device slot.
6406 *
Jake Hambye994d462014-02-03 13:10:13 -08006407 * @return true on success; false on any failure
6408 */
6409 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006410 public boolean resetModemConfig(int slotIndex) {
6411 Phone phone = PhoneFactory.getPhone(slotIndex);
6412 if (phone != null) {
6413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6414 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415
joonhunshin4ac60942023-11-15 15:23:39 +00006416 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6417 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6418
chen xu6dac5ab2018-10-26 17:39:23 -07006419 final long identity = Binder.clearCallingIdentity();
6420 try {
6421 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6422 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6423 return success;
6424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427 }
chen xu6dac5ab2018-10-26 17:39:23 -07006428 return false;
6429 }
6430
6431 /**
6432 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6433 *
6434 * @param slotIndex - device slot.
6435 *
6436 * @return true on success; false on any failure
6437 */
6438 @Override
6439 public boolean rebootModem(int slotIndex) {
6440 Phone phone = PhoneFactory.getPhone(slotIndex);
6441 if (phone != null) {
6442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6443 mApp, phone.getSubId(), "rebootModem");
6444
joonhunshin4ac60942023-11-15 15:23:39 +00006445 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6446 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6447
chen xu6dac5ab2018-10-26 17:39:23 -07006448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6451 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6452 return success;
6453 } finally {
6454 Binder.restoreCallingIdentity(identity);
6455 }
6456 }
6457 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006458 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006459
Brad Ebinger51f743a2017-01-23 13:50:20 -08006460 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006461 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6462 * {@link #disableIms(int)}.
6463 * @param slotIndex device slot.
6464 */
6465 public void resetIms(int slotIndex) {
6466 enforceModifyPermission();
6467
joonhunshin4ac60942023-11-15 15:23:39 +00006468 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6469 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6470
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006471 final long identity = Binder.clearCallingIdentity();
6472 try {
6473 if (mImsResolver == null) {
6474 // may happen if the does not support IMS.
6475 return;
6476 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006477 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006478 } finally {
6479 Binder.restoreCallingIdentity(identity);
6480 }
6481 }
6482
6483 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006484 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6485 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006486 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006487 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006488 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489
6490 final long identity = Binder.clearCallingIdentity();
6491 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006492 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006493 // may happen if the device does not support IMS.
6494 return;
6495 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006496 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006500 }
6501
6502 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006503 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6504 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006505 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006506 public void disableIms(int slotId) {
6507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508
6509 final long identity = Binder.clearCallingIdentity();
6510 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006511 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006512 // may happen if the device does not support IMS.
6513 return;
6514 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006515 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516 } finally {
6517 Binder.restoreCallingIdentity(identity);
6518 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006519 }
6520
6521 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006522 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6523 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006524 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006525 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006526 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528
6529 final long identity = Binder.clearCallingIdentity();
6530 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006531 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006532 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6533 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006534 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006535 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536 } finally {
6537 Binder.restoreCallingIdentity(identity);
6538 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006539 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006540 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006541 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6542 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006543 @Override
6544 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006545 enforceModifyPermission();
6546
6547 final long identity = Binder.clearCallingIdentity();
6548 try {
6549 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006550 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006551 } finally {
6552 Binder.restoreCallingIdentity(identity);
6553 }
6554 }
6555
6556 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006557 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006558 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006559 */
6560 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6561 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562
6563 final long identity = Binder.clearCallingIdentity();
6564 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006565 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006566 // may happen if the device does not support IMS.
6567 return null;
6568 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006569 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 } finally {
6571 Binder.restoreCallingIdentity(identity);
6572 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006573 }
6574
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006575 /**
6576 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006577 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006578 */
6579 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6580 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581
6582 final long identity = Binder.clearCallingIdentity();
6583 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006584 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006585 // may happen if the device does not support IMS.
6586 return null;
6587 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006588 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 } finally {
6590 Binder.restoreCallingIdentity(identity);
6591 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006592 }
6593
Brad Ebinger884c07b2018-02-15 16:17:40 -08006594 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006595 * Sets the ImsService Package Name that Telephony will bind to.
6596 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006597 * @param slotIndex the slot ID that the ImsService should bind for.
6598 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006599 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006600 * @param featureTypes An integer array of feature types associated with a packageName.
6601 * @param packageName The name of the package that the current configuration will be replaced
6602 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006603 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006604 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006605 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6606 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006607 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006609 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611 final long identity = Binder.clearCallingIdentity();
6612 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006613 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006614 // may happen if the device does not support IMS.
6615 return false;
6616 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006617 Map<Integer, String> featureConfig = new HashMap<>();
6618 for (int featureType : featureTypes) {
6619 featureConfig.put(featureType, packageName);
6620 }
6621 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6622 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 } finally {
6624 Binder.restoreCallingIdentity(identity);
6625 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006626 }
6627
6628 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006629 * Clears any carrier ImsService overrides for the slot index specified that were previously
6630 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6631 *
6632 * This should only be used for testing.
6633 *
6634 * @param slotIndex the slot ID that the ImsService should bind for.
6635 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6636 */
6637 @Override
6638 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006639 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6640 "clearCarrierImsServiceOverride");
6641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006642 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006643
6644 final long identity = Binder.clearCallingIdentity();
6645 try {
6646 if (mImsResolver == null) {
6647 // may happen if the device does not support IMS.
6648 return false;
6649 }
6650 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6651 } finally {
6652 Binder.restoreCallingIdentity(identity);
6653 }
6654 }
6655
6656 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006657 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006658 *
6659 * @param slotId The slot that the ImsService is associated with.
6660 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6661 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006662 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006663 * @return the package name of the ImsService configuration.
6664 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006665 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6666 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006667 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006668 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6669 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006670
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006671 final long identity = Binder.clearCallingIdentity();
6672 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006673 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006674 // may happen if the device does not support IMS.
6675 return "";
6676 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006677 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006678 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6679 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680 } finally {
6681 Binder.restoreCallingIdentity(identity);
6682 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006683 }
6684
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006685 /**
6686 * Get the MmTelFeature state associated with the requested subscription id.
6687 * @param subId The subscription that the MmTelFeature is associated with.
6688 * @param callback A callback with an integer containing the
6689 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6690 */
6691 @Override
6692 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6693 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006694 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6695 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6696 "IMS not available on device.");
6697 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006698 final long token = Binder.clearCallingIdentity();
6699 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006700 int slotId = getSlotIndex(subId);
6701 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6702 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6703 + subId + "'");
6704 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6705 }
6706 verifyImsMmTelConfiguredOrThrow(slotId);
6707 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6708 try {
6709 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6710 } catch (RemoteException e) {
6711 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6712 + "Ignore");
6713 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006714 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006715 } catch (ImsException e) {
6716 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006717 } finally {
6718 Binder.restoreCallingIdentity(token);
6719 }
6720 }
6721
Daniel Brightbb5840b2021-01-12 15:48:18 -08006722 /**
6723 * Sets the ims registration state on all valid {@link Phone}s.
6724 */
6725 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006726 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727
6728 final long identity = Binder.clearCallingIdentity();
6729 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006730 // NOTE: Before S, this method only set the default phone.
6731 for (final Phone phone : PhoneFactory.getPhones()) {
6732 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6733 phone.setImsRegistrationState(registered);
6734 }
6735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736 } finally {
6737 Binder.restoreCallingIdentity(identity);
6738 }
Wink Saville36469e72014-06-11 15:17:00 -07006739 }
6740
6741 /**
Stuart Scott54788802015-03-30 13:18:01 -07006742 * Set the network selection mode to automatic.
6743 *
6744 */
6745 @Override
6746 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6748 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749
joonhunshin4ac60942023-11-15 15:23:39 +00006750 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6751 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753 final long identity = Binder.clearCallingIdentity();
6754 try {
shilufc958392020-01-20 11:36:01 -08006755 if (!isActiveSubscription(subId)) {
6756 return;
6757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006759 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6760 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 } finally {
6762 Binder.restoreCallingIdentity(identity);
6763 }
Stuart Scott54788802015-03-30 13:18:01 -07006764 }
6765
Jack Yud10cdd42020-09-28 20:28:01 -07006766 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006767 * Ask the radio to connect to the input network and change selection mode to manual.
6768 *
6769 * @param subId the id of the subscription.
6770 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6771 * the operator to attach to.
6772 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6773 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6774 * normal network selection next time.
6775 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006776 */
6777 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006778 public boolean setNetworkSelectionModeManual(
6779 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6781 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006782
joonhunshin4ac60942023-11-15 15:23:39 +00006783 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6784 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6785
Jack Yu285100e2022-12-02 22:48:35 -08006786 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006787 if (!isActiveSubscription(subId)) {
6788 return false;
6789 }
6790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006791 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006792 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006794 if (DBG) {
6795 log("setNetworkSelectionModeManual: subId: " + subId
6796 + " operator: " + operatorInfo);
6797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006798 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006802 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006803 /**
shilu84f6e8b2019-12-19 13:58:01 -08006804 * Get the manual network selection
6805 *
6806 * @param subId the id of the subscription.
6807 *
6808 * @return the previously saved user selected PLMN
6809 */
6810 @Override
6811 public String getManualNetworkSelectionPlmn(int subId) {
6812 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006813 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6814 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006815
joonhunshin4ac60942023-11-15 15:23:39 +00006816 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6817 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6818
shilu84f6e8b2019-12-19 13:58:01 -08006819 final long identity = Binder.clearCallingIdentity();
6820 try {
6821 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006822 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006823 }
6824
6825 final Phone phone = getPhone(subId);
6826 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006827 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006828 }
6829 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6830 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006831 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006832 } finally {
6833 Binder.restoreCallingIdentity(identity);
6834 }
6835 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006836
6837 /**
6838 * Scans for available networks.
6839 */
6840 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006841 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6842 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6844 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006845 LocationAccessPolicy.LocationPermissionResult locationResult =
6846 LocationAccessPolicy.checkLocationPermission(mApp,
6847 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6848 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006849 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006850 .setCallingPid(Binder.getCallingPid())
6851 .setCallingUid(Binder.getCallingUid())
6852 .setMethod("getCellNetworkScanResults")
6853 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006854 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6855 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006856 .build());
6857 switch (locationResult) {
6858 case DENIED_HARD:
6859 throw new SecurityException("Not allowed to access scan results -- location");
6860 case DENIED_SOFT:
6861 return null;
6862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863
Pengquan Menga1bb6272018-09-06 09:59:22 -07006864 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 try {
6866 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006867 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869 } finally {
6870 Binder.restoreCallingIdentity(identity);
6871 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006872 }
6873
6874 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006875 * Get the call forwarding info, given the call forwarding reason.
6876 */
6877 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006878 public void getCallForwarding(int subId, int callForwardingReason,
6879 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006880 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006881
6882 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6883 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6884
Shuo Qian4a594052020-01-23 11:59:30 -08006885 long identity = Binder.clearCallingIdentity();
6886 try {
6887 if (DBG) {
6888 log("getCallForwarding: subId " + subId
6889 + " callForwardingReason" + callForwardingReason);
6890 }
Hall Liu27d24262020-09-18 19:04:59 -07006891
6892 Phone phone = getPhone(subId);
6893 if (phone == null) {
6894 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006895 callback.onError(
6896 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006897 } catch (RemoteException e) {
6898 // ignore
6899 }
6900 return;
6901 }
6902
6903 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6904 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6905 @Override
6906 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6907 try {
6908 callback.onCallForwardingInfoAvailable(info);
6909 } catch (RemoteException e) {
6910 // ignore
6911 }
6912 }
6913
6914 @Override
6915 public void onError(int error) {
6916 try {
6917 callback.onError(error);
6918 } catch (RemoteException e) {
6919 // ignore
6920 }
6921 }
6922 });
6923 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006924 } finally {
6925 Binder.restoreCallingIdentity(identity);
6926 }
6927 }
6928
6929 /**
6930 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6931 * reason, the number to forward, and the timeout before the forwarding is attempted.
6932 */
6933 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006934 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6935 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006936 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006937
6938 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6939 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6940
Shuo Qian4a594052020-01-23 11:59:30 -08006941 long identity = Binder.clearCallingIdentity();
6942 try {
6943 if (DBG) {
6944 log("setCallForwarding: subId " + subId
6945 + " callForwardingInfo" + callForwardingInfo);
6946 }
Hall Liu27d24262020-09-18 19:04:59 -07006947
6948 Phone phone = getPhone(subId);
6949 if (phone == null) {
6950 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006951 callback.accept(
6952 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006953 } catch (RemoteException e) {
6954 // ignore
6955 }
6956 return;
6957 }
6958
6959 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6960 FunctionalUtils.ignoreRemoteException(callback::accept));
6961
6962 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006963 } finally {
6964 Binder.restoreCallingIdentity(identity);
6965 }
6966 }
6967
6968 /**
Hall Liu27d24262020-09-18 19:04:59 -07006969 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006970 */
6971 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006972 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006973 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00006974
6975 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6976 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
6977
Shuo Qian4a594052020-01-23 11:59:30 -08006978 long identity = Binder.clearCallingIdentity();
6979 try {
Hall Liu27d24262020-09-18 19:04:59 -07006980 Phone phone = getPhone(subId);
6981 if (phone == null) {
6982 try {
6983 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6984 } catch (RemoteException e) {
6985 // ignore
6986 }
6987 return;
6988 }
SongFerngWang0e767992021-03-31 22:08:45 +08006989 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6990 PersistableBundle c = configManager.getConfigForSubId(subId);
6991 boolean requireUssd = c.getBoolean(
6992 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006993
Shuo Qian4a594052020-01-23 11:59:30 -08006994 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006995 if (requireUssd) {
6996 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6997 getSubscriptionCarrierId(subId));
6998 String newUssdCommand = "";
6999 try {
7000 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007001 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007002 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7003 } catch (NullPointerException e) {
7004 loge("Failed to generate USSD number" + e);
7005 }
7006 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7007 mMainThreadHandler, callback, carrierXmlParser,
7008 CarrierXmlParser.SsEntry.SSAction.QUERY);
7009 final String ussdCommand = newUssdCommand;
7010 Executors.newSingleThreadExecutor().execute(() -> {
7011 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7012 });
7013 } else {
7014 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7015 callback::accept);
7016 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7017 }
Shuo Qian4a594052020-01-23 11:59:30 -08007018 } finally {
7019 Binder.restoreCallingIdentity(identity);
7020 }
7021 }
7022
7023 /**
Hall Liu27d24262020-09-18 19:04:59 -07007024 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007025 */
7026 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007027 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007028 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007029
7030 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7031 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7032
Shuo Qian4a594052020-01-23 11:59:30 -08007033 long identity = Binder.clearCallingIdentity();
7034 try {
Hall Liu27d24262020-09-18 19:04:59 -07007035 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7036
7037 Phone phone = getPhone(subId);
7038 if (phone == null) {
7039 try {
7040 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7041 } catch (RemoteException e) {
7042 // ignore
7043 }
7044 return;
7045 }
7046
SongFerngWang0e767992021-03-31 22:08:45 +08007047 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7048 PersistableBundle c = configManager.getConfigForSubId(subId);
7049 boolean requireUssd = c.getBoolean(
7050 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007051
SongFerngWang0e767992021-03-31 22:08:45 +08007052 if (DBG) log("getCallWaitingStatus: subId " + subId);
7053 if (requireUssd) {
7054 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7055 getSubscriptionCarrierId(subId));
7056 CarrierXmlParser.SsEntry.SSAction ssAction =
7057 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7058 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7059 String newUssdCommand = "";
7060 try {
7061 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007062 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007063 .makeCommand(ssAction, null);
7064 } catch (NullPointerException e) {
7065 loge("Failed to generate USSD number" + e);
7066 }
7067 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7068 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7069 final String ussdCommand = newUssdCommand;
7070 Executors.newSingleThreadExecutor().execute(() -> {
7071 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7072 });
7073 } else {
7074 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7075 FunctionalUtils.ignoreRemoteException(callback::accept));
7076
7077 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7078 }
Shuo Qian4a594052020-01-23 11:59:30 -08007079 } finally {
7080 Binder.restoreCallingIdentity(identity);
7081 }
7082 }
7083
7084 /**
yinxub1bed742017-04-17 11:45:04 -07007085 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007086 *
yinxub1bed742017-04-17 11:45:04 -07007087 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007088 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7089 * location related information which will be sent if the caller already possess
7090 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007091 * @param request contains the radio access networks with bands/channels to scan
7092 * @param messenger callback messenger for scan results or errors
7093 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007094 * @return the id of the requested scan which can be used to stop the scan.
7095 */
7096 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007097 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7098 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007099 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7101 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007102 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007103 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7104 if (!renounceFineLocationAccess) {
7105 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007106 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7107 .setCallingPackage(callingPackage)
7108 .setCallingFeatureId(callingFeatureId)
7109 .setCallingPid(Binder.getCallingPid())
7110 .setCallingUid(Binder.getCallingUid())
7111 .setMethod("requestNetworkScan")
7112 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7113 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7114 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7115 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007116 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007117 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007118 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7119 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007120 if (e != null) {
7121 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7122 throw e;
7123 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007124 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007125 return TelephonyScanManager.INVALID_SCAN_ID;
7126 }
7127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 }
joonhunshin4ac60942023-11-15 15:23:39 +00007129
7130 enforceTelephonyFeatureWithException(callingPackage,
7131 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7132
Hall Liu912dfd32019-04-25 14:02:26 -07007133 int callingUid = Binder.getCallingUid();
7134 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007135 final long identity = Binder.clearCallingIdentity();
7136 try {
7137 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007138 renounceFineLocationAccess, request, messenger, binder,
7139 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007140 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
yinxu504e1392017-04-12 16:03:22 -07007144 }
7145
Hall Liub2ac8ef2019-02-28 15:56:23 -08007146 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007147 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007148 boolean hasCarrierPriv;
7149 final long identity = Binder.clearCallingIdentity();
7150 try {
7151 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7152 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7153 } finally {
7154 Binder.restoreCallingIdentity(identity);
7155 }
Hall Liu558027f2019-05-15 19:14:05 -07007156 boolean hasNetworkScanPermission =
7157 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007158 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007159
7160 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7161 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7162 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007163 }
7164
7165 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7166 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007167 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7168 return new SecurityException("Specific channels must not be"
7169 + " scanned without location access.");
7170 }
7171 }
7172 }
7173
Hall Liub2ac8ef2019-02-28 15:56:23 -08007174 return null;
7175 }
7176
yinxu504e1392017-04-12 16:03:22 -07007177 /**
7178 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007179 *
7180 * @param subId id of the subscription
7181 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007182 */
7183 @Override
7184 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7186 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187
Hall Liu912dfd32019-04-25 14:02:26 -07007188 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 final long identity = Binder.clearCallingIdentity();
7190 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007191 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192 } finally {
7193 Binder.restoreCallingIdentity(identity);
7194 }
yinxu504e1392017-04-12 16:03:22 -07007195 }
7196
7197 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007198 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007199 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007200 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007201 */
7202 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007203 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007204 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007205 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007206 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207
joonhunshin4ac60942023-11-15 15:23:39 +00007208 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7209 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 final long identity = Binder.clearCallingIdentity();
7212 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007213 if (DBG) log("getAllowedNetworkTypesBitmask");
7214 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7215 int networkTypesBitmask = (result != null ? result[0] : -1);
7216 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7217 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007218 } finally {
7219 Binder.restoreCallingIdentity(identity);
7220 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007221 }
7222
7223 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007224 * Get the allowed network types for certain reason.
7225 *
7226 * @param subId the id of the subscription.
7227 * @param reason the reason the allowed network type change is taking place
7228 * @return the allowed network types.
7229 */
7230 @Override
7231 public long getAllowedNetworkTypesForReason(int subId,
7232 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007233 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007234 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007235
7236 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7237 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesForReason");
7238
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007239 final long identity = Binder.clearCallingIdentity();
7240 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007241 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007242 } finally {
7243 Binder.restoreCallingIdentity(identity);
7244 }
7245 }
7246
7247 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007248 * Enable/Disable E-UTRA-NR Dual Connectivity
7249 * @param subId subscription id of the sim card
7250 * @param nrDualConnectivityState expected NR dual connectivity state
7251 * This can be passed following states
7252 * <ol>
7253 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7254 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7255 * <li>Disable NR dual connectivity and force secondary cell to be released
7256 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7257 * </ol>
7258 * @return operation result.
7259 */
7260 @Override
7261 public int setNrDualConnectivityState(int subId,
7262 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7264 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007265 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007266 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7267 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7268 }
7269
Sooraj Sasindran37444802020-08-11 10:40:43 -07007270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7271 final long identity = Binder.clearCallingIdentity();
7272 try {
7273 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7274 nrDualConnectivityState, subId,
7275 workSource);
7276 if (DBG) log("enableNRDualConnectivity result: " + result);
7277 return result;
7278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280 }
7281 }
7282
7283 /**
7284 * Is E-UTRA-NR Dual Connectivity enabled
7285 * @return true if dual connectivity is enabled else false
7286 */
7287 @Override
7288 public boolean isNrDualConnectivityEnabled(int subId) {
7289 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007290 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007291 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007292 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007293 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7294 return false;
7295 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7297 final long identity = Binder.clearCallingIdentity();
7298 try {
7299 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7300 null, subId, workSource);
7301 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7302 return isEnabled;
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
7305 }
7306 }
7307
7308 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007309 * Set the allowed network types of the device and
7310 * provide the reason triggering the allowed network change.
7311 *
7312 * @param subId the id of the subscription.
7313 * @param reason the reason the allowed network type change is taking place
7314 * @param allowedNetworkTypes the allowed network types.
7315 * @return true on success; false on any failure.
7316 */
7317 @Override
7318 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007319 @TelephonyManager.AllowedNetworkTypesReason int reason,
7320 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7322 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007323 // If the caller only has carrier privileges, then they should not be able to override
7324 // any network types which were set for security reasons.
7325 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7326 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007327 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007328 throw new SecurityException(
7329 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007330 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007331 }
joonhunshin4ac60942023-11-15 15:23:39 +00007332
7333 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7334 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7335
SongFerngWang3ef3e072020-12-21 16:41:52 +08007336 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007337 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007338 return false;
7339 }
7340 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7341 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007342 return false;
7343 }
7344
Jack Yu5b494332023-01-23 18:18:04 +00007345 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7346 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007347
Jack Yue37dd262022-12-16 11:53:37 -08007348 Phone phone = getPhone(subId);
7349 if (phone == null) {
7350 return false;
7351 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007352
Jack Yue37dd262022-12-16 11:53:37 -08007353 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007354 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007355 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007356 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007357
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007358 final long identity = Binder.clearCallingIdentity();
7359 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007360 Boolean success = (Boolean) sendRequest(
7361 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7362 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7363
7364 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7365 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
7369 }
7370
7371 /**
Miaoa84611c2019-03-15 09:21:10 +08007372 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007373 *
Miaoa84611c2019-03-15 09:21:10 +08007374 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007375 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007376 * @hide
7377 */
7378 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007379 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007380 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007381
7382 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7383 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007386 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 try {
Miaoa84611c2019-03-15 09:21:10 +08007388 if (phone != null) {
7389 return phone.hasMatchedTetherApnSetting();
7390 } else {
7391 return false;
7392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 } finally {
7394 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007395 }
Junda Liu475951f2014-11-07 16:45:03 -08007396 }
7397
7398 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007399 * Get the user enabled state of Mobile Data.
7400 *
7401 * TODO: remove and use isUserDataEnabled.
7402 * This can't be removed now because some vendor codes
7403 * calls through ITelephony directly while they should
7404 * use TelephonyManager.
7405 *
7406 * @return true on enabled
7407 */
7408 @Override
7409 public boolean getDataEnabled(int subId) {
7410 return isUserDataEnabled(subId);
7411 }
7412
7413 /**
7414 * Get whether mobile data is enabled per user setting.
7415 *
7416 * There are other factors deciding whether mobile data is actually enabled, but they are
7417 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007418 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007419 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7420 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007421 *
7422 * @return {@code true} if data is enabled else {@code false}
7423 */
7424 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007425 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007426 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007427 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007428 try {
7429 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7430 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007431 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007432 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7433 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007434 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007436 mApp, subId, functionName);
7437
Robert Greenwalt646120a2014-05-23 11:54:03 -07007438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439
7440 final long identity = Binder.clearCallingIdentity();
7441 try {
Jack Yu285100e2022-12-02 22:48:35 -08007442 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7444 Phone phone = PhoneFactory.getPhone(phoneId);
7445 if (phone != null) {
7446 boolean retVal = phone.isUserDataEnabled();
7447 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7448 return retVal;
7449 } else {
7450 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7451 return false;
7452 }
7453 } finally {
7454 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007455 }
7456 }
7457
7458 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007459 * Checks if the device is capable of mobile data by considering whether whether the
7460 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7461 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007462 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007463 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007464 */
7465 @Override
7466 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007467 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007468 try {
7469 try {
7470 mApp.enforceCallingOrSelfPermission(
7471 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007472 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007473 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007474 try {
7475 mApp.enforceCallingOrSelfPermission(
7476 android.Manifest.permission.READ_PHONE_STATE,
7477 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007478 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007479 mApp.enforceCallingOrSelfPermission(
7480 permission.READ_BASIC_PHONE_STATE, functionName);
7481 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007482 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007483 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007484 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486
joonhunshin4ac60942023-11-15 15:23:39 +00007487 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7488 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 final long identity = Binder.clearCallingIdentity();
7491 try {
Jack Yu285100e2022-12-02 22:48:35 -08007492 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 Phone phone = PhoneFactory.getPhone(phoneId);
7494 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007495 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007496 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 return retVal;
7498 } else {
7499 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7500 return false;
7501 }
7502 } finally {
7503 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007504 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007505 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007506
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007507 /**
7508 * Check if data is enabled for a specific reason
7509 * @param subId Subscription index
7510 * @param reason the reason the data enable change is taking place
7511 * @return {@code true} if the overall data is enabled; {@code false} if not.
7512 */
7513 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007514 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007515 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007516 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007517 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007518 try {
7519 mApp.enforceCallingOrSelfPermission(
7520 android.Manifest.permission.ACCESS_NETWORK_STATE,
7521 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007522 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007523 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7524 functionName);
7525 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007526 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007527 try {
7528 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007529 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007530 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007532 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007533 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007534 }
7535
joonhunshin4ac60942023-11-15 15:23:39 +00007536 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7537 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007538
7539 final long identity = Binder.clearCallingIdentity();
7540 try {
Jack Yu285100e2022-12-02 22:48:35 -08007541 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007542 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007543 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007544 + " reason=" + reason);
7545 }
7546 Phone phone = PhoneFactory.getPhone(phoneId);
7547 if (phone != null) {
7548 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007549 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007550 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007551 return retVal;
7552 } else {
7553 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007554 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007555 + subId + " retVal=false");
7556 }
7557 return false;
7558 }
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
7561 }
7562 }
7563
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007564 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007565 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007566 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7567 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7568
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007569 // No permission needed; this only lets the caller inspect their own status.
7570 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007571 }
Junda Liu29340342014-07-10 15:23:27 -07007572
7573 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007574 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007575 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007576
7577 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7578 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7579
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007580 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7581 }
7582
7583 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7584 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007585 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007586 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007587 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7588 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007589 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7590 if (cpt == null) {
7591 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007592 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7593 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007594 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007595 }
7596
7597 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007598 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007599 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007600
7601 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7602 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7603
chen xuf7e9fe82019-05-09 19:31:02 -07007604 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007605 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007606 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007607 Phone phone = getPhone(subId);
7608 if (phone == null) {
7609 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7610 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7611 }
7612 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7613 if (cpt == null) {
7614 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007615 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7616 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007617 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007618 }
7619
7620 @Override
7621 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007622 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007623
7624 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7625 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7626 "checkCarrierPrivilegesForPackageAnyPhone");
7627
Rambo Wange7209ce2022-02-23 13:41:02 -08007628 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7629 }
7630
7631 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007632 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007633 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007634 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007635 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007636 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7637 Phone phone = PhoneFactory.getPhone(phoneId);
7638 if (phone == null) {
7639 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007640 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007641 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7642 if (cpt == null) {
7643 continue;
7644 }
7645 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007646 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7647 break;
7648 }
7649 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007650 return result;
Junda Liu29340342014-07-10 15:23:27 -07007651 }
Derek Tan89e89d42014-07-08 17:00:10 -07007652
7653 @Override
Junda Liue64de782015-04-16 17:19:16 -07007654 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007655 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007656
7657 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7658 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7659 "getCarrierPackageNamesForIntentAndPhone");
7660
Rambo Wang8a247eb2022-02-08 21:11:18 +00007661 Phone phone = PhoneFactory.getPhone(phoneId);
7662 if (phone == null) {
7663 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007664 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007665 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7666 if (cpt == null) {
7667 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007668 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007669 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007670 }
7671
Amith Yamasani6e118872016-02-19 12:53:51 -08007672 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007673 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007674 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007675 Phone phone = PhoneFactory.getPhone(phoneId);
7676 if (phone == null) {
7677 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007678 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007679 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7680 if (cpt == null) {
7681 return Collections.emptyList();
7682 }
7683 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007684 }
7685
chen xuf7e9fe82019-05-09 19:31:02 -07007686 @Override
7687 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007688 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007689
7690 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7691 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7692 "getPackagesWithCarrierPrivilegesForAllPhones");
7693
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007694 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007695 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007696 try {
7697 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7698 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7699 }
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007702 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007703 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007704 }
7705
Rambo Wang6812ffb2022-03-15 16:54:17 -07007706 @Override
7707 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7708 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7709
joonhunshin4ac60942023-11-15 15:23:39 +00007710 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7711 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7712 "getCarrierServicePackageNameForLogicalSlot");
7713
Rambo Wang6812ffb2022-03-15 16:54:17 -07007714 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7715 if (phone == null) {
7716 return null;
7717 }
7718 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7719 if (cpt == null) {
7720 return null;
7721 }
7722 return cpt.getCarrierServicePackageName();
7723 }
7724
Wink Savilleb564aae2014-10-23 10:18:09 -07007725 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007726 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007727 UiccPort port = phone == null ? null : phone.getUiccPort();
7728 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007729 return null;
7730 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007731 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007732 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007733 return null;
7734 }
7735 return iccId;
7736 }
7737
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007738 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007739 public void setCallComposerStatus(int subId, int status) {
7740 enforceModifyPermission();
7741
joonhunshin4ac60942023-11-15 15:23:39 +00007742 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7743 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7744
Shuo Qiane4e11672020-12-15 22:15:33 -08007745 final long identity = Binder.clearCallingIdentity();
7746 try {
7747 Phone phone = getPhone(subId);
7748 if (phone != null) {
7749 Phone defaultPhone = phone.getImsPhone();
7750 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7751 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7752 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007753 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7754 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007755 }
7756 }
Shuo Qian284ae752020-12-22 19:10:14 -08007757 } catch (ImsException e) {
7758 throw new ServiceSpecificException(e.getCode());
7759 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007760 Binder.restoreCallingIdentity(identity);
7761 }
7762 }
7763
7764 @Override
7765 public int getCallComposerStatus(int subId) {
7766 enforceReadPrivilegedPermission("getCallComposerStatus");
7767
joonhunshin4ac60942023-11-15 15:23:39 +00007768 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7769 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7770
Shuo Qiane4e11672020-12-15 22:15:33 -08007771 final long identity = Binder.clearCallingIdentity();
7772 try {
7773 Phone phone = getPhone(subId);
7774 if (phone != null) {
7775 Phone defaultPhone = phone.getImsPhone();
7776 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7777 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7778 return imsPhone.getCallComposerStatus();
7779 }
7780 }
7781 } finally {
7782 Binder.restoreCallingIdentity(identity);
7783 }
7784 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7785 }
7786
7787 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007788 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7789 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007790 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007791 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007792
joonhunshin4ac60942023-11-15 15:23:39 +00007793 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7794 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7795 "setLine1NumberForDisplayForSubscriber");
7796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 final long identity = Binder.clearCallingIdentity();
7798 try {
7799 final String iccId = getIccId(subId);
7800 final Phone phone = getPhone(subId);
7801 if (phone == null) {
7802 return false;
7803 }
7804 final String subscriberId = phone.getSubscriberId();
7805
7806 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007807 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 + subscriberId + " to " + number);
7809 }
7810
7811 if (TextUtils.isEmpty(iccId)) {
7812 return false;
7813 }
7814
7815 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7816
7817 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7818 if (alphaTag == null) {
7819 editor.remove(alphaTagPrefKey);
7820 } else {
7821 editor.putString(alphaTagPrefKey, alphaTag);
7822 }
7823
7824 // Record both the line number and IMSI for this ICCID, since we need to
7825 // track all merged IMSIs based on line number
7826 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7827 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7828 if (number == null) {
7829 editor.remove(numberPrefKey);
7830 editor.remove(subscriberPrefKey);
7831 } else {
7832 editor.putString(numberPrefKey, number);
7833 editor.putString(subscriberPrefKey, subscriberId);
7834 }
7835
7836 editor.commit();
7837 return true;
7838 } finally {
7839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007840 }
Derek Tan7226c842014-07-02 17:42:23 -07007841 }
7842
7843 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007844 public String getLine1NumberForDisplay(int subId, String callingPackage,
7845 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007846 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007847 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007848 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007849 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007850 return null;
7851 }
Derek Tan97ebb422014-09-05 16:55:38 -07007852
joonhunshin4ac60942023-11-15 15:23:39 +00007853 enforceTelephonyFeatureWithException(callingPackage,
7854 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7855
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007856 final long identity = Binder.clearCallingIdentity();
7857 try {
7858 String iccId = getIccId(subId);
7859 if (iccId != null) {
7860 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7861 if (DBG_MERGE) {
7862 log("getLine1NumberForDisplay returning "
7863 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7864 }
7865 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007867 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7868 return null;
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007871 }
Derek Tan7226c842014-07-02 17:42:23 -07007872 }
7873
7874 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007875 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7876 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007878 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007879 return null;
7880 }
Derek Tan97ebb422014-09-05 16:55:38 -07007881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882 final long identity = Binder.clearCallingIdentity();
7883 try {
7884 String iccId = getIccId(subId);
7885 if (iccId != null) {
7886 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7887 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7888 }
7889 return null;
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007892 }
Derek Tan7226c842014-07-02 17:42:23 -07007893 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007894
7895 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007896 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7897 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007898 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7899 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007901 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007902 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007903 return null;
7904 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007905
Jordan Liub49b04b2019-05-06 14:45:15 -07007906 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7907 // the process, where TelephonyManager was instantiated.
7908 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007909 final long identity = Binder.clearCallingIdentity();
7910 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007911 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 final TelephonyManager tele = TelephonyManager.from(context);
7913 final SubscriptionManager sub = SubscriptionManager.from(context);
7914
7915 // Figure out what subscribers are currently active
7916 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917
Jordan Liub49b04b2019-05-06 14:45:15 -07007918 // Only consider subs which match the current subId
7919 // This logic can be simplified. See b/131189269 for progress.
7920 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007921 activeSubscriberIds.add(tele.getSubscriberId(subId));
7922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923
7924 // First pass, find a number override for an active subscriber
7925 String mergeNumber = null;
7926 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7927 for (String key : prefs.keySet()) {
7928 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7929 final String subscriberId = (String) prefs.get(key);
7930 if (activeSubscriberIds.contains(subscriberId)) {
7931 final String iccId = key.substring(
7932 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7933 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7934 mergeNumber = (String) prefs.get(numberKey);
7935 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007936 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 + " for active subscriber " + subscriberId);
7938 }
7939 if (!TextUtils.isEmpty(mergeNumber)) {
7940 break;
7941 }
7942 }
7943 }
7944 }
7945
7946 // Shortcut when no active merged subscribers
7947 if (TextUtils.isEmpty(mergeNumber)) {
7948 return null;
7949 }
7950
7951 // Second pass, find all subscribers under that line override
7952 final ArraySet<String> result = new ArraySet<>();
7953 for (String key : prefs.keySet()) {
7954 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7955 final String number = (String) prefs.get(key);
7956 if (mergeNumber.equals(number)) {
7957 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7958 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7959 final String subscriberId = (String) prefs.get(subscriberKey);
7960 if (!TextUtils.isEmpty(subscriberId)) {
7961 result.add(subscriberId);
7962 }
7963 }
7964 }
7965 }
7966
7967 final String[] resultArray = result.toArray(new String[result.size()]);
7968 Arrays.sort(resultArray);
7969 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007970 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007971 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7972 }
7973 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007974 } finally {
7975 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007976 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007977 }
7978
7979 @Override
zoey chen38003472019-12-13 17:16:31 +08007980 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7981 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007982
joonhunshin4ac60942023-11-15 15:23:39 +00007983 enforceTelephonyFeatureWithException(callingPackage,
7984 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
7985
Malcolm Chen6ca97372019-07-01 16:28:21 -07007986 final long identity = Binder.clearCallingIdentity();
7987 try {
7988 final TelephonyManager telephonyManager = mApp.getSystemService(
7989 TelephonyManager.class);
7990 String subscriberId = telephonyManager.getSubscriberId(subId);
7991 if (subscriberId == null) {
7992 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007993 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007994 + subId);
7995 }
7996 return null;
7997 }
7998
Jack Yu3beaf9d2023-04-14 09:17:27 -07007999 final SubscriptionInfo info = getSubscriptionManagerService()
8000 .getSubscriptionInfo(subId);
8001 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008002 // If it doesn't belong to any group, return just subscriberId of itself.
8003 if (groupUuid == null) {
8004 return new String[]{subscriberId};
8005 }
8006
8007 // Get all subscriberIds from the group.
8008 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008009 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8010 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8011 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008012 for (SubscriptionInfo subInfo : groupInfos) {
8013 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8014 if (subscriberId != null) {
8015 mergedSubscriberIds.add(subscriberId);
8016 }
8017 }
8018
8019 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8020 } finally {
8021 Binder.restoreCallingIdentity(identity);
8022
8023 }
8024 }
8025
8026 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008027 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008028 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008029 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008030
joonhunshin4ac60942023-11-15 15:23:39 +00008031 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8032 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008034 final long identity = Binder.clearCallingIdentity();
8035 try {
8036 final Phone phone = getPhone(subId);
8037 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
8040 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008041 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008042
8043 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008044 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008045 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8046 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008047 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8048 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049
8050 final long identity = Binder.clearCallingIdentity();
8051 try {
8052 final Phone phone = getPhone(subId);
8053 if (phone == null) {
8054 return false;
8055 }
8056 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8057 cdmaNonRoamingList);
8058 } finally {
8059 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008060 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008061 }
8062
8063 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008064 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008065 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008066 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008067 if (phone == null) {
8068 return raf;
8069 }
8070
Shuo Qiandee53402020-05-29 14:08:15 -07008071 try {
8072 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008073 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008074 mApp, phone.getSubId(), "getRadioAccessFamily");
8075 } catch (SecurityException e) {
8076 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8077 throw e;
8078 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008079
joonhunshin4ac60942023-11-15 15:23:39 +00008080 enforceTelephonyFeatureWithException(callingPackage,
8081 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 final long identity = Binder.clearCallingIdentity();
8084 try {
chen xub97461a2018-10-26 14:17:57 -07008085 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086 } finally {
8087 Binder.restoreCallingIdentity(identity);
8088 }
chen xub97461a2018-10-26 14:17:57 -07008089 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008090 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008091
8092 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008093 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008094 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008095 try {
8096 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8097 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008098 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008099 }
8100 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008101 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008102 }
joonhunshin4ac60942023-11-15 15:23:39 +00008103
8104 enforceTelephonyFeatureWithException(callingPackage,
8105 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8106
Hall Liu82694d52020-12-11 18:22:04 -08008107 RoleManager rm = mApp.getSystemService(RoleManager.class);
8108 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8109 if (!dialerRoleHolders.contains(callingPackage)) {
8110 throw new SecurityException("App must be the dialer role holder to"
8111 + " upload a call composer pic");
8112 }
8113
8114 Executors.newSingleThreadExecutor().execute(() -> {
8115 ByteArrayOutputStream output = new ByteArrayOutputStream(
8116 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8117 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8118 boolean readUntilEnd = false;
8119 int totalBytesRead = 0;
8120 byte[] buffer = new byte[16 * 1024];
8121 while (true) {
8122 int numRead;
8123 try {
8124 numRead = input.read(buffer);
8125 } catch (IOException e) {
8126 try {
8127 fd.checkError();
8128 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8129 null);
8130 } catch (IOException e1) {
8131 // This means that the other side closed explicitly with an error. If this
8132 // happens, log and ignore.
8133 loge("Remote end of call composer picture pipe closed: " + e1);
8134 }
8135 break;
8136 }
8137 if (numRead == -1) {
8138 readUntilEnd = true;
8139 break;
8140 }
8141 totalBytesRead += numRead;
8142 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8143 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8144 try {
8145 input.close();
8146 } catch (IOException e) {
8147 // ignore
8148 }
8149 break;
8150 }
8151 output.write(buffer, 0, numRead);
8152 }
8153 // Generally, the remote end will close the file descriptors. The only case where we
8154 // close is above, where the picture size is too big.
8155
8156 try {
8157 fd.checkError();
8158 } catch (IOException e) {
8159 loge("Remote end for call composer closed with an error: " + e);
8160 return;
8161 }
8162
Hall Liuaa4211e2021-01-20 15:43:39 -08008163 if (!readUntilEnd) {
8164 loge("Did not finish reading entire image; aborting");
8165 return;
8166 }
Hall Liu82694d52020-12-11 18:22:04 -08008167
Hall Liuaa4211e2021-01-20 15:43:39 -08008168 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8169 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8170 new CallComposerPictureTransfer.Factory() {},
8171 imageData,
8172 (result) -> {
8173 if (result.first != null) {
8174 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8175 Bundle outputResult = new Bundle();
8176 outputResult.putParcelable(
8177 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8178 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8179 outputResult);
8180 } else {
8181 callback.send(result.second, null);
8182 }
8183 }
8184 );
Hall Liu82694d52020-12-11 18:22:04 -08008185 });
8186 }
8187
8188 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008189 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008190 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008191 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008192
joonhunshin4ac60942023-11-15 15:23:39 +00008193 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8194 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196 final long identity = Binder.clearCallingIdentity();
8197 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008198 ImsManager.getInstance(defaultPhone.getContext(),
8199 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200 } finally {
8201 Binder.restoreCallingIdentity(identity);
8202 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008203 }
8204
8205 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008206 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008207 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8209 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008210 return false;
8211 }
Svet Ganovb320e182015-04-16 12:30:10 -07008212
joonhunshin4ac60942023-11-15 15:23:39 +00008213 enforceTelephonyFeatureWithException(callingPackage,
8214 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008216 final long identity = Binder.clearCallingIdentity();
8217 try {
8218 // Check the user preference and the system-level IMS setting. Even if the user has
8219 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8220 // In the long run, we may instead need to check if there exists a connection service
8221 // which can support video calling.
8222 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008223 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 return imsManager.isVtEnabledByPlatform()
8225 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8226 && imsManager.isVtEnabledByUser();
8227 } finally {
8228 Binder.restoreCallingIdentity(identity);
8229 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008230 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008231
Andrew Leea1239f22015-03-02 17:44:07 -08008232 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008233 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8234 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008236 mApp, subId, callingPackage, callingFeatureId,
8237 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 return false;
8239 }
8240
joonhunshin4ac60942023-11-15 15:23:39 +00008241 enforceTelephonyFeatureWithException(callingPackage,
8242 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 final long identity = Binder.clearCallingIdentity();
8245 try {
8246 CarrierConfigManager configManager =
8247 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008248 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8250 } finally {
8251 Binder.restoreCallingIdentity(identity);
8252 }
Andrew Leea1239f22015-03-02 17:44:07 -08008253 }
8254
8255 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008256 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008258 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008259 return false;
8260 }
8261
joonhunshin4ac60942023-11-15 15:23:39 +00008262 enforceTelephonyFeatureWithException(callingPackage,
8263 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265 final long identity = Binder.clearCallingIdentity();
8266 try {
8267 CarrierConfigManager configManager =
8268 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008269 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8271 } finally {
8272 Binder.restoreCallingIdentity(identity);
8273 }
Andrew Leea1239f22015-03-02 17:44:07 -08008274 }
8275
Andrew Lee9431b832015-03-09 18:46:45 -07008276 @Override
8277 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008278 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008279 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008280 }
8281
8282 @Override
8283 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008284 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8285 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287 final long identity = Binder.clearCallingIdentity();
8288 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008289 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008290 } finally {
8291 Binder.restoreCallingIdentity(identity);
8292 }
Andrew Lee9431b832015-03-09 18:46:45 -07008293 }
8294
Hall Liuf6668912018-10-31 17:05:23 -07008295 /**
8296 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8297 * support for the feature and device firmware support.
8298 *
8299 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8300 */
8301 @Override
8302 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008303 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8304 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008306 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008307 final Phone phone = getPhone(subscriptionId);
8308 if (phone == null) {
8309 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8310 return false;
8311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008313 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008315 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8316 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8317 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008318 return isCarrierSupported && isDeviceSupported;
8319 } finally {
8320 Binder.restoreCallingIdentity(identity);
8321 }
Hall Liu98187582018-01-22 19:15:32 -08008322 }
8323
Hall Liuf6668912018-10-31 17:05:23 -07008324 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008325 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8326 * RTT setting, will return true if the device and carrier both support RTT.
8327 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008328 */
8329 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008330 final long identity = Binder.clearCallingIdentity();
8331 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008332 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8333 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8334 return false;
8335 }
8336 }
8337
Hall Liu5bab75c2019-12-11 23:58:20 +00008338 boolean isRttSupported = isRttSupported(subscriptionId);
8339 boolean isUserRttSettingOn = Settings.Secure.getInt(
8340 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8341 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8342 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8343 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008347 }
8348
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008349 @Deprecated
8350 @Override
8351 public String getDeviceId(String callingPackage) {
8352 return getDeviceIdWithFeature(callingPackage, null);
8353 }
8354
Sanket Padawe7310cc72015-01-14 09:53:20 -08008355 /**
8356 * Returns the unique device ID of phone, for example, the IMEI for
8357 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8358 *
8359 * <p>Requires Permission:
8360 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8361 */
8362 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008363 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008364 try {
8365 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8366 } catch (SecurityException se) {
8367 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8368 throw new SecurityException("Package " + callingPackage + " does not belong to "
8369 + Binder.getCallingUid());
8370 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008371 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008372 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008373 return null;
8374 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008375 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008376 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008377 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008378 return null;
8379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008380
8381 final long identity = Binder.clearCallingIdentity();
8382 try {
8383 return phone.getDeviceId();
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008387 }
8388
Ping Sunc67b7c22016-03-02 19:16:45 +08008389 /**
8390 * {@hide}
8391 * Returns the IMS Registration Status on a particular subid
8392 *
8393 * @param subId
8394 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008395 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008396 Phone phone = getPhone(subId);
8397 if (phone != null) {
8398 return phone.isImsRegistered();
8399 } else {
8400 return false;
8401 }
8402 }
8403
Santos Cordon7a1885b2015-02-03 11:15:19 -08008404 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008405 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008406 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008408 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008409 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8410 }
8411 final long identity = Binder.clearCallingIdentity();
8412 try {
8413 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8414 } finally {
8415 Binder.restoreCallingIdentity(identity);
8416 }
8417 }
8418
8419 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008420 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008421 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008422 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008423 mApp,
8424 subscriptionId,
8425 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8426 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008427
8428 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8429 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8430
Tyler Gunnf70ed162019-04-03 15:28:53 -07008431 final long identity = Binder.clearCallingIdentity();
8432 try {
8433 Phone phone = getPhone(subscriptionId);
8434 if (phone == null) {
8435 return null;
8436 }
8437 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8438 } finally {
8439 Binder.restoreCallingIdentity(identity);
8440 }
8441 }
8442
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008443 /**
8444 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008445 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008446 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008447 final long identity = Binder.clearCallingIdentity();
8448 try {
8449 Phone phone = getPhone(subId);
8450 if (phone != null) {
8451 return phone.isWifiCallingEnabled();
8452 } else {
8453 return false;
8454 }
8455 } finally {
8456 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008457 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008458 }
8459
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008460 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008461 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008462 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008463 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008464 final long identity = Binder.clearCallingIdentity();
8465 try {
8466 Phone phone = getPhone(subId);
8467 if (phone != null) {
8468 return phone.isVideoEnabled();
8469 } else {
8470 return false;
8471 }
8472 } finally {
8473 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008474 }
8475 }
8476
8477 /**
8478 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8479 * defined in {@link ImsRegistrationImplBase}.
8480 */
8481 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008482 final long identity = Binder.clearCallingIdentity();
8483 try {
8484 Phone phone = getPhone(subId);
8485 if (phone != null) {
8486 return phone.getImsRegistrationTech();
8487 } else {
8488 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8489 }
8490 } finally {
8491 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008492 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008493 }
8494
Stuart Scott8eef64f2015-04-08 15:13:54 -07008495 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008496 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008497 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008498
8499 enforceTelephonyFeatureWithException(callingPackage,
8500 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8501
Stuart Scott981d8582015-04-21 14:09:50 -07008502 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8503 return;
8504 }
Kai Shif70f46f2021-03-03 13:59:46 -08008505 Phone defaultPhone = getDefaultPhone();
8506 if (defaultPhone != null) {
8507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8508 mApp, getDefaultPhone().getSubId(), "factoryReset");
8509 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008510 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008511
Svet Ganovcc087f82015-05-12 20:35:54 -07008512 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008513 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8514 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008515 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008516 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008517 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008518 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008519 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008520 setDataRoamingEnabled(subId, phone == null ? false
8521 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008522 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008523 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008524 // There has been issues when Sms raw table somehow stores orphan
8525 // fragments. They lead to garbled message when new fragments come
8526 // in and combined with those stale ones. In case this happens again,
8527 // user can reset all network settings which will clean up this table.
8528 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008529 // Clean up IMS settings as well here.
8530 int slotId = getSlotIndex(subId);
8531 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8532 ImsManager.getInstance(mApp, slotId).factoryReset();
8533 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008534
Kai Shif70f46f2021-03-03 13:59:46 -08008535 if (defaultPhone == null) {
8536 return;
8537 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008538 // Erase modem config if erase modem on network setting is enabled.
8539 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8540 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8541 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008542 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008543 }
Kai Shif70f46f2021-03-03 13:59:46 -08008544
8545 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008546 } finally {
8547 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008548 }
8549 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008550
SongFerngWangfd89b102021-05-27 22:44:54 +08008551 @VisibleForTesting
8552 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8553 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8554 return;
8555 }
8556 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8557 RILConstants.PREFERRED_NETWORK_MODE);
8558 SubscriptionManager.setSubscriptionProperty(subId,
8559 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8560 "user=" + defaultNetworkType);
8561 phone.loadAllowedNetworksFromSubscriptionDatabase();
8562 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8563 defaultNetworkType, null);
8564 }
8565
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008566 private void cleanUpSmsRawTable(Context context) {
8567 ContentResolver resolver = context.getContentResolver();
8568 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8569 resolver.delete(uri, null, null);
8570 }
8571
Narayan Kamath1c496c22015-04-16 14:40:19 +01008572 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008573 public String getSimLocaleForSubscriber(int subId) {
8574 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008575
8576 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8577 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8578
chen xu5d3637b2019-01-21 23:31:38 -08008579 final Phone phone = getPhone(subId);
8580 if (phone == null) {
8581 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008582 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008583 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008584 final long identity = Binder.clearCallingIdentity();
8585 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008586 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8587 phone.getContext().getOpPackageName(),
8588 phone.getContext().getAttributionTag());
8589 if (info == null) {
8590 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8591 return null;
chen xu6291c472019-02-04 12:55:53 -08008592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593 // Try and fetch the locale from the carrier properties or from the SIM language
8594 // preferences (EF-PL and EF-LI)...
8595 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008596 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008597 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8598 if (localeFromDefaultSim != null) {
8599 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8600 if (DBG) log("Using locale from subId: " + subId + " locale: "
8601 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008602 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008603 } else {
8604 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008605 }
8606 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008608 // The SIM language preferences only store a language (e.g. fr = French), not an
8609 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8610 // the SIM and carrier preferences does not include a country we add the country
8611 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008612 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008613 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008614 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008615 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008616 }
8617
8618 if (DBG) log("No locale found - returning null");
8619 return null;
8620 } finally {
8621 Binder.restoreCallingIdentity(identity);
8622 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008623 }
8624
tom hsu0b59d292022-09-29 23:49:21 +08008625 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008626 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008627 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008628 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008629 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008630 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8631 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008632 Locale.forLanguageTag(localeTag).getCountry())) {
8633 return localeTag;
8634 }
8635 }
8636 return inputLocale.toLanguageTag();
8637 }
8638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008639 /**
8640 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8641 */
8642 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008643 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008644 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008645 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008646
Gary Jian3aa9a762022-01-24 16:41:19 +08008647 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8648 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008649
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008650 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008651 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8652 * representing the state of the modem.
8653 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008654 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8655 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008656 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008657 */
8658 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008659 public void requestModemActivityInfo(ResultReceiver result) {
8660 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008661
8662 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8663 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8664
vagdeviaf9a5b92018-08-15 16:01:53 -07008665 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008666
8667 final long identity = Binder.clearCallingIdentity();
8668 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008669 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008670 } finally {
8671 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008672 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008673 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008674
Gary Jian76280a42022-12-07 16:18:33 +08008675 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008676 // less than total activity duration.
8677 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8678 if (info == null) {
8679 return false;
8680 }
8681 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008682 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008683 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8684
Hall Liu49656c02020-10-09 19:00:11 -07008685 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8686
Siddharth Rayb8114062018-06-17 15:02:38 -07008687 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008688 && (info.getSleepTimeMillis() <= activityDurationMs)
8689 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008690 }
8691
Gary Jian3aa9a762022-01-24 16:41:19 +08008692 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8693 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8694 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8695 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8696
8697 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8698 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8699 }
8700
8701 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8702 mLastModemActivityInfo.setReceiveTimeMillis(
8703 rat,
8704 freq,
8705 info.getReceiveTimeMillis(rat, freq)
8706 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8707 }
8708
8709 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8710 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8711 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8712 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8713
8714 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8715 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8716 }
8717 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8718 mLastModemActivityInfo.setReceiveTimeMillis(
8719 rat,
8720 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8721 }
8722
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008723 /**
8724 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8725 * @param info recent ModemActivityInfo
8726 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008727 private void mergeModemActivityInfo(ModemActivityInfo info) {
8728 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008729 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008730 boolean matched;
8731 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8732 matched = false;
8733 int rat = info.getSpecificInfoRat(i);
8734 int freq = info.getSpecificInfoFrequencyRange(i);
8735 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8736 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8737 //if it already exists
8738 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8739 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8740 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8741 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8742 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8743 updateLastModemActivityInfo(info, rat, freq);
8744 matched = true;
8745 }
8746 } else {
8747 updateLastModemActivityInfo(info, rat);
8748 matched = true;
8749 }
8750 }
8751 }
8752
8753 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008754 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008755 new ActivityStatsTechSpecificInfo(
8756 rat,
8757 freq,
8758 info.getTransmitTimeMillis(rat, freq),
8759 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008760 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008761 }
8762 }
8763 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8764 mLastModemActivitySpecificInfo =
8765 new ActivityStatsTechSpecificInfo[merged.size()];
8766 merged.toArray(mLastModemActivitySpecificInfo);
8767
8768 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8769 mLastModemActivityInfo.setSleepTimeMillis(
8770 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008771 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008772 mLastModemActivityInfo.setIdleTimeMillis(
8773 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008774 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008775
8776 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008777 new ModemActivityInfo(
8778 mLastModemActivityInfo.getTimestampMillis(),
8779 mLastModemActivityInfo.getSleepTimeMillis(),
8780 mLastModemActivityInfo.getIdleTimeMillis(),
8781 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008782 }
8783
8784 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8785 ActivityStatsTechSpecificInfo[] info) {
8786 int infoSize = info.length;
8787 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8788 for (int i = 0; i < infoSize; i++) {
8789 ret[i] = new ActivityStatsTechSpecificInfo(
8790 info[i].getRat(), info[i].getFrequencyRange(),
8791 info[i].getTransmitTimeMillis(),
8792 (int) info[i].getReceiveTimeMillis());
8793 }
8794 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008795 }
8796
Jack Yu85bd38a2015-11-09 11:34:32 -08008797 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008798 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008799 */
8800 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008801 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8802 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8803 Phone phone = PhoneFactory.getPhone(slotIndex);
8804 if (phone == null) {
8805 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8806 return null;
8807 }
8808
8809 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008810 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008811 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008812 return null;
8813 }
8814
joonhunshin4ac60942023-11-15 15:23:39 +00008815 enforceTelephonyFeatureWithException(callingPackage,
8816 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8817
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008818 boolean hasFinePermission = false;
8819 boolean hasCoarsePermission = false;
8820 if (!renounceFineLocationAccess) {
8821 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8822 LocationAccessPolicy.checkLocationPermission(mApp,
8823 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8824 .setCallingPackage(callingPackage)
8825 .setCallingFeatureId(callingFeatureId)
8826 .setCallingPid(Binder.getCallingPid())
8827 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008828 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008829 .setLogAsInfo(true)
8830 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8831 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8832 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8833 .build());
8834 hasFinePermission =
8835 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8836 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008837
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008838 if (!renounceCoarseLocationAccess) {
8839 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8840 LocationAccessPolicy.checkLocationPermission(mApp,
8841 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8842 .setCallingPackage(callingPackage)
8843 .setCallingFeatureId(callingFeatureId)
8844 .setCallingPid(Binder.getCallingPid())
8845 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008846 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008847 .setLogAsInfo(true)
8848 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8849 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8850 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8851 .build());
8852 hasCoarsePermission =
8853 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8854 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008855
Jordan Liu0f2bc442020-11-18 16:47:37 -08008856 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008857 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008858 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8859 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008860 if (subInfo != null && !subInfo.isActive()) {
8861 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008862 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008863 }
8864
Hall Liuf19c44f2018-11-27 14:38:17 -08008865 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008866 boolean isCallingPackageDataService = phone.getDataServicePackages()
8867 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008868
8869 // Scrub out the location info in ServiceState depending on what level of access
8870 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008871 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008872 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8873 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008874 } finally {
8875 Binder.restoreCallingIdentity(identity);
8876 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008877 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008878
8879 /**
8880 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8881 *
8882 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8883 * voicemail ringtone.
8884 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8885 * PhoneAccount.
8886 */
8887 @Override
8888 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008889 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8890 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008892 final long identity = Binder.clearCallingIdentity();
8893 try {
8894 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8895 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008896 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008897 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008899 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8900 } finally {
8901 Binder.restoreCallingIdentity(identity);
8902 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008903 }
8904
8905 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008906 * Sets the per-account voicemail ringtone.
8907 *
8908 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8909 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8910 *
8911 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8912 * voicemail ringtone.
8913 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8914 * PhoneAccount.
8915 */
8916 @Override
8917 public void setVoicemailRingtoneUri(String callingPackage,
8918 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008919 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008920 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008921 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8922 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8924 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8925 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008927
joonhunshin4ac60942023-11-15 15:23:39 +00008928 enforceTelephonyFeatureWithException(callingPackage,
8929 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008931 final long identity = Binder.clearCallingIdentity();
8932 try {
8933 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8934 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008935 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008936 }
8937 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8938 } finally {
8939 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008940 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008941 }
8942
8943 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008944 * Returns whether vibration is set for voicemail notification in Phone settings.
8945 *
8946 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8947 * voicemail vibration setting.
8948 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8949 */
8950 @Override
8951 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008952 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8953 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
8954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008955 final long identity = Binder.clearCallingIdentity();
8956 try {
8957 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8958 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008959 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008960 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008962 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8963 } finally {
8964 Binder.restoreCallingIdentity(identity);
8965 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008966 }
8967
Youhan Wange64578a2016-05-02 15:32:42 -07008968 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008969 * Sets the per-account voicemail vibration.
8970 *
8971 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8972 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8973 *
8974 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8975 * voicemail vibration setting.
8976 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8977 * specific PhoneAccount.
8978 */
8979 @Override
8980 public void setVoicemailVibrationEnabled(String callingPackage,
8981 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008982 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008983 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008984 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8985 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8987 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8988 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008989 }
8990
joonhunshin4ac60942023-11-15 15:23:39 +00008991 enforceTelephonyFeatureWithException(callingPackage,
8992 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
8993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008994 final long identity = Binder.clearCallingIdentity();
8995 try {
8996 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8997 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008998 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008999 }
9000 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9001 } finally {
9002 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009003 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009004 }
9005
9006 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009007 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9008 *
9009 * @throws SecurityException if the caller does not have the required permission
9010 */
arunvoddud7401012022-12-15 16:08:12 +00009011 @VisibleForTesting
9012 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009013 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009014 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009015 }
9016
9017 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009018 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9019 * permission.
9020 *
9021 * @throws SecurityException if the caller does not have the required permission
9022 */
9023 private void enforceSendSmsPermission() {
9024 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9025 }
9026
9027 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009028 * Make sure either called from same process as self (phone) or IPC caller has interact across
9029 * users permission.
9030 *
9031 * @throws SecurityException if the caller does not have the required permission
9032 */
9033 private void enforceInteractAcrossUsersPermission(String message) {
9034 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9035 }
9036
9037 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009038 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009039 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009040 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009041 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009042 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009043 final long identity = Binder.clearCallingIdentity();
9044 try {
9045 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009046 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009047 if (componentName == null) {
9048 throw new SecurityException(
9049 "Caller not current active visual voicemail package[null]");
9050 }
9051 String vvmPackage = componentName.getPackageName();
9052 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009053 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009054 }
9055 } finally {
9056 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009057 }
9058 }
9059
9060 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009061 * Return the application ID for the app type.
9062 *
9063 * @param subId the subscription ID that this request applies to.
9064 * @param appType the uicc app type.
9065 * @return Application ID for specificied app type, or null if no uicc.
9066 */
9067 @Override
9068 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009069 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009070
9071 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9072 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9073
Youhan Wange64578a2016-05-02 15:32:42 -07009074 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009075
9076 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009077 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009078 if (phone == null) {
9079 return null;
9080 }
9081 String aid = null;
9082 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009083 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009084 .getApplicationByType(appType).getAid();
9085 } catch (Exception e) {
9086 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9087 }
9088 return aid;
9089 } finally {
9090 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009091 }
Youhan Wange64578a2016-05-02 15:32:42 -07009092 }
9093
Youhan Wang4001d252016-05-11 10:29:41 -07009094 /**
9095 * Return the Electronic Serial Number.
9096 *
9097 * @param subId the subscription ID that this request applies to.
9098 * @return ESN or null if error.
9099 */
9100 @Override
9101 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009102 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009103 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009104
9105 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009106 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009107 if (phone == null) {
9108 return null;
9109 }
9110 String esn = null;
9111 try {
9112 esn = phone.getEsn();
9113 } catch (Exception e) {
9114 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9115 }
9116 return esn;
9117 } finally {
9118 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009119 }
Youhan Wang4001d252016-05-11 10:29:41 -07009120 }
9121
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009122 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009123 * Return the Preferred Roaming List Version.
9124 *
9125 * @param subId the subscription ID that this request applies to.
9126 * @return PRLVersion or null if error.
9127 */
9128 @Override
9129 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009130 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009131
9132 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9133 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9134
Youhan Wang66ad5d72016-07-18 17:56:58 -07009135 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009136
9137 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009138 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009139 if (phone == null) {
9140 return null;
9141 }
9142 String cdmaPrlVersion = null;
9143 try {
9144 cdmaPrlVersion = phone.getCdmaPrlVersion();
9145 } catch (Exception e) {
9146 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9147 }
9148 return cdmaPrlVersion;
9149 } finally {
9150 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009151 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009152 }
9153
9154 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009155 * Get snapshot of Telephony histograms
9156 * @return List of Telephony histograms
9157 * @hide
9158 */
9159 @Override
9160 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9162 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009163
9164 final long identity = Binder.clearCallingIdentity();
9165 try {
9166 return RIL.getTelephonyRILTimingHistograms();
9167 } finally {
9168 Binder.restoreCallingIdentity(identity);
9169 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009170 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009171
9172 /**
9173 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009174 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9175 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009176 * Require system privileges. In the future we may add this to carrier APIs.
9177 *
Michele Berionne482f8202018-11-27 18:57:59 -08009178 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009179 */
9180 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009181 @TelephonyManager.SetCarrierRestrictionResult
9182 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009183 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009184
9185 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9186 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9187
vagdeviaf9a5b92018-08-15 16:01:53 -07009188 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009189
Michele Berionne482f8202018-11-27 18:57:59 -08009190 if (carrierRestrictionRules == null) {
9191 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009192 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009194 final long identity = Binder.clearCallingIdentity();
9195 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009196 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009197 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009198 } finally {
9199 Binder.restoreCallingIdentity(identity);
9200 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009201 }
9202
9203 /**
9204 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009205 * Get the allowed carrier list and the excluded carrier list, including the priority between
9206 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009207 * Require system privileges. In the future we may add this to carrier APIs.
9208 *
Michele Berionne482f8202018-11-27 18:57:59 -08009209 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009210 */
9211 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009212 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009213 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009214
9215 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9216 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9217
vagdeviaf9a5b92018-08-15 16:01:53 -07009218 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009219
9220 final long identity = Binder.clearCallingIdentity();
9221 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009222 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9223 if (response instanceof CarrierRestrictionRules) {
9224 return (CarrierRestrictionRules) response;
9225 }
9226 // Response is an Exception of some kind,
9227 // which is signalled to the user as a NULL retval
9228 return null;
9229 } catch (Exception e) {
9230 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9231 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009232 } finally {
9233 Binder.restoreCallingIdentity(identity);
9234 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009235 }
9236
fionaxu59545b42016-05-25 15:53:37 -07009237 /**
arunvoddud7401012022-12-15 16:08:12 +00009238 * Fetches the carrier restriction status of the device and sends the status to the caller
9239 * through the callback.
9240 *
9241 * @param callback The callback that will be used to send the result.
9242 * @throws SecurityException if the caller does not have the required permission/privileges or
9243 * the caller is not allowlisted.
9244 */
9245 @Override
9246 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9247 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009248
9249 enforceTelephonyFeatureWithException(packageName,
9250 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9251
Steve Statia28b7cb32024-03-11 23:58:50 +00009252 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9253 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009254 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9255 throw new SecurityException("Not an authorized caller");
9256 }
9257 final long identity = Binder.clearCallingIdentity();
9258 try {
9259 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009260 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009261 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9262 } finally {
9263 Binder.restoreCallingIdentity(identity);
9264 }
9265 }
9266
arunvoddu567f2b42023-04-25 17:22:00 +00009267 @Override
9268 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9269 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9270 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9271 return allowListInfo.getShaIdList(pkgName, carrierId);
9272 }
9273
arunvoddud7401012022-12-15 16:08:12 +00009274 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009275 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009276 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009277 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009278 }
9279
9280 /**
fionaxu59545b42016-05-25 15:53:37 -07009281 * Action set from carrier signalling broadcast receivers to enable/disable radio
9282 * @param subId the subscription ID that this action applies to.
9283 * @param enabled control enable or disable radio.
9284 * {@hide}
9285 */
9286 @Override
9287 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9288 enforceModifyPermission();
9289 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009290
9291 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009292 if (phone == null) {
9293 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9294 return;
9295 }
9296 try {
9297 phone.carrierActionSetRadioEnabled(enabled);
9298 } catch (Exception e) {
9299 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009300 } finally {
9301 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009302 }
9303 }
9304
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009305 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009306 * Enable or disable Voice over NR (VoNR)
9307 * @param subId the subscription ID that this action applies to.
9308 * @param enabled enable or disable VoNR.
9309 * @return operation result.
9310 */
9311 @Override
9312 public int setVoNrEnabled(int subId, boolean enabled) {
9313 enforceModifyPermission();
9314 final Phone phone = getPhone(subId);
9315
9316 final long identity = Binder.clearCallingIdentity();
9317 if (phone == null) {
9318 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9319 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9320 }
9321
9322 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9323 try {
9324 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9325 workSource);
9326 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009327
9328 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9329 if (DBG) {
9330 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9331 }
9332 SubscriptionManager.setSubscriptionProperty(
9333 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9334 (enabled ? "1" : "0"));
9335 }
9336
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009337 return result;
9338 } finally {
9339 Binder.restoreCallingIdentity(identity);
9340 }
9341 }
9342
9343 /**
9344 * Is voice over NR enabled
9345 * @return true if VoNR is enabled else false
9346 */
9347 @Override
9348 public boolean isVoNrEnabled(int subId) {
9349 enforceReadPrivilegedPermission("isVoNrEnabled");
9350 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9351 final long identity = Binder.clearCallingIdentity();
9352 try {
9353 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9354 null, subId, workSource);
9355 if (DBG) log("isVoNrEnabled: " + isEnabled);
9356 return isEnabled;
9357 } finally {
9358 Binder.restoreCallingIdentity(identity);
9359 }
9360 }
9361
9362 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009363 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9364 * network status based on which carrier apps could apply actions accordingly,
9365 * enable/disable default url handler for example.
9366 *
9367 * @param subId the subscription ID that this action applies to.
9368 * @param report control start/stop reporting the default network status.
9369 * {@hide}
9370 */
9371 @Override
9372 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9373 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009374
9375 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9376 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9377 "carrierActionReportDefaultNetworkStatus");
9378
fionaxu8da9cb12017-05-23 15:02:46 -07009379 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009380
9381 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009382 if (phone == null) {
9383 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9384 return;
9385 }
9386 try {
9387 phone.carrierActionReportDefaultNetworkStatus(report);
9388 } catch (Exception e) {
9389 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009390 } finally {
9391 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009392 }
9393 }
9394
9395 /**
fionaxud9622282017-07-17 17:51:30 -07009396 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9397 * @param subId the subscription ID that this action applies to.
9398 * {@hide}
9399 */
9400 @Override
9401 public void carrierActionResetAll(int subId) {
9402 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009403
9404 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9405 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9406
fionaxud9622282017-07-17 17:51:30 -07009407 final Phone phone = getPhone(subId);
9408 if (phone == null) {
9409 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9410 return;
9411 }
9412 try {
9413 phone.carrierActionResetAll();
9414 } catch (Exception e) {
9415 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9416 }
9417 }
9418
9419 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009420 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9421 * bug report is being generated.
9422 */
9423 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009424 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009425 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9426 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009427 writer.println("Permission Denial: can't dump Phone from pid="
9428 + Binder.getCallingPid()
9429 + ", uid=" + Binder.getCallingUid()
9430 + "without permission "
9431 + android.Manifest.permission.DUMP);
9432 return;
9433 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009434 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009435 }
Jack Yueb89b242016-06-22 13:27:47 -07009436
Brad Ebingerdac2f002018-04-03 15:17:52 -07009437 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009438 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9439 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9440 @NonNull String[] args) {
9441 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9442 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009443 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009444 }
9445
Jack Yueb89b242016-06-22 13:27:47 -07009446 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009447 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009448 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009449 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009450 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009451 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009452 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009453 */
9454 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009455 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009456 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009457 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9458 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9459 try {
9460 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009461 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009462 } catch (SecurityException se) {
9463 enforceModifyPermission();
9464 }
9465 } else {
9466 enforceModifyPermission();
9467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009468
joonhunshin4ac60942023-11-15 15:23:39 +00009469 enforceTelephonyFeatureWithException(callingPackage,
9470 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9471
Nate Myren116695d2024-02-09 09:36:01 -08009472 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009473 final long identity = Binder.clearCallingIdentity();
9474 try {
Nate Myren116695d2024-02-09 09:36:01 -08009475 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9476 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009477 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009478 callingUid, callingPackage, null, null);
9479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009480 Phone phone = getPhone(subId);
9481 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009482 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9483 phone.carrierActionSetMeteredApnsEnabled(enabled);
9484 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009485 phone.getDataSettingsManager().setDataEnabled(
9486 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009488 }
9489 } finally {
9490 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009491 }
9492 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009493
9494 /**
9495 * Get Client request stats
9496 * @return List of Client Request Stats
9497 * @hide
9498 */
9499 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009500 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9501 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009503 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009504 return null;
9505 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009506 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009508 final long identity = Binder.clearCallingIdentity();
9509 try {
9510 if (phone != null) {
9511 return phone.getClientRequestStats();
9512 }
9513
9514 return null;
9515 } finally {
9516 Binder.restoreCallingIdentity(identity);
9517 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009518 }
9519
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009520 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009521 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009522 if (uid == Process.ROOT_UID && packageName == null) {
9523 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9524 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9525 // exception. ROOT_UID seems not to have a valid package name returned by
9526 // PackageManager, so just fake it here to avoid issues when running telephony shell
9527 // commands that plumb through the RIL as root, like so:
9528 // $ adb root
9529 // $ adb shell cmd phone ...
9530 packageName = "root";
9531 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009532 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009533 }
Jack Yueb4124c2017-02-16 15:32:43 -08009534
9535 /**
Grace Chen70990072017-03-24 17:21:30 -07009536 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009537 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009538 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009539 * @param state State of SIM (power down, power up, pass through)
9540 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9541 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9542 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009543 *
9544 **/
9545 @Override
Grace Chen70990072017-03-24 17:21:30 -07009546 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009547 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009548
9549 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9550 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9551
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009552 Phone phone = PhoneFactory.getPhone(slotIndex);
9553
vagdeviaf9a5b92018-08-15 16:01:53 -07009554 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009556 final long identity = Binder.clearCallingIdentity();
9557 try {
9558 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009559 phone.setSimPowerState(state, null, workSource);
9560 }
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
9563 }
9564 }
9565
9566 /**
9567 * Set SIM card power state.
9568 *
9569 * @param slotIndex SIM slot id.
9570 * @param state State of SIM (power down, power up, pass through)
9571 * @param callback callback to trigger after success or failure
9572 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9573 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9574 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9575 *
9576 **/
9577 @Override
9578 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9579 IIntegerConsumer callback) {
9580 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009581
9582 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9583 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9584 "setSimPowerStateForSlotWithCallback");
9585
Jordan Liu109698e2020-11-24 14:50:34 -08009586 Phone phone = PhoneFactory.getPhone(slotIndex);
9587
9588 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9589
9590 final long identity = Binder.clearCallingIdentity();
9591 try {
9592 if (phone != null) {
9593 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9594 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009595 }
9596 } finally {
9597 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009598 }
9599 }
Shuo Qiandd210312017-04-12 22:11:33 +00009600
Tyler Gunn65d45c22017-06-05 11:22:26 -07009601 private boolean isUssdApiAllowed(int subId) {
9602 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009603 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009604 if (configManager == null) {
9605 return false;
9606 }
9607 PersistableBundle pb = configManager.getConfigForSubId(subId);
9608 if (pb == null) {
9609 return false;
9610 }
9611 return pb.getBoolean(
9612 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9613 }
9614
Shuo Qiandd210312017-04-12 22:11:33 +00009615 /**
Ling Mac28f0212023-03-24 16:07:15 -07009616 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009617 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009618 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009619 */
goneil9c5f4872017-12-05 14:07:56 -08009620 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009621 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009622 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009623
9624 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9625 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009627 final long identity = Binder.clearCallingIdentity();
9628 try {
Ling Mac28f0212023-03-24 16:07:15 -07009629 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009630 } finally {
9631 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009632 }
9633 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009634
9635 /**
9636 * Get the current signal strength information for the given subscription.
9637 * Because this information is not updated when the device is in a low power state
9638 * it should not be relied-upon to be current.
9639 * @param subId Subscription index
9640 * @return the most recent cached signal strength info from the modem
9641 */
9642 @Override
9643 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009644 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9645 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009647 final long identity = Binder.clearCallingIdentity();
9648 try {
9649 Phone p = getPhone(subId);
9650 if (p == null) {
9651 return null;
9652 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009654 return p.getSignalStrength();
9655 } finally {
9656 Binder.restoreCallingIdentity(identity);
9657 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009658 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009659
Pengquan Meng77b7f132018-08-22 14:49:57 -07009660 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009661 * Get the current modem radio state for the given slot.
9662 * @param slotIndex slot index.
9663 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009664 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009665 * @return the current radio power state from the modem
9666 */
9667 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009668 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009669 Phone phone = PhoneFactory.getPhone(slotIndex);
9670 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9672 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009673 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9674 }
9675
joonhunshin4ac60942023-11-15 15:23:39 +00009676 enforceTelephonyFeatureWithException(callingPackage,
9677 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9678
Chen Xuf792fd62018-10-17 17:54:36 +00009679 final long identity = Binder.clearCallingIdentity();
9680 try {
9681 return phone.getRadioPowerState();
9682 } finally {
9683 Binder.restoreCallingIdentity(identity);
9684 }
9685 }
9686 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9687 }
9688
9689 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009690 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9691 *
9692 * <p>Requires one of the following permissions:
9693 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009694 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009695 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9696 * privileges.
9697 *
9698 * @param subId subscription id
9699 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9700 * {@code false}.
9701 */
9702 @Override
9703 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009704 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009705 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009706 try {
9707 mApp.enforceCallingOrSelfPermission(
9708 android.Manifest.permission.ACCESS_NETWORK_STATE,
9709 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009710 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009711 mApp.enforceCallingOrSelfPermission(
9712 permission.READ_BASIC_PHONE_STATE, functionName);
9713 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009714 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009715 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009716 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009717 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009718
joonhunshin4ac60942023-11-15 15:23:39 +00009719 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9720 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9721
Pengquan Menga1bb6272018-09-06 09:59:22 -07009722 boolean isEnabled = false;
9723 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009724 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009725 Phone phone = getPhone(subId);
9726 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009727 } finally {
9728 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009729 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009730 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009731 }
9732
9733
9734 /**
9735 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9736 *
9737 * <p> Requires permission:
9738 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9739 * privileges.
9740 *
9741 * @param subId subscription id
9742 * @param isEnabled {@code true} means enable, {@code false} means disable.
9743 */
9744 @Override
9745 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9747 mApp, subId, "setDataRoamingEnabled");
9748
joonhunshin4ac60942023-11-15 15:23:39 +00009749 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9750 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9751
Pengquan Menga1bb6272018-09-06 09:59:22 -07009752 final long identity = Binder.clearCallingIdentity();
9753 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009754 Phone phone = getPhone(subId);
9755 if (phone != null) {
9756 phone.setDataRoamingEnabled(isEnabled);
9757 }
9758 } finally {
9759 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009760 }
9761 }
9762
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009763 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009764 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009765 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009766 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009767 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009768
joonhunshin4ac60942023-11-15 15:23:39 +00009769 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9770 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9771
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009772 boolean isAllowed = true;
9773 final long identity = Binder.clearCallingIdentity();
9774 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009775 Phone phone = getPhone(subId);
9776 if (phone != null) {
9777 isAllowed = phone.isCspPlmnEnabled();
9778 }
9779 } finally {
9780 Binder.restoreCallingIdentity(identity);
9781 }
9782 return isAllowed;
9783 }
9784
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009785 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9786 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009787 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009788 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009789 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009790 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9791 if (phone == null) {
9792 return false;
9793 }
9794 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9795 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9796 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009797 }
9798
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009799 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009800 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009801 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009802 mApp.getSystemService(AppOpsManager.class)
9803 .checkPackage(Binder.getCallingUid(), callingPackage);
9804
Jordan Liu1e142fc2019-04-22 15:10:43 -07009805 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009806 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009807 try {
9808 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009809 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009810 } catch (SecurityException e) {
9811 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9812 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009813 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009814 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009815 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009816 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009817 }
joonhunshin4ac60942023-11-15 15:23:39 +00009818
9819 enforceTelephonyFeatureWithException(callingPackage,
9820 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9821
sandeepjsb6c87872021-09-27 15:34:44 +00009822 // checking compatibility, if calling app's target SDK is T and beyond.
9823 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9824 Binder.getCallingUid())) {
9825 isIccIdAccessRestricted = true;
9826 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009827 final long identity = Binder.clearCallingIdentity();
9828 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009829 UiccController uiccController = UiccController.getInstance();
9830 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009831 if (hasReadPermission) {
9832 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009833 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009834
9835 // Remove private info if the caller doesn't have access
9836 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9837 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009838 //setting the value after compatibility check
9839 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009840 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9841 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009842 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009843 if (card == null) {
9844 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009845 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009846 continue;
9847 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009848 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9849 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009850 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009851 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009852 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009853 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9854 for (UiccPortInfo portInfo : portInfos) {
9855 UiccPort port = uiccController.getUiccPortForSlot(
9856 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9857 if (port == null) {
9858 // assume no access if port is null
9859 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9860 continue;
9861 }
9862 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9863 uiccPortInfos.add(portInfo);
9864 } else {
9865 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9866 }
9867 }
9868 filteredInfos.add(new UiccCardInfo(
9869 cardInfo.isEuicc(),
9870 cardInfo.getCardId(),
9871 null,
9872 cardInfo.getPhysicalSlotIndex(),
9873 cardInfo.isRemovable(),
9874 cardInfo.isMultipleEnabledProfilesSupported(),
9875 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009876 }
9877 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009878 } finally {
9879 Binder.restoreCallingIdentity(identity);
9880 }
9881 }
9882
sandeepjsb6c87872021-09-27 15:34:44 +00009883 /**
9884 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9885 * generally private and require carrier privileges to view.
9886 *
9887 * @hide
9888 */
9889 @NonNull
9890 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9891 List<UiccPortInfo> portinfo = new ArrayList<>();
9892 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9893 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9894 }
9895 return new UiccCardInfo(
9896 cardInfo.isEuicc(),
9897 cardInfo.getCardId(),
9898 null,
9899 cardInfo.getPhysicalSlotIndex(),
9900 cardInfo.isRemovable(),
9901 cardInfo.isMultipleEnabledProfilesSupported(),
9902 portinfo
9903 );
9904 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009905
sandeepjsb6c87872021-09-27 15:34:44 +00009906 /**
9907 * @hide
9908 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9909 * These values are generally private and require carrier privileges to view.
9910 */
9911 @NonNull
9912 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9913 return new UiccPortInfo(
9914 UiccPortInfo.ICCID_REDACTED,
9915 portInfo.getPortIndex(),
9916 portInfo.getLogicalSlotIndex(),
9917 portInfo.isActive()
9918 );
9919 }
9920 @Override
9921 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009922 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009923 mApp.getSystemService(AppOpsManager.class)
9924 .checkPackage(Binder.getCallingUid(), callingPackage);
9925
sandeepjsb6c87872021-09-27 15:34:44 +00009926 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009927
Aman Guptaf3c90b32022-03-17 04:54:16 +00009928 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9929 // we are reading iccId which is PII data.
9930 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009931
joonhunshin4ac60942023-11-15 15:23:39 +00009932 enforceTelephonyFeatureWithException(callingPackage,
9933 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9934
sandeepjsb6c87872021-09-27 15:34:44 +00009935 // checking compatibility, if calling app's target SDK is T and beyond.
9936 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9937 Binder.getCallingUid())) {
9938 isLogicalSlotAccessRestricted = true;
9939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009940 final long identity = Binder.clearCallingIdentity();
9941 try {
9942 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009943 if (slots == null || slots.length == 0) {
9944 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009945 return null;
9946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009947 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9948 for (int i = 0; i < slots.length; i++) {
9949 UiccSlot slot = slots[i];
9950 if (slot == null) {
9951 continue;
9952 }
9953
Jordan Liu7be7e652019-05-06 18:55:02 +00009954 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009955 UiccCard card = slot.getUiccCard();
9956 if (card != null) {
9957 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009958 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009959 cardId = slot.getEid();
9960 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009961 // If cardId is null, use iccId of default port as cardId.
9962 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009964 }
9965
Jordan Liu857451f2019-05-09 16:35:35 -07009966 if (cardId != null) {
9967 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9968 // if cardId is an EID, it's all digits so this is fine
9969 cardId = IccUtils.stripTrailingFs(cardId);
9970 }
9971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009972 int cardState = 0;
9973 switch (slot.getCardState()) {
9974 case CARDSTATE_ABSENT:
9975 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9976 break;
9977 case CARDSTATE_PRESENT:
9978 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9979 break;
9980 case CARDSTATE_ERROR:
9981 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9982 break;
9983 case CARDSTATE_RESTRICTED:
9984 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9985 break;
9986 default:
9987 break;
9988
9989 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009990 List<UiccPortInfo> portInfos = new ArrayList<>();
9991 int[] portIndexes = slot.getPortList();
9992 for (int portIdx : portIndexes) {
9993 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009994 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009995 portInfos.add(new UiccPortInfo(iccId, portIdx,
9996 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009998 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009999 slot.isEuicc(),
10000 cardId,
10001 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010002 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010003 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010004 //setting the value after compatibility check
10005 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010006 }
10007 return infos;
10008 } finally {
10009 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010010 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010011 }
10012
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010013 /* Returns null if doesn't have read permission or carrier privilege access. */
10014 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10015 boolean hasReadPermission) {
10016 String iccId = slot.getIccId(portIndex);
10017 if (hasReadPermission) { // if has read permission
10018 return iccId;
10019 } else {
10020 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10021 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10022 // if no read permission, checking carrier privilege access
10023 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10024 return iccId;
10025 }
10026 }
10027 }
10028 // No read permission or carrier privilege access.
10029 return UiccPortInfo.ICCID_REDACTED;
10030 }
10031
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010032 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010033 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010034 public boolean switchSlots(int[] physicalSlots) {
10035 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010036
joonhunshin4ac60942023-11-15 15:23:39 +000010037 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10038 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10039
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010040 final long identity = Binder.clearCallingIdentity();
10041 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010042 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10043 for (int i = 0; i < physicalSlots.length; i++) {
10044 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10045 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10046 physicalSlots[i], i));
10047 }
10048 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010049 } finally {
10050 Binder.restoreCallingIdentity(identity);
10051 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010052 }
Jack Yu4c988042018-02-27 15:30:01 -080010053
10054 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010055 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10056 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10057 enforceModifyPermission();
10058
joonhunshin4ac60942023-11-15 15:23:39 +000010059 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10060 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10061
sandeepjsb6c87872021-09-27 15:34:44 +000010062 final long identity = Binder.clearCallingIdentity();
10063 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010064 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010065 } finally {
10066 Binder.restoreCallingIdentity(identity);
10067 }
10068 }
10069
10070 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010071 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010072 enforceTelephonyFeatureWithException(callingPackage,
10073 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10074
Jordan Liu7de49fa2018-12-06 14:48:49 -080010075 final long identity = Binder.clearCallingIdentity();
10076 try {
10077 return UiccController.getInstance().getCardIdForDefaultEuicc();
10078 } finally {
10079 Binder.restoreCallingIdentity(identity);
10080 }
10081 }
10082
Pengquan Meng85728fb2018-03-12 16:31:21 -070010083 /**
goneil47ffb6e2018-04-06 15:40:58 -070010084 * A test API to reload the UICC profile.
10085 *
10086 * <p>Requires that the calling app has permission
10087 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10088 * @hide
10089 */
10090 @Override
10091 public void refreshUiccProfile(int subId) {
10092 enforceModifyPermission();
10093
10094 final long identity = Binder.clearCallingIdentity();
10095 try {
10096 Phone phone = getPhone(subId);
10097 if (phone == null) {
10098 return;
10099 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010100 UiccPort uiccPort = phone.getUiccPort();
10101 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010102 return;
10103 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010104 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010105 if (uiccProfile == null) {
10106 return;
10107 }
10108 uiccProfile.refresh();
10109 } finally {
10110 Binder.restoreCallingIdentity(identity);
10111 }
10112 }
10113
10114 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010115 * Returns false if the mobile data is disabled by default, otherwise return true.
10116 */
10117 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010118 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010119 }
10120
10121 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010122 * Returns the default network type for the given {@code subId}, if the default network type is
10123 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10124 */
10125 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010126 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010127 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010128 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10129 return list.get(phoneId);
10130 }
10131 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010132 }
fionaxua13278b2018-03-21 00:08:13 -070010133
10134 @Override
10135 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010136 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010137 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010138
10139 final long identity = Binder.clearCallingIdentity();
10140 try {
10141 final Phone phone = getPhone(subId);
10142 if (phone == null) {
10143 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10144 return;
10145 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010146 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10147 if (cpt != null) {
10148 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10149 }
10150 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010151 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10152 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010153 if (carrierPrivilegeRules == null) {
10154 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10155 } else {
10156 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10157 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010158 } finally {
10159 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010160 }
fionaxua13278b2018-03-21 00:08:13 -070010161 }
10162
10163 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010164 public void setCarrierServicePackageOverride(
10165 int subId, String carrierServicePackage, String callingPackage) {
10166 TelephonyPermissions.enforceShellOnly(
10167 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10168
Benedict Wong66477622023-02-03 23:30:57 +000010169 final long identity = Binder.clearCallingIdentity();
10170 try {
10171 final Phone phone = getPhone(subId);
10172 if (phone == null || phone.getSubId() != subId) {
10173 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10174 throw new IllegalArgumentException("No phone for subid");
10175 }
10176 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10177 if (cpt == null) {
10178 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10179 throw new IllegalStateException("No CPT for phone");
10180 }
10181 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10182 } finally {
10183 Binder.restoreCallingIdentity(identity);
10184 }
10185 }
10186
10187 @Override
fionaxua13278b2018-03-21 00:08:13 -070010188 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010189 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010190
10191 final long identity = Binder.clearCallingIdentity();
10192 try {
10193 final Phone phone = getPhone(subId);
10194 if (phone == null) {
10195 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10196 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10197 }
10198 return phone.getCarrierIdListVersion();
10199 } finally {
10200 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010201 }
fionaxua13278b2018-03-21 00:08:13 -070010202 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010203
10204 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010205 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10206 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010208 mApp, subId, callingPackage, callingFeatureId,
10209 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010210 return -1;
10211 }
10212
10213 final long identity = Binder.clearCallingIdentity();
10214 try {
10215 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10216 } finally {
10217 Binder.restoreCallingIdentity(identity);
10218 }
10219 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010220
10221 @Override
10222 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010223 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010224 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010225 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010226
joonhunshin4ac60942023-11-15 15:23:39 +000010227 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10228 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10229
Pengquan Menga1bb6272018-09-06 09:59:22 -070010230 final long identity = Binder.clearCallingIdentity();
10231 try {
10232 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10233 } finally {
10234 Binder.restoreCallingIdentity(identity);
10235 }
10236 }
10237
10238 @Override
10239 public boolean setCdmaRoamingMode(int subId, int mode) {
10240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10241 mApp, subId, "setCdmaRoamingMode");
10242
joonhunshin4ac60942023-11-15 15:23:39 +000010243 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10244 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10245
Pengquan Menga1bb6272018-09-06 09:59:22 -070010246 final long identity = Binder.clearCallingIdentity();
10247 try {
10248 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10249 } finally {
10250 Binder.restoreCallingIdentity(identity);
10251 }
10252 }
10253
10254 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010255 public int getCdmaSubscriptionMode(int subId) {
10256 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010257 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010258 mApp, subId, "getCdmaSubscriptionMode");
10259
joonhunshin4ac60942023-11-15 15:23:39 +000010260 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10261 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10262
Sarah Chinbaab1432020-10-28 13:46:24 -070010263 final long identity = Binder.clearCallingIdentity();
10264 try {
10265 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10266 } finally {
10267 Binder.restoreCallingIdentity(identity);
10268 }
10269 }
10270
10271 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010272 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10274 mApp, subId, "setCdmaSubscriptionMode");
10275
joonhunshin4ac60942023-11-15 15:23:39 +000010276 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10277 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10278
Pengquan Menga1bb6272018-09-06 09:59:22 -070010279 final long identity = Binder.clearCallingIdentity();
10280 try {
10281 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10282 } finally {
10283 Binder.restoreCallingIdentity(identity);
10284 }
10285 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010286
sqianc5eccab2018-10-19 18:46:41 -070010287 @Override
sqian8c685422019-02-22 15:55:18 -080010288 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010289 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010291 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10292 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010293 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10294 }
joonhunshin4ac60942023-11-15 15:23:39 +000010295
10296 enforceTelephonyFeatureWithException(callingPackage,
10297 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10298
sqian11b7a0e2018-12-05 18:48:28 -080010299 final long identity = Binder.clearCallingIdentity();
10300 try {
sqian854d44b2018-12-12 16:48:18 -080010301 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10302 for (Phone phone: PhoneFactory.getPhones()) {
10303 if (phone.getEmergencyNumberTracker() != null
10304 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10305 emergencyNumberListInternal.put(
10306 phone.getSubId(),
10307 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10308 }
sqian11b7a0e2018-12-05 18:48:28 -080010309 }
sqian854d44b2018-12-12 16:48:18 -080010310 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010311 } finally {
10312 Binder.restoreCallingIdentity(identity);
10313 }
sqianc5eccab2018-10-19 18:46:41 -070010314 }
10315
10316 @Override
sqian8c685422019-02-22 15:55:18 -080010317 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010318 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010319 if (!exactMatch) {
10320 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010321 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010322 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010323 }
joonhunshin4ac60942023-11-15 15:23:39 +000010324
10325 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10326 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10327
sqian11b7a0e2018-12-05 18:48:28 -080010328 final long identity = Binder.clearCallingIdentity();
10329 try {
sqian854d44b2018-12-12 16:48:18 -080010330 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010331 //Note: we ignore passed in param exactMatch. We can remove it once
10332 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010333 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010334 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010335 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010336 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010337 }
sqian11b7a0e2018-12-05 18:48:28 -080010338 }
10339 return false;
10340 } finally {
10341 Binder.restoreCallingIdentity(identity);
10342 }
10343 }
10344
sqianf4ca7ed2019-01-15 18:32:07 -080010345 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010346 * Start emergency callback mode for GsmCdmaPhone for testing.
10347 */
10348 @Override
10349 public void startEmergencyCallbackMode() {
10350 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10351 "startEmergencyCallbackMode");
10352 enforceModifyPermission();
10353 final long identity = Binder.clearCallingIdentity();
10354 try {
10355 for (Phone phone : PhoneFactory.getPhones()) {
10356 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10357 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10358 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10359 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10360 gsmCdmaPhone.obtainMessage(
10361 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10362 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10363 }
10364 }
10365 } finally {
10366 Binder.restoreCallingIdentity(identity);
10367 }
10368 }
10369
10370 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010371 * Update emergency number list for test mode.
10372 */
10373 @Override
10374 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10375 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10376 "updateEmergencyNumberListTestMode");
10377
10378 final long identity = Binder.clearCallingIdentity();
10379 try {
10380 for (Phone phone: PhoneFactory.getPhones()) {
10381 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10382 if (tracker != null) {
10383 tracker.executeEmergencyNumberTestModeCommand(action, num);
10384 }
10385 }
10386 } finally {
10387 Binder.restoreCallingIdentity(identity);
10388 }
10389 }
10390
10391 /**
10392 * Get the full emergency number list for test mode.
10393 */
10394 @Override
10395 public List<String> getEmergencyNumberListTestMode() {
10396 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10397 "getEmergencyNumberListTestMode");
10398
10399 final long identity = Binder.clearCallingIdentity();
10400 try {
10401 Set<String> emergencyNumbers = new HashSet<>();
10402 for (Phone phone: PhoneFactory.getPhones()) {
10403 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10404 if (tracker != null) {
10405 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10406 emergencyNumbers.add(num.getNumber());
10407 }
10408 }
10409 }
10410 return new ArrayList<>(emergencyNumbers);
10411 } finally {
10412 Binder.restoreCallingIdentity(identity);
10413 }
10414 }
10415
chen xud6b45bd2018-10-30 22:27:10 -070010416 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010417 public int getEmergencyNumberDbVersion(int subId) {
10418 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10419
joonhunshin4ac60942023-11-15 15:23:39 +000010420 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10421 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10422
Shuo Qian3b6ee772019-11-13 17:43:31 -080010423 final long identity = Binder.clearCallingIdentity();
10424 try {
10425 final Phone phone = getPhone(subId);
10426 if (phone == null) {
10427 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10428 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10429 }
10430 return phone.getEmergencyNumberDbVersion();
10431 } finally {
10432 Binder.restoreCallingIdentity(identity);
10433 }
10434 }
10435
10436 @Override
10437 public void notifyOtaEmergencyNumberDbInstalled() {
10438 enforceModifyPermission();
10439
joonhunshin4ac60942023-11-15 15:23:39 +000010440 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10441 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10442
Shuo Qian3b6ee772019-11-13 17:43:31 -080010443 final long identity = Binder.clearCallingIdentity();
10444 try {
10445 for (Phone phone: PhoneFactory.getPhones()) {
10446 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10447 if (tracker != null) {
10448 tracker.updateOtaEmergencyNumberDatabase();
10449 }
10450 }
10451 } finally {
10452 Binder.restoreCallingIdentity(identity);
10453 }
10454 }
10455
10456 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010457 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010458 enforceActiveEmergencySessionPermission();
10459
joonhunshin4ac60942023-11-15 15:23:39 +000010460 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10461 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10462
Shuo Qian3b6ee772019-11-13 17:43:31 -080010463 final long identity = Binder.clearCallingIdentity();
10464 try {
10465 for (Phone phone: PhoneFactory.getPhones()) {
10466 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10467 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010468 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10469 }
10470 }
10471 } finally {
10472 Binder.restoreCallingIdentity(identity);
10473 }
10474 }
10475
10476 @Override
10477 public void resetOtaEmergencyNumberDbFilePath() {
10478 enforceActiveEmergencySessionPermission();
10479
joonhunshin4ac60942023-11-15 15:23:39 +000010480 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10481 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10482
Shuo Qianc373f112020-03-05 17:55:34 -080010483 final long identity = Binder.clearCallingIdentity();
10484 try {
10485 for (Phone phone: PhoneFactory.getPhones()) {
10486 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10487 if (tracker != null) {
10488 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010489 }
10490 }
10491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 }
10495
10496 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010497 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10498 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10499 Phone phone = getPhone(subId);
10500 if (phone == null) {
10501 return null;
10502 }
10503 final long identity = Binder.clearCallingIdentity();
10504 try {
10505 UiccProfile profile = UiccController.getInstance()
10506 .getUiccProfileForPhone(phone.getPhoneId());
10507 if (profile != null) {
10508 return profile.getCertsFromCarrierPrivilegeAccessRules();
10509 }
10510 } finally {
10511 Binder.restoreCallingIdentity(identity);
10512 }
10513 return null;
10514 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010515
10516 /**
10517 * Enable or disable a modem stack.
10518 */
10519 @Override
10520 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10521 enforceModifyPermission();
10522
joonhunshin4ac60942023-11-15 15:23:39 +000010523 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10524 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10525
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010526 final long identity = Binder.clearCallingIdentity();
10527 try {
10528 Phone phone = PhoneFactory.getPhone(slotIndex);
10529 if (phone == null) {
10530 return false;
10531 } else {
10532 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10533 }
10534 } finally {
10535 Binder.restoreCallingIdentity(identity);
10536 }
10537 }
Michelecea4cf22018-12-21 15:00:11 -080010538
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010539 /**
10540 * Whether a modem stack is enabled or not.
10541 */
10542 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010543 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10544 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010545 Phone phone = PhoneFactory.getPhone(slotIndex);
10546 if (phone == null) return false;
10547
10548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010549 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10550 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010551 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10552 }
10553
joonhunshin4ac60942023-11-15 15:23:39 +000010554 enforceTelephonyFeatureWithException(callingPackage,
10555 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10556
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010557 final long identity = Binder.clearCallingIdentity();
10558 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010559 try {
10560 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10561 } catch (NoSuchElementException ex) {
10562 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10563 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010564 } finally {
10565 Binder.restoreCallingIdentity(identity);
10566 }
10567 }
10568
Michelecea4cf22018-12-21 15:00:11 -080010569 @Override
Michele0ea7d782019-03-19 14:58:42 -070010570 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010571 enforceModifyPermission();
10572
joonhunshin4ac60942023-11-15 15:23:39 +000010573 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10574 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10575
Michelecea4cf22018-12-21 15:00:11 -080010576 final long identity = Binder.clearCallingIdentity();
10577 try {
10578 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010579 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010580 .commit();
10581 } finally {
10582 Binder.restoreCallingIdentity(identity);
10583 }
10584 }
10585
10586 @Override
Michele0ea7d782019-03-19 14:58:42 -070010587 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010588 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010590 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10591 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010592 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010593 }
Michelecea4cf22018-12-21 15:00:11 -080010594
joonhunshin4ac60942023-11-15 15:23:39 +000010595 enforceTelephonyFeatureWithException(callingPackage,
10596 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10597
Michelecea4cf22018-12-21 15:00:11 -080010598 final long identity = Binder.clearCallingIdentity();
10599 try {
Michele0ea7d782019-03-19 14:58:42 -070010600 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010601 } finally {
10602 Binder.restoreCallingIdentity(identity);
10603 }
10604 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010605
Michele0ea7d782019-03-19 14:58:42 -070010606 @TelephonyManager.IsMultiSimSupportedResult
10607 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010608 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10609 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10610 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010611 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10612 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010613 }
10614 // Check if the hardware supports multisim functionality. If usage of multisim is not
10615 // supported by the modem, indicate that it is restricted.
10616 PhoneCapability staticCapability =
10617 mPhoneConfigurationManager.getStaticPhoneCapability();
10618 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010619 loge("isMultiSimSupportedInternal: no static configuration available");
10620 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010621 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010622 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010623 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10624 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010625 }
10626 // Check if support of multiple SIMs is restricted by carrier
10627 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010628 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010629 }
10630
Michele0ea7d782019-03-19 14:58:42 -070010631 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010632 }
10633
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010634 /**
10635 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010636 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10637 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10638 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010639 * @param numOfSims number of active sims we want to switch to
10640 */
10641 @Override
10642 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010643 if (numOfSims == 1) {
10644 enforceModifyPermission();
10645 } else {
10646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10647 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10648 }
joonhunshin4ac60942023-11-15 15:23:39 +000010649
10650 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10651 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10652
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010653 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010654
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010655 try {
Michele30b57b22019-03-01 12:01:14 -080010656 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010657 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010658 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10659 return;
10660 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010661 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10662 } finally {
10663 Binder.restoreCallingIdentity(identity);
10664 }
10665 }
10666
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010667 @Override
10668 public boolean isApplicationOnUicc(int subId, int appType) {
10669 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010670
10671 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10672 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10673
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010674 Phone phone = getPhone(subId);
10675 if (phone == null) {
10676 return false;
10677 }
10678 final long identity = Binder.clearCallingIdentity();
10679 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010680 UiccPort uiccPort = phone.getUiccPort();
10681 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010682 return false;
10683 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010684 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010685 if (uiccProfile == null) {
10686 return false;
10687 }
10688 if (TelephonyManager.APPTYPE_SIM <= appType
10689 && appType <= TelephonyManager.APPTYPE_ISIM) {
10690 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10691 }
10692 return false;
10693 } finally {
10694 Binder.restoreCallingIdentity(identity);
10695 }
10696 }
10697
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010698 /**
chen xub4baa772019-04-03 10:23:41 -070010699 * Get whether making changes to modem configurations will trigger reboot.
10700 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010701 */
10702 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010703 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10704 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010706 mApp, subId, callingPackage, callingFeatureId,
10707 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010708 return false;
10709 }
joonhunshin4ac60942023-11-15 15:23:39 +000010710
10711 enforceTelephonyFeatureWithException(callingPackage,
10712 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10713 "doesSwitchMultiSimConfigTriggerReboot");
10714
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010715 final long identity = Binder.clearCallingIdentity();
10716 try {
10717 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10718 } finally {
10719 Binder.restoreCallingIdentity(identity);
10720 }
10721 }
10722
Nathan Harold29f5f052019-02-15 13:41:57 -080010723 private void updateModemStateMetrics() {
10724 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10725 // TODO: check the state for each modem if the api is ready.
10726 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10727 }
10728
Pengquan Meng3889a572019-01-23 11:16:29 -080010729 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010730 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010731 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010732 // Verify that the callingPackage belongs to the calling UID
10733 mApp.getSystemService(AppOpsManager.class)
10734 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010735
10736 enforceTelephonyFeatureWithException(callingPackage,
10737 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10738
Pengquan Meng3889a572019-01-23 11:16:29 -080010739 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010740 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010741 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010742 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10743 if (slotInfos != null) {
10744 for (int i = 0; i < slotInfos.length; i++) {
10745 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10746 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10747 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10748 portInfo.getLogicalSlotIndex()));
10749 }
10750 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010751 }
10752 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010753 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010754 } finally {
10755 Binder.restoreCallingIdentity(identity);
10756 }
10757 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010758
10759 /**
10760 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010761 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010762 */
jimsunf9ec1622022-09-13 21:18:43 +080010763 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010764 @Override
10765 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010766 return getHalVersion(HAL_SERVICE_RADIO);
10767 }
10768
10769 /**
10770 * Get the HAL Version of a specific service
10771 */
10772 @Override
10773 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010774 Phone phone = getDefaultPhone();
10775 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010776 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010777 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10778 return hv.major * 100 + hv.minor;
10779 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010780
10781 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010782 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010783 *
10784 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010785 */
10786 @Override
sangyun097dcf72024-01-04 10:35:49 +090010787 public @Nullable String getCurrentPackageName() {
10788 PackageManager pm = mApp.getPackageManager();
10789 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10790 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010791 }
10792
10793 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010794 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10795 * corresponding network requests on a subId.
10796 *
10797 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010798 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010799 * 2) APN is un-metered for this subscription, or
10800 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010801 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010802 *
10803 * @return whether data is allowed for a apn type.
10804 *
10805 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010806 */
10807 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010808 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010809 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10810 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010811
joonhunshin4ac60942023-11-15 15:23:39 +000010812 enforceTelephonyFeatureWithException(callingPackage,
10813 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10814
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010815 // Now that all security checks passes, perform the operation as ourselves.
10816 final long identity = Binder.clearCallingIdentity();
10817 try {
10818 Phone phone = getPhone(subId);
10819 if (phone == null) return false;
10820
Jack Yu27422a52022-03-21 10:38:05 -070010821 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010822 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010823 isMetered = phone.getDataNetworkController().getDataConfigManager()
10824 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10825 phone.getServiceState().getDataRoaming());
10826 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010827 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831 }
10832
10833 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010834 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010835 enforceReadPrivilegedPermission("isApnMetered");
10836
joonhunshin4ac60942023-11-15 15:23:39 +000010837 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10838 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10839
Malcolm Chene5ad5792019-04-18 13:51:02 -070010840 // Now that all security checks passes, perform the operation as ourselves.
10841 final long identity = Binder.clearCallingIdentity();
10842 try {
10843 Phone phone = getPhone(subId);
10844 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010845 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10846 DataUtils.apnTypeToNetworkCapability(apnType),
10847 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010848 } finally {
10849 Binder.restoreCallingIdentity(identity);
10850 }
10851 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010852
10853 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010854 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10855 int subscriptionId, IBooleanConsumer resultCallback) {
10856 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010857
10858 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10859 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10860
Hall Liu73f5d362020-01-20 13:42:00 -080010861 long token = Binder.clearCallingIdentity();
10862 try {
10863 Phone phone = getPhone(subscriptionId);
10864 if (phone == null) {
10865 try {
10866 if (resultCallback != null) {
10867 resultCallback.accept(false);
10868 }
10869 } catch (RemoteException e) {
10870 // ignore
10871 }
10872 return;
10873 }
10874 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10875 Pair.create(specifiers, (x) -> {
10876 try {
10877 if (resultCallback != null) {
10878 resultCallback.accept(x);
10879 }
10880 } catch (RemoteException e) {
10881 // ignore
10882 }
10883 });
10884 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10885 } finally {
10886 Binder.restoreCallingIdentity(token);
10887 }
10888 }
10889
10890 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010891 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10892 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010893 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010894 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010895
10896 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10897 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10898
Sarah Chin679c08a2020-11-18 13:39:35 -080010899 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10900 final long identity = Binder.clearCallingIdentity();
10901 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010902 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10903 if (result instanceof IllegalStateException) {
10904 throw (IllegalStateException) result;
10905 }
10906 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010907 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10908 return specifiers;
10909 } finally {
10910 Binder.restoreCallingIdentity(identity);
10911 }
10912 }
10913
10914 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010915 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010916 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010917
10918 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10919 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10920
Jack Yu8b766fc2022-03-21 09:42:33 -070010921 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010922 }
10923
10924 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010925 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10926 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010927 if (callingPackage == null) {
10928 callingPackage = getCurrentPackageName();
10929 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010930 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10931 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010932 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10933 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010934 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10935 }
10936 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10937 Intent intent = new Intent();
10938 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10939 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10940 // Bring up choose default SMS subscription dialog right now
10941 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10942 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10943 mApp.startActivity(intent);
10944 }
chen xud5ca2d52019-05-28 15:20:57 -070010945
10946 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010947 public void showSwitchToManagedProfileDialog() {
10948 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000010949 try {
10950 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
10951 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
10952 // for work telephony.
10953 Intent intent = new Intent(Intent.ACTION_SENDTO);
10954 intent.setData(Uri.parse("smsto:"));
10955 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10956 mApp.startActivity(intent);
10957 } catch (ActivityNotFoundException e) {
10958 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
10959 Intent intent = new Intent();
10960 intent.setClass(mApp, ErrorDialogActivity.class);
10961 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10962 mApp.startActivity(intent);
10963 }
Ayush Sharma787854b2022-12-12 14:55:02 +000010964 }
10965
10966 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010967 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010968 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10969 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
10970
chen xud5ca2d52019-05-28 15:20:57 -070010971 //TODO investigate if this API should require proper permission check in R b/133791609
10972 final long identity = Binder.clearCallingIdentity();
10973 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010974 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10975 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10976 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10977 return carrierUAProfUrl;
10978 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010979 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10980 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010981 } finally {
10982 Binder.restoreCallingIdentity(identity);
10983 }
10984 }
10985
10986 @Override
10987 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000010988 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10989 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
10990
chen xud5ca2d52019-05-28 15:20:57 -070010991 //TODO investigate if this API should require proper permission check in R b/133791609
10992 final long identity = Binder.clearCallingIdentity();
10993 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010994 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10995 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10996 if (!TextUtils.isEmpty(carrierUserAgent)) {
10997 return carrierUserAgent;
10998 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010999 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11000 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011001 } finally {
11002 Binder.restoreCallingIdentity(identity);
11003 }
11004 }
Jack Yub07d4972019-05-28 16:12:25 -070011005
11006 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011007 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11008 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011009
joonhunshin4ac60942023-11-15 15:23:39 +000011010 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11011 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11012
Jack Yub07d4972019-05-28 16:12:25 -070011013 final long identity = Binder.clearCallingIdentity();
11014 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011015 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011016 if (phone == null) return false;
11017
Ling Maf188d502022-09-16 15:22:36 -070011018 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011019 } finally {
11020 Binder.restoreCallingIdentity(identity);
11021 }
11022 }
11023
11024 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011025 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011026 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011027 enforceModifyPermission();
11028
joonhunshin4ac60942023-11-15 15:23:39 +000011029 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11030 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11031
changbettyd5c246e2019-12-24 15:40:37 +080011032 final long identity = Binder.clearCallingIdentity();
11033 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011034 Phone phone = getPhone(subscriptionId);
11035 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011036
Ling Maf188d502022-09-16 15:22:36 -070011037 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011038 } finally {
11039 Binder.restoreCallingIdentity(identity);
11040 }
11041 }
11042
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011043 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011044 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011045 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11046 * otherwise.
11047 */
11048 @Override
11049 public void setCepEnabled(boolean isCepEnabled) {
11050 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11051
11052 final long identity = Binder.clearCallingIdentity();
11053 try {
11054 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11055 for (Phone phone : PhoneFactory.getPhones()) {
11056 Phone defaultPhone = phone.getImsPhone();
11057 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11058 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11059 ImsPhoneCallTracker imsPhoneCallTracker =
11060 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11061 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11062 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11063 + imsPhone.getMsisdn());
11064 }
11065 }
11066 } finally {
11067 Binder.restoreCallingIdentity(identity);
11068 }
11069 }
allenwtsu46dcc572020-01-08 18:24:03 +080011070
11071 /**
11072 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11073 *
11074 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11075 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11076 * before being read.
11077 */
11078 @Override
11079 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11080 isCompressed) {
11081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11082 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011083 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11084 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11085 }
joonhunshin4ac60942023-11-15 15:23:39 +000011086
11087 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11088 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11089 Binder.getCallingUserHandle())) {
11090 if (!isImsAvailableOnDevice()) {
11091 // ProvisioningManager can not handle ServiceSpecificException.
11092 // Throw the IllegalStateException and annotate ProvisioningManager.
11093 throw new IllegalStateException("IMS not available on device.");
11094 }
11095 } else {
11096 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11097 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11098 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011099 }
11100
11101 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011102 try {
Hui Wang761a6682020-10-31 05:12:53 +000011103 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11104 } finally {
11105 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011106 }
11107 }
zoey chene02881a2019-12-30 16:11:23 +080011108
11109 @Override
11110 public boolean isIccLockEnabled(int subId) {
11111 enforceReadPrivilegedPermission("isIccLockEnabled");
11112
joonhunshin4ac60942023-11-15 15:23:39 +000011113 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11114 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11115
zoey chene02881a2019-12-30 16:11:23 +080011116 // Now that all security checks passes, perform the operation as ourselves.
11117 final long identity = Binder.clearCallingIdentity();
11118 try {
11119 Phone phone = getPhone(subId);
11120 if (phone != null && phone.getIccCard() != null) {
11121 return phone.getIccCard().getIccLockEnabled();
11122 } else {
11123 return false;
11124 }
11125 } finally {
11126 Binder.restoreCallingIdentity(identity);
11127 }
11128 }
11129
11130 /**
11131 * Set the ICC pin lock enabled or disabled.
11132 *
11133 * @return an integer representing the status of IccLock enabled or disabled in the following
11134 * three cases:
11135 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11136 * successfully.
11137 * - Positive number and zero for remaining password attempts.
11138 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11139 *
11140 */
11141 @Override
11142 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11143 enforceModifyPermission();
11144
joonhunshin4ac60942023-11-15 15:23:39 +000011145 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11146 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11147
zoey chene02881a2019-12-30 16:11:23 +080011148 Phone phone = getPhone(subId);
11149 if (phone == null) {
11150 return 0;
11151 }
11152 // Now that all security checks passes, perform the operation as ourselves.
11153 final long identity = Binder.clearCallingIdentity();
11154 try {
11155 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11156 new Pair<Boolean, String>(enabled, password), phone, null);
11157 return attemptsRemaining;
11158
11159 } catch (Exception e) {
11160 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11161 } finally {
11162 Binder.restoreCallingIdentity(identity);
11163 }
11164 return 0;
11165 }
11166
11167 /**
11168 * Change the ICC password used in ICC pin lock.
11169 *
11170 * @return an integer representing the status of IccLock changed in the following three cases:
11171 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11172 * - Positive number and zero for remaining password attempts.
11173 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11174 *
11175 */
11176 @Override
11177 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11178 enforceModifyPermission();
11179
joonhunshin4ac60942023-11-15 15:23:39 +000011180 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11181 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11182
zoey chene02881a2019-12-30 16:11:23 +080011183 Phone phone = getPhone(subId);
11184 if (phone == null) {
11185 return 0;
11186 }
11187 // Now that all security checks passes, perform the operation as ourselves.
11188 final long identity = Binder.clearCallingIdentity();
11189 try {
11190 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11191 new Pair<String, String>(oldPassword, newPassword), phone, null);
11192 return attemptsRemaining;
11193
11194 } catch (Exception e) {
11195 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11196 } finally {
11197 Binder.restoreCallingIdentity(identity);
11198 }
11199 return 0;
11200 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011201
11202 /**
11203 * Request for receiving user activity notification
11204 */
11205 @Override
11206 public void requestUserActivityNotification() {
11207 if (!mNotifyUserActivity.get()
11208 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11209 mNotifyUserActivity.set(true);
11210 }
11211 }
11212
11213 /**
11214 * Called when userActivity is signalled in the power manager.
11215 * This is safe to call from any thread, with any window manager locks held or not.
11216 */
11217 @Override
11218 public void userActivity() {
11219 // ***************************************
11220 // * Inherited from PhoneWindowManager *
11221 // ***************************************
11222 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11223 // WITH ITS LOCKS HELD.
11224 //
11225 // This code must be VERY careful about the locks
11226 // it acquires.
11227 // In fact, the current code acquires way too many,
11228 // and probably has lurking deadlocks.
11229
11230 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11231 throw new SecurityException("Only the OS may call notifyUserActivity()");
11232 }
11233
11234 if (mNotifyUserActivity.getAndSet(false)) {
11235 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11236 USER_ACTIVITY_NOTIFICATION_DELAY);
11237 }
11238 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011239
11240 @Override
11241 public boolean canConnectTo5GInDsdsMode() {
11242 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11243 }
Jack Yud10cdd42020-09-28 20:28:01 -070011244
11245 @Override
11246 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11247 String callingFeatureId) {
11248 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11249 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11250 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11251 }
11252
joonhunshin4ac60942023-11-15 15:23:39 +000011253 enforceTelephonyFeatureWithException(callingPackage,
11254 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11255
Jack Yud10cdd42020-09-28 20:28:01 -070011256 Phone phone = getPhone(subId);
11257 if (phone == null) {
11258 throw new RuntimeException("phone is not available");
11259 }
11260 // Now that all security checks passes, perform the operation as ourselves.
11261 final long identity = Binder.clearCallingIdentity();
11262 try {
11263 return phone.getEquivalentHomePlmns();
11264 } finally {
11265 Binder.restoreCallingIdentity(identity);
11266 }
11267 }
Daniel Bright59e67312020-11-13 11:49:37 -080011268
11269 @Override
11270 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011271 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
joonhunshin4ac60942023-11-15 15:23:39 +000011272 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11273 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11274 "isRadioInterfaceCapabilitySupported");
11275
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011276 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011277 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011278 if (radioInterfaceCapabilities == null) {
11279 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011280 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011281 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011282 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011283
Hui Wang641e81c2020-10-12 12:14:23 -070011284 @Override
11285 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11286 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011287 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11288 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11289 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11290 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11291 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011292
11293 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11294 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11295
Hui Wang641e81c2020-10-12 12:14:23 -070011296 if (DBG) {
11297 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11298 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11299 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11300 }
11301
11302 if (!SubscriptionManager.isValidSubscriptionId(subId)
11303 || appType < TelephonyManager.APPTYPE_UNKNOWN
11304 || appType > TelephonyManager.APPTYPE_ISIM
11305 || nafUrl == null || securityProtocol == null || callback == null) {
11306 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11307 if (callback != null) {
11308 try {
11309 callback.onAuthenticationFailure(
11310 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11311 } catch (RemoteException exception) {
11312 log("Fail to notify onAuthenticationFailure due to " + exception);
11313 }
11314 return;
11315 }
11316 }
11317
11318 final long token = Binder.clearCallingIdentity();
11319 try {
11320 getGbaManager(subId).bootstrapAuthenticationRequest(
11321 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011322 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011323 } finally {
11324 Binder.restoreCallingIdentity(token);
11325 }
11326 }
11327
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011328 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011329 * Attempts to set the radio power state for all phones for thermal reason.
11330 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011331 * requested radio power state will actually be set. See {@link
11332 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11333 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011334 * @param enable {@code true} if trying to turn radio on.
11335 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11336 * false}.
11337 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011338 private boolean setRadioPowerForThermal(boolean enable) {
11339 boolean isPhoneAvailable = false;
11340 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11341 Phone phone = PhoneFactory.getPhone(i);
11342 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011343 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011344 isPhoneAvailable = true;
11345 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011346 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011347
11348 // return true if successfully informed the phone object about the thermal radio power
11349 // request.
11350 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011351 }
11352
11353 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011354 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011355 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11356 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11357 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11358 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11359 throw new IllegalArgumentException("modem does not support data throttling");
11360 }
11361
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011362 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11363 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011364 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011365 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11366 }
11367
Sarah Chinecc78c42022-03-31 21:16:48 -070011368 setDataEnabledForReason(
11369 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011370
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011371 if (isDataThrottlingSupported) {
11372 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011373 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011374 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11375 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11376 } else if (thermalMitigationResult
11377 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011378 log("Modem likely does not support data throttling on secondary carrier. Data " +
11379 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11380 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011381 }
11382 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011383 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011384
11385 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011386 }
11387
Jack Nudelman644b91a2021-03-12 14:09:48 -080011388 private static List<String> getThermalMitigationAllowlist(Context context) {
11389 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11390 for (String pckg : context.getResources()
11391 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11392 sThermalMitigationAllowlistedPackages.add(pckg);
11393 }
11394 }
11395
11396 return sThermalMitigationAllowlistedPackages;
11397 }
11398
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011399 private boolean isAnyPhoneInEmergencyState() {
11400 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11401 if (tm.isInEmergencyCall()) {
11402 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11403 return true;
11404 }
11405 for (Phone phone : PhoneFactory.getPhones()) {
11406 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11407 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011408 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11409 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011410 return true;
11411 }
11412 }
11413
11414 return false;
11415 }
11416
Jack Nudelman644b91a2021-03-12 14:09:48 -080011417 /**
11418 * Used by shell commands to add an authorized package name for thermal mitigation.
11419 * @param packageName name of package to be allowlisted
11420 * @param context
11421 */
11422 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11423 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11424 sThermalMitigationAllowlistedPackages.add(packageName);
11425 }
11426
11427 /**
11428 * Used by shell commands to remove an authorized package name for thermal mitigation.
11429 * @param packageName name of package to remove from allowlist
11430 * @param context
11431 */
11432 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11433 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11434 sThermalMitigationAllowlistedPackages.remove(packageName);
11435 }
11436
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011437 /**
11438 * Thermal mitigation request to control functionalities at modem.
11439 *
11440 * @param subId the id of the subscription.
11441 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011442 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011443 *
11444 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11445 */
11446 @Override
11447 @ThermalMitigationResult
11448 public int sendThermalMitigationRequest(
11449 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011450 ThermalMitigationRequest thermalMitigationRequest,
11451 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011452 enforceModifyPermission();
11453
Jack Nudelman644b91a2021-03-12 14:09:48 -080011454 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011455
11456 enforceTelephonyFeatureWithException(callingPackage,
11457 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11458
Jack Nudelman644b91a2021-03-12 14:09:48 -080011459 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11460 .contains(callingPackage)) {
11461 throw new SecurityException("Calling package must be configured in the device config. "
11462 + "calling package: " + callingPackage);
11463 }
11464
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011465 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11466 final long identity = Binder.clearCallingIdentity();
11467
11468 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11469 try {
11470 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11471 switch (thermalMitigationAction) {
11472 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11473 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011474 handleDataThrottlingRequest(subId,
11475 thermalMitigationRequest.getDataThrottlingRequest(),
11476 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011477 break;
11478 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11479 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11480 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11481 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11482 }
11483
11484 // Ensure that radio is on. If not able to power on due to phone being
11485 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011486 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011487 thermalMitigationResult =
11488 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11489 break;
11490 }
11491
11492 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011493 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011494 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11495 break;
11496 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11497 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11498 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11499 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11500 }
11501
11502 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11503 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011504 Phone phone = getPhone(subId);
11505 if (phone == null) {
11506 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011507 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011508 break;
11509 }
11510
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011511 TelephonyConnectionService service =
11512 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011513 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011514 Log.e(LOG_TAG, "An emergency call is pending");
11515 thermalMitigationResult =
11516 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11517 break;
11518 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011519 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011520 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011521 break;
11522 }
11523 } else {
11524 thermalMitigationResult =
11525 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11526 break;
11527 }
11528
11529 // Turn radio off. If not able to power off due to phone being unavailable,
11530 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011531 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011532 thermalMitigationResult =
11533 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11534 break;
11535 }
11536 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011537 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011538 break;
11539 default:
11540 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11541 + "not exist. Requested action: " + thermalMitigationAction);
11542 }
11543 } catch (IllegalArgumentException e) {
11544 throw e;
11545 } catch (Exception e) {
11546 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11547 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11548 } finally {
11549 Binder.restoreCallingIdentity(identity);
11550 }
11551
11552 if (DBG) {
11553 log("thermalMitigationRequest returning with thermalMitigationResult: "
11554 + thermalMitigationResult);
11555 }
11556
11557 return thermalMitigationResult;
11558 }
Hui Wang641e81c2020-10-12 12:14:23 -070011559
11560 /**
11561 * Set the GbaService Package Name that Telephony will bind to.
11562 *
11563 * @param subId The sim that the GbaService is associated with.
11564 * @param packageName The name of the package to be replaced with.
11565 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11566 */
11567 @Override
11568 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11569 enforceModifyPermission();
11570
11571 final long identity = Binder.clearCallingIdentity();
11572 try {
11573 return getGbaManager(subId).overrideServicePackage(packageName);
11574 } finally {
11575 Binder.restoreCallingIdentity(identity);
11576 }
11577 }
11578
11579 /**
11580 * Return the package name of the currently bound GbaService.
11581 *
11582 * @param subId The sim that the GbaService is associated with.
11583 * @return the package name of the GbaService configuration, null if GBA is not supported.
11584 */
11585 @Override
11586 public String getBoundGbaService(int subId) {
11587 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11588
11589 final long identity = Binder.clearCallingIdentity();
11590 try {
11591 return getGbaManager(subId).getServicePackage();
11592 } finally {
11593 Binder.restoreCallingIdentity(identity);
11594 }
11595 }
11596
11597 /**
11598 * Set the release time for telephony to unbind GbaService.
11599 *
11600 * @param subId The sim that the GbaService is associated with.
11601 * @param interval The release time to unbind GbaService by millisecond.
11602 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11603 */
11604 @Override
11605 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11606 enforceModifyPermission();
11607
11608 final long identity = Binder.clearCallingIdentity();
11609 try {
11610 return getGbaManager(subId).overrideReleaseTime(interval);
11611 } finally {
11612 Binder.restoreCallingIdentity(identity);
11613 }
11614 }
11615
11616 /**
11617 * Return the release time for telephony to unbind GbaService.
11618 *
11619 * @param subId The sim that the GbaService is associated with.
11620 * @return The release time to unbind GbaService by millisecond.
11621 */
11622 @Override
11623 public int getGbaReleaseTime(int subId) {
11624 enforceReadPrivilegedPermission("getGbaReleaseTime");
11625
11626 final long identity = Binder.clearCallingIdentity();
11627 try {
11628 return getGbaManager(subId).getReleaseTime();
11629 } finally {
11630 Binder.restoreCallingIdentity(identity);
11631 }
11632 }
11633
11634 private GbaManager getGbaManager(int subId) {
11635 GbaManager instance = GbaManager.getInstance(subId);
11636 if (instance == null) {
11637 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11638 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11639 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11640 }
11641 return instance;
11642 }
Hui Wang761a6682020-10-31 05:12:53 +000011643
11644 /**
11645 * indicate whether the device and the carrier can support
11646 * RCS VoLTE single registration.
11647 */
11648 @Override
11649 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011650 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11651 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11652 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11653 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011654
11655 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11656 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11657 }
11658
11659 final long identity = Binder.clearCallingIdentity();
11660 try {
11661 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11662 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011663 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11664 if (isCapable != null) {
11665 return isCapable;
11666 }
Hui Wang761a6682020-10-31 05:12:53 +000011667 }
Hui Wang67af90e2021-06-04 16:57:15 -070011668 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11669 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011670 } finally {
11671 Binder.restoreCallingIdentity(identity);
11672 }
11673 }
11674
11675 /**
11676 * Register RCS provisioning callback.
11677 */
11678 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011679 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011680 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011681 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011682 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011683 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11684 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011685
11686 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11687 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11688 }
joonhunshin4ac60942023-11-15 15:23:39 +000011689 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11690 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11691 Binder.getCallingUserHandle())) {
11692 if (!isImsAvailableOnDevice()) {
11693 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11694 "IMS not available on device.");
11695 }
11696 } else {
11697 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11698 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011699 }
11700
11701 final long identity = Binder.clearCallingIdentity();
11702 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011703 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011704 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011705 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11706 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011707 }
Hui Wang761a6682020-10-31 05:12:53 +000011708 } finally {
11709 Binder.restoreCallingIdentity(identity);
11710 }
11711 }
11712
11713 /**
11714 * Unregister RCS provisioning callback.
11715 */
11716 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011717 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011718 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011719 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011720 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011721 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11722 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011723
11724 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11725 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11726 }
joonhunshin4ac60942023-11-15 15:23:39 +000011727
11728 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11729 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11730 Binder.getCallingUserHandle())) {
11731 if (!isImsAvailableOnDevice()) {
11732 // operation failed silently
11733 Rlog.w(LOG_TAG, "IMS not available on device.");
11734 return;
11735 }
11736 } else {
11737 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11738 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11739 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011740 }
11741
11742 final long identity = Binder.clearCallingIdentity();
11743 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011744 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011745 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011746 } finally {
11747 Binder.restoreCallingIdentity(identity);
11748 }
11749 }
11750
11751 /**
11752 * trigger RCS reconfiguration.
11753 */
11754 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011755 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11756 "triggerRcsReconfiguration",
11757 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011758
11759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11760 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11761 }
joonhunshin4ac60942023-11-15 15:23:39 +000011762 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11763 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11764 Binder.getCallingUserHandle())) {
11765 if (!isImsAvailableOnDevice()) {
11766 // ProvisioningManager can not handle ServiceSpecificException.
11767 // Throw the IllegalStateException and annotate ProvisioningManager.
11768 throw new IllegalStateException("IMS not available on device.");
11769 }
11770 } else {
11771 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11772 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011773 }
11774
11775 final long identity = Binder.clearCallingIdentity();
11776 try {
11777 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11778 } finally {
11779 Binder.restoreCallingIdentity(identity);
11780 }
11781 }
11782
11783 /**
11784 * Provide the client configuration parameters of the RCS application.
11785 */
11786 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011787 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11788 "setRcsClientConfiguration",
11789 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011790
11791 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11792 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11793 }
joonhunshin4ac60942023-11-15 15:23:39 +000011794 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11795 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11796 Binder.getCallingUserHandle())) {
11797 if (!isImsAvailableOnDevice()) {
11798 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11799 "IMS not available on device.");
11800 }
11801 } else {
11802 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11803 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011804 }
11805
11806 final long identity = Binder.clearCallingIdentity();
11807
11808 try {
11809 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11810 if (configBinder == null) {
11811 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011812 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11813 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011814 } else {
11815 configBinder.setRcsClientConfiguration(rcc);
11816 }
joonhunshin3e154242021-09-17 06:33:39 +000011817
11818 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11819 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011820 } catch (RemoteException e) {
11821 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011822 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11823 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011824 } finally {
11825 Binder.restoreCallingIdentity(identity);
11826 }
11827 }
11828
11829 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011830 * Enables or disables the test mode for RCS VoLTE single registration.
11831 */
11832 @Override
11833 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11834 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11835 "setRcsSingleRegistrationTestModeEnabled");
11836
11837 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11838 }
11839
11840 /**
11841 * Gets the test mode for RCS VoLTE single registration.
11842 */
11843 @Override
11844 public boolean getRcsSingleRegistrationTestModeEnabled() {
11845 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11846 "getRcsSingleRegistrationTestModeEnabled");
11847
11848 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11849 }
11850
11851 /**
Hui Wang761a6682020-10-31 05:12:53 +000011852 * Overrides the config of RCS VoLTE single registration enabled for the device.
11853 */
11854 @Override
11855 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11857 "setDeviceSingleRegistrationEnabledOverride");
11858 enforceModifyPermission();
11859
11860 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11861 : Boolean.parseBoolean(enabledStr);
11862 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011863 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011864 }
11865
11866 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011867 * Sends a device to device communication message. Only usable via shell.
11868 * @param message message to send.
11869 * @param value message value.
11870 */
11871 @Override
11872 public void sendDeviceToDeviceMessage(int message, int value) {
11873 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011874 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011875 enforceModifyPermission();
11876
11877 final long identity = Binder.clearCallingIdentity();
11878 try {
11879 TelephonyConnectionService service =
11880 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11881 if (service == null) {
11882 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11883 return;
11884 }
11885 service.sendTestDeviceToDeviceMessage(message, value);
11886 } finally {
11887 Binder.restoreCallingIdentity(identity);
11888 }
11889 }
11890
Tyler Gunnbabbda02021-02-10 11:05:02 -080011891 /**
11892 * Sets the specified device to device transport active.
11893 * @param transport The transport to set active.
11894 */
11895 @Override
11896 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11897 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11898 "setActiveDeviceToDeviceTransport");
11899 enforceModifyPermission();
11900
11901 final long identity = Binder.clearCallingIdentity();
11902 try {
11903 TelephonyConnectionService service =
11904 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11905 if (service == null) {
11906 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11907 return;
11908 }
11909 service.setActiveDeviceToDeviceTransport(transport);
11910 } finally {
11911 Binder.restoreCallingIdentity(identity);
11912 }
11913 }
Tyler Gunn92479152021-01-20 16:30:10 -080011914
Tyler Gunnd4339262021-05-03 14:46:49 -070011915 @Override
11916 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11917 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11918 "setDeviceToDeviceForceEnabled");
11919
11920 final long identity = Binder.clearCallingIdentity();
11921 try {
11922 Arrays.stream(PhoneFactory.getPhones()).forEach(
11923 p -> {
11924 Phone thePhone = p.getImsPhone();
11925 if (thePhone != null && thePhone instanceof ImsPhone) {
11926 ImsPhone imsPhone = (ImsPhone) thePhone;
11927 CallTracker tracker = imsPhone.getCallTracker();
11928 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11929 ImsPhoneCallTracker imsPhoneCallTracker =
11930 (ImsPhoneCallTracker) tracker;
11931 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11932 }
11933 }
11934 }
11935 );
11936 } finally {
11937 Binder.restoreCallingIdentity(identity);
11938 }
11939 }
11940
Tyler Gunn92479152021-01-20 16:30:10 -080011941 /**
Hui Wang761a6682020-10-31 05:12:53 +000011942 * Gets the config of RCS VoLTE single registration enabled for the device.
11943 */
11944 @Override
11945 public boolean getDeviceSingleRegistrationEnabled() {
11946 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11947 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11948 }
11949
11950 /**
11951 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11952 */
11953 @Override
11954 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11955 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11956 "setCarrierSingleRegistrationEnabledOverride");
11957 enforceModifyPermission();
11958
11959 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11960 : Boolean.parseBoolean(enabledStr);
11961 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11962 subId, enabled);
11963 }
11964
11965 /**
11966 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11967 */
11968 @Override
11969 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11970 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11971 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11972 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011973
11974 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011975 * Overrides the ims feature validation result
11976 */
11977 @Override
11978 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11979 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11980 "setImsFeatureValidationOverride");
11981
11982 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11983 : Boolean.parseBoolean(enabledStr);
11984 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11985 subId, enabled);
11986 }
11987
11988 /**
11989 * Gets the ims feature validation override value
11990 */
11991 @Override
11992 public boolean getImsFeatureValidationOverride(int subId) {
11993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11994 "getImsFeatureValidationOverride");
11995 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11996 }
11997
11998 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011999 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12000 * their mobile plan.
12001 */
12002 @Override
12003 public String getMobileProvisioningUrl() {
12004 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12005 final long identity = Binder.clearCallingIdentity();
12006 try {
12007 return getDefaultPhone().getMobileProvisioningUrl();
12008 } finally {
12009 Binder.restoreCallingIdentity(identity);
12010 }
12011 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012012
James.cf Linbcdf8b32021-01-14 16:44:13 +080012013 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012014 * Get the EAB contact from the EAB database.
12015 */
12016 @Override
12017 public String getContactFromEab(String contact) {
12018 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12019 enforceModifyPermission();
12020 final long identity = Binder.clearCallingIdentity();
12021 try {
12022 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12023 } finally {
12024 Binder.restoreCallingIdentity(identity);
12025 }
12026 }
12027
12028 /**
Calvin Pana1434322021-07-01 19:27:01 +080012029 * Get the EAB capability from the EAB database.
12030 */
12031 @Override
12032 public String getCapabilityFromEab(String contact) {
12033 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12034 enforceModifyPermission();
12035 final long identity = Binder.clearCallingIdentity();
12036 try {
12037 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12038 } finally {
12039 Binder.restoreCallingIdentity(identity);
12040 }
12041 }
12042
12043 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012044 * Remove the EAB contacts from the EAB database.
12045 */
12046 @Override
12047 public int removeContactFromEab(int subId, String contacts) {
12048 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12049 enforceModifyPermission();
12050 final long identity = Binder.clearCallingIdentity();
12051 try {
12052 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12053 } finally {
12054 Binder.restoreCallingIdentity(identity);
12055 }
12056 }
12057
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012058 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012059 public boolean getDeviceUceEnabled() {
12060 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12061 final long identity = Binder.clearCallingIdentity();
12062 try {
12063 return mApp.getDeviceUceEnabled();
12064 } finally {
12065 Binder.restoreCallingIdentity(identity);
12066 }
12067 }
12068
12069 @Override
12070 public void setDeviceUceEnabled(boolean isEnabled) {
12071 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12072 final long identity = Binder.clearCallingIdentity();
12073 try {
12074 mApp.setDeviceUceEnabled(isEnabled);
12075 } finally {
12076 Binder.restoreCallingIdentity(identity);
12077 }
12078 }
12079
Brad Ebinger14d467f2021-02-12 06:18:28 +000012080 /**
12081 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12082 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12083 */
12084 // Used for SHELL command only right now.
12085 @Override
12086 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12087 List<String> featureTags) {
12088 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12089 "addUceRegistrationOverrideShell");
12090 final long identity = Binder.clearCallingIdentity();
12091 try {
12092 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12093 new ArraySet<>(featureTags));
12094 } catch (ImsException e) {
12095 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12096 } finally {
12097 Binder.restoreCallingIdentity(identity);
12098 }
12099 }
12100
12101 /**
12102 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12103 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12104 */
12105 // Used for SHELL command only right now.
12106 @Override
12107 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12108 List<String> featureTags) {
12109 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12110 "removeUceRegistrationOverrideShell");
12111 final long identity = Binder.clearCallingIdentity();
12112 try {
12113 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12114 new ArraySet<>(featureTags));
12115 } catch (ImsException e) {
12116 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12117 } finally {
12118 Binder.restoreCallingIdentity(identity);
12119 }
12120 }
12121
12122 /**
12123 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12124 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12125 */
12126 // Used for SHELL command only right now.
12127 @Override
12128 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12129 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12130 "clearUceRegistrationOverrideShell");
12131 final long identity = Binder.clearCallingIdentity();
12132 try {
12133 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12134 } catch (ImsException e) {
12135 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12136 } finally {
12137 Binder.restoreCallingIdentity(identity);
12138 }
12139 }
12140
12141 /**
12142 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12143 */
12144 // Used for SHELL command only right now.
12145 @Override
12146 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12147 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12148 "getLatestRcsContactUceCapabilityShell");
12149 final long identity = Binder.clearCallingIdentity();
12150 try {
12151 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12152 } catch (ImsException e) {
12153 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12154 } finally {
12155 Binder.restoreCallingIdentity(identity);
12156 }
12157 }
12158
12159 /**
12160 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12161 * device does not have an active PUBLISH.
12162 */
12163 // Used for SHELL command only right now.
12164 @Override
12165 public String getLastUcePidfXmlShell(int subId) {
12166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12167 final long identity = Binder.clearCallingIdentity();
12168 try {
12169 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12170 } catch (ImsException e) {
12171 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12172 } finally {
12173 Binder.restoreCallingIdentity(identity);
12174 }
12175 }
12176
James.cf Line8713a42021-04-29 16:04:26 +080012177 /**
12178 * Remove UCE requests cannot be sent to the network status.
12179 */
12180 // Used for SHELL command only right now.
12181 @Override
12182 public boolean removeUceRequestDisallowedStatus(int subId) {
12183 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12184 final long identity = Binder.clearCallingIdentity();
12185 try {
12186 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12187 } catch (ImsException e) {
12188 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12189 } finally {
12190 Binder.restoreCallingIdentity(identity);
12191 }
12192 }
12193
James.cf Lin18bb9002021-05-25 01:37:38 +080012194 /**
12195 * Remove UCE requests cannot be sent to the network status.
12196 */
12197 // Used for SHELL command only.
12198 @Override
12199 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12200 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12201 final long identity = Binder.clearCallingIdentity();
12202 try {
12203 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12204 } catch (ImsException e) {
12205 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12206 } finally {
12207 Binder.restoreCallingIdentity(identity);
12208 }
12209 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012210
James.cf Lin4b784aa2021-01-31 03:25:15 +080012211 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012212 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12213 String callingPackage) {
12214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12215 mApp, subId, "setSignalStrengthUpdateRequest");
12216
joonhunshin4ac60942023-11-15 15:23:39 +000012217 enforceTelephonyFeatureWithException(callingPackage,
12218 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12219
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012220 final int callingUid = Binder.getCallingUid();
12221 // Verify that tha callingPackage belongs to the calling UID
12222 mApp.getSystemService(AppOpsManager.class)
12223 .checkPackage(callingUid, callingPackage);
12224
Rambo Wang3607f502021-02-01 21:51:40 -080012225 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012226
12227 final long identity = Binder.clearCallingIdentity();
12228 try {
12229 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12230 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12231
12232 if (result instanceof IllegalStateException) {
12233 throw (IllegalStateException) result;
12234 }
12235 } finally {
12236 Binder.restoreCallingIdentity(identity);
12237 }
12238 }
12239
12240 @Override
12241 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12242 String callingPackage) {
12243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12244 mApp, subId, "clearSignalStrengthUpdateRequest");
12245
joonhunshin4ac60942023-11-15 15:23:39 +000012246 enforceTelephonyFeatureWithException(callingPackage,
12247 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12248
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012249 final int callingUid = Binder.getCallingUid();
12250 // Verify that tha callingPackage belongs to the calling UID
12251 mApp.getSystemService(AppOpsManager.class)
12252 .checkPackage(callingUid, callingPackage);
12253
12254 final long identity = Binder.clearCallingIdentity();
12255 try {
12256 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12257 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12258
12259 if (result instanceof IllegalStateException) {
12260 throw (IllegalStateException) result;
12261 }
12262 } finally {
12263 Binder.restoreCallingIdentity(identity);
12264 }
12265 }
12266
Rambo Wang3607f502021-02-01 21:51:40 -080012267 private static void validateSignalStrengthUpdateRequest(Context context,
12268 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012269 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12270 // phone/system process do not have further restriction on request
12271 return;
12272 }
12273
12274 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012275 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012276 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012277 context.enforceCallingOrSelfPermission(
12278 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12279 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012280 }
12281
12282 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012283 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012284 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012285 || info.isEnabled()) {
12286 throw new IllegalArgumentException(
12287 "Only system can set hide fields in SignalThresholdInfo");
12288 }
12289
12290 // Thresholds length for each RAN need in range. This has been validated in
12291 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12292 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12293 final int[] thresholds = info.getThresholds();
12294 Objects.requireNonNull(thresholds);
12295 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12296 || thresholds.length
12297 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12298 throw new IllegalArgumentException(
12299 "thresholds length is out of range: " + thresholds.length);
12300 }
12301 }
12302 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012303
12304 /**
12305 * Gets the current phone capability.
12306 *
12307 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12308 * @return the PhoneCapability which describes the data connection capability of modem.
12309 * It's used to evaluate possible phone config change, for example from single
12310 * SIM device to multi-SIM device.
12311 */
12312 @Override
12313 public PhoneCapability getPhoneCapability() {
12314 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012315
12316 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12317 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12318
SongFerngWang8236caa2021-01-17 21:51:44 +080012319 final long identity = Binder.clearCallingIdentity();
12320 try {
12321 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12322 } finally {
12323 Binder.restoreCallingIdentity(identity);
12324 }
12325 }
Michele Berionne5e411512020-11-13 02:36:59 +000012326
12327 /**
12328 * Prepare TelephonyManager for an unattended reboot. The reboot is
12329 * required to be done shortly after the API is invoked.
12330 */
12331 @Override
12332 @TelephonyManager.PrepareUnattendedRebootResult
12333 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012334 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012335 enforceRebootPermission();
12336
joonhunshin4ac60942023-11-15 15:23:39 +000012337 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12338 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12339
Michele Berionne5e411512020-11-13 02:36:59 +000012340 final long identity = Binder.clearCallingIdentity();
12341 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012342 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012343 } finally {
12344 Binder.restoreCallingIdentity(identity);
12345 }
12346 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012347
12348 /**
12349 * Request to get the current slicing configuration including URSP rules and
12350 * NSSAIs (configured, allowed and rejected).
12351 *
12352 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12353 */
12354 @Override
12355 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012356 TelephonyPermissions
12357 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12358 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012359
joonhunshin4ac60942023-11-15 15:23:39 +000012360 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12361 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12362 "getSlicingConfig");
12363
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012364 final long identity = Binder.clearCallingIdentity();
12365 try {
12366 Phone phone = getDefaultPhone();
12367 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12368 } finally {
12369 Binder.restoreCallingIdentity(identity);
12370 }
12371 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012372
12373 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012374 * Check whether the given premium capability is available for purchase from the carrier.
12375 *
12376 * @param capability The premium capability to check.
12377 * @param subId The subId to check the premium capability for.
12378 *
12379 * @return Whether the given premium capability is available to purchase.
12380 */
12381 @Override
12382 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12383 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12384 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12385 log("Premium capability "
12386 + TelephonyManager.convertPremiumCapabilityToString(capability)
12387 + " is not available for purchase due to missing permissions.");
12388 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12389 + "permission READ_BASIC_PHONE_STATE.");
12390 }
12391
joonhunshin4ac60942023-11-15 15:23:39 +000012392 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12393 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12394
Sarah Chin2ec39f62022-08-31 17:03:26 -070012395 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012396 if (phone == null) {
12397 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12398 return false;
12399 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012400 final long identity = Binder.clearCallingIdentity();
12401 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012402 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012403 .isPremiumCapabilityAvailableForPurchase(capability);
12404 } finally {
12405 Binder.restoreCallingIdentity(identity);
12406 }
12407 }
12408
12409 /**
12410 * Purchase the given premium capability from the carrier.
12411 *
12412 * @param capability The premium capability to purchase.
12413 * @param callback The result of the purchase request.
12414 * @param subId The subId to purchase the premium capability for.
12415 */
12416 @Override
12417 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12418 log("purchasePremiumCapability: capability="
12419 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12420 + getCurrentPackageName());
12421
12422 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12423 mApp, "purchasePremiumCapability")) {
12424 log("purchasePremiumCapability "
12425 + TelephonyManager.convertPremiumCapabilityToString(capability)
12426 + " failed due to missing permissions.");
12427 throw new SecurityException("purchasePremiumCapability requires permission "
12428 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012429 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12430 mApp, "purchasePremiumCapability")) {
12431 log("purchasePremiumCapability "
12432 + TelephonyManager.convertPremiumCapabilityToString(capability)
12433 + " failed due to missing permissions.");
12434 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012435 }
12436
joonhunshin4ac60942023-11-15 15:23:39 +000012437 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12438 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12439
Sarah Chin2ec39f62022-08-31 17:03:26 -070012440 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012441 if (phone == null) {
12442 try {
12443 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12444 callback.accept(result);
12445 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12446 } catch (RemoteException e) {
12447 String logStr = "Purchase premium capability "
12448 + TelephonyManager.convertPremiumCapabilityToString(capability)
12449 + " failed due to RemoteException handling null phone: " + e;
12450 if (DBG) log(logStr);
12451 AnomalyReporter.reportAnomaly(
12452 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12453 }
12454 return;
12455 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012456
12457 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012458 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012459 callingProcess = mApp.getPackageManager().getApplicationInfo(
12460 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012461 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012462 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012463 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012464
12465 boolean isVisible = false;
12466 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12467 if (am != null) {
12468 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12469 if (processes != null) {
12470 for (ActivityManager.RunningAppProcessInfo process : processes) {
12471 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012472 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012473 if (process.processName.equals(callingProcess) && process.importance
12474 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12475 isVisible = true;
12476 break;
12477 }
12478 }
12479 }
12480 }
12481
12482 if (!isVisible) {
12483 try {
12484 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12485 callback.accept(result);
12486 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12487 } catch (RemoteException e) {
12488 String logStr = "Purchase premium capability "
12489 + TelephonyManager.convertPremiumCapabilityToString(capability)
12490 + " failed due to RemoteException handling background application: " + e;
12491 if (DBG) log(logStr);
12492 AnomalyReporter.reportAnomaly(
12493 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12494 }
12495 return;
12496 }
12497
Sarah Chin71b3a852022-09-28 15:54:19 -070012498 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012499 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012500 }
12501
12502 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012503 * Register an IMS connection state callback
12504 */
12505 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012506 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12507 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012508 if (feature == ImsFeature.FEATURE_MMTEL) {
12509 // ImsMmTelManager
12510 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12511 TelephonyPermissions
12512 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12513 mApp, subId, "registerImsStateCallback");
12514 } else if (feature == ImsFeature.FEATURE_RCS) {
12515 // ImsRcsManager or SipDelegateManager
12516 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12517 Binder.getCallingUid(), "registerImsStateCallback",
12518 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12519 Manifest.permission.READ_PRECISE_PHONE_STATE,
12520 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12521 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12522 }
12523
12524 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12525 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12526 "IMS not available on device.");
12527 }
12528
12529 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12530 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12531 }
12532
12533 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12534 if (controller == null) {
12535 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12536 "IMS not available on device.");
12537 }
12538
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012539 if (callingPackage == null) {
12540 callingPackage = getCurrentPackageName();
12541 }
12542
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012543 final long token = Binder.clearCallingIdentity();
12544 try {
12545 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012546 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012547 } catch (ImsException e) {
12548 throw new ServiceSpecificException(e.getCode());
12549 } finally {
12550 Binder.restoreCallingIdentity(token);
12551 }
12552 }
12553
12554 /**
12555 * Unregister an IMS connection state callback
12556 */
12557 @Override
12558 public void unregisterImsStateCallback(IImsStateCallback cb) {
12559 final long token = Binder.clearCallingIdentity();
12560 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12561 if (controller == null) {
12562 return;
12563 }
12564 try {
12565 controller.unregisterImsStateCallback(cb);
12566 } finally {
12567 Binder.restoreCallingIdentity(token);
12568 }
12569 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012570
12571 /**
12572 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12573 *
12574 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012575 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012576 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012577 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012578 * If there is current registered network this value will be same as the registered cell
12579 * identity. If the device goes out of service the previous cell identity is cached and
12580 * will be returned. If the cache age of the Cell identity is more than 24 hours
12581 * it will be cleared and null will be returned.
12582 *
12583 */
12584 @Override
12585 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12586 String callingFeatureId) {
12587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12588 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12589 LocationAccessPolicy.checkLocationPermission(mApp,
12590 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12591 .setCallingPackage(callingPackage)
12592 .setCallingFeatureId(callingFeatureId)
12593 .setCallingPid(Binder.getCallingPid())
12594 .setCallingUid(Binder.getCallingUid())
12595 .setMethod("getLastKnownCellIdentity")
12596 .setLogAsInfo(true)
12597 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12598 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12599 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12600 .build());
12601
12602 boolean hasFinePermission =
12603 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12604 if (!hasFinePermission
12605 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12606 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012607 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012608 }
12609
12610 final long identity = Binder.clearCallingIdentity();
12611 try {
Ling Mac28f0212023-03-24 16:07:15 -070012612 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012613 if (sst == null) return null;
12614 return sst.getLastKnownCellIdentity();
12615 } finally {
12616 Binder.restoreCallingIdentity(identity);
12617 }
12618 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012619
jimsun3b9ccac2021-10-26 15:01:23 +080012620 /**
12621 * Sets the modem service class Name that Telephony will bind to.
12622 *
12623 * @param serviceName The class name of the modem service.
12624 * @return true if the operation is succeed, otherwise false.
12625 */
12626 public boolean setModemService(String serviceName) {
12627 Log.d(LOG_TAG, "setModemService - " + serviceName);
12628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012630 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12631 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012632 return mPhoneConfigurationManager.setModemService(serviceName);
12633 }
12634
12635 /**
12636 * Return the class name of the currently bounded modem service.
12637 *
12638 * @return the class name of the modem service.
12639 */
12640 public String getModemService() {
12641 String result;
12642 Log.d(LOG_TAG, "getModemService");
12643 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12644 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012645 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012646 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12647 "getModemService");
12648 result = mPhoneConfigurationManager.getModemService();
12649 Log.d(LOG_TAG, "result = " + result);
12650 return result;
12651 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012652
Hakjun Choi3ee81112023-12-19 15:40:58 +000012653 /**
12654 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12655 * including carrier config, entitlement server, and config update.
12656 *
12657 * @param subId subId The subscription ID of the carrier.
12658 *
12659 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12660 * be returned.
12661 *
12662 * @throws SecurityException if the caller doesn't have the required permission.
12663 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012664 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12665 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012666 final long identity = Binder.clearCallingIdentity();
12667 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012668 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012669 } finally {
12670 Binder.restoreCallingIdentity(identity);
12671 }
12672 }
12673
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012674 @Override
12675 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12676 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12677 mApp.enforceCallingOrSelfPermission(
12678 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12679 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12680
12681 final long identity = Binder.clearCallingIdentity();
12682 try {
12683 Phone phone = getPhone(subId);
12684 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012685 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12686 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012687 phone.setVoiceServiceStateOverride(hasService);
12688 } finally {
12689 Binder.restoreCallingIdentity(identity);
12690 }
12691 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012692
12693 /**
12694 * set removable eSIM as default eUICC.
12695 *
12696 * @hide
12697 */
12698 @Override
12699 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12700 enforceModifyPermission();
12701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12702
12703 final long identity = Binder.clearCallingIdentity();
12704 try {
12705 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12706 } finally {
12707 Binder.restoreCallingIdentity(identity);
12708 }
12709 }
12710
12711 /**
12712 * Returns whether the removable eSIM is default eUICC or not.
12713 *
12714 * @hide
12715 */
12716 @Override
12717 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12718 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12719 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12720
12721 final long identity = Binder.clearCallingIdentity();
12722 try {
12723 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12724 } finally {
12725 Binder.restoreCallingIdentity(identity);
12726 }
12727 }
12728
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012729 /**
12730 * Get the component name of the default app to direct respond-via-message intent for the
12731 * user associated with this subscription, update the cache if there is no respond-via-message
12732 * application currently configured for this user.
12733 * @return component name of the app and class to direct Respond Via Message intent to, or
12734 * {@code null} if the functionality is not supported.
12735 * @hide
12736 */
12737 @Override
12738 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12739 boolean updateIfNeeded) {
12740 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012741
joonhunshin4ac60942023-11-15 15:23:39 +000012742 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12743 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12744 "getDefaultRespondViaMessageApplication");
12745
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012746 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12747
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012748 UserHandle userHandle = null;
12749 final long identity = Binder.clearCallingIdentity();
12750 try {
12751 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12752 } finally {
12753 Binder.restoreCallingIdentity(identity);
12754 }
12755 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12756 updateIfNeeded, userHandle);
12757 }
Jack Yuf5badd92022-12-08 00:50:53 -080012758
12759 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012760 * Set whether the device is able to connect with null ciphering or integrity
12761 * algorithms. This is a global setting and will apply to all active subscriptions
12762 * and all new subscriptions after this.
12763 *
12764 * @param enabled when true, null cipher and integrity algorithms are allowed.
12765 * @hide
12766 */
12767 @Override
12768 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12769 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12770 enforceModifyPermission();
12771 checkForNullCipherAndIntegritySupport();
12772
12773 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12774 // for listening to these preference changes and applying them immediately.
12775 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12776 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12777 editor.apply();
12778
12779 for (Phone phone: PhoneFactory.getPhones()) {
12780 phone.handleNullCipherEnabledChange();
12781 }
12782 }
12783
12784
12785 /**
12786 * Get whether the device is able to connect with null ciphering or integrity
12787 * algorithms. Note that this retrieves the phone-global preference and not
12788 * the state of the radio.
12789 *
12790 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12791 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12792 * version for this feature.
12793 * @hide
12794 */
12795 @Override
12796 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12797 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12798 enforceReadPermission();
12799 checkForNullCipherAndIntegritySupport();
12800 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12801 }
12802
12803 private void checkForNullCipherAndIntegritySupport() {
12804 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12805 throw new UnsupportedOperationException(
12806 "Null cipher and integrity operations require HAL 2.1 or above");
12807 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012808 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12809 throw new UnsupportedOperationException(
12810 "Null cipher and integrity operations unsupported by modem");
12811 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012812 }
12813
Gil Cukierman06403e12023-11-29 16:33:03 +000012814 private void checkForIdentifierDisclosureNotificationSupport() {
12815 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12816 throw new UnsupportedOperationException(
12817 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12818 + "above");
12819 }
12820 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12821 throw new UnsupportedOperationException(
12822 "Cellular identifier disclosure transparency operations unsupported by modem");
12823 }
12824 }
12825
Michael Groover826b71d2023-12-21 22:08:06 -060012826 private void checkForNullCipherNotificationSupport() {
12827 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12828 throw new UnsupportedOperationException(
12829 "Null cipher notification operations require HAL 2.2 or above");
12830 }
12831 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12832 throw new UnsupportedOperationException(
12833 "Null cipher notification operations unsupported by modem");
12834 }
12835 }
12836
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012837 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012838 * Get the SIM state for the slot index.
12839 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12840 *
12841 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12842 */
12843 @Override
12844 @SimState
12845 public int getSimStateForSlotIndex(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +000012846 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12847 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12848
Jack Yuf5badd92022-12-08 00:50:53 -080012849 IccCardConstants.State simState;
12850 if (slotIndex < 0) {
12851 simState = IccCardConstants.State.UNKNOWN;
12852 } else {
12853 Phone phone = null;
12854 try {
12855 phone = PhoneFactory.getPhone(slotIndex);
12856 } catch (IllegalStateException e) {
12857 // ignore
12858 }
12859 if (phone == null) {
12860 simState = IccCardConstants.State.UNKNOWN;
12861 } else {
12862 IccCard icc = phone.getIccCard();
12863 if (icc == null) {
12864 simState = IccCardConstants.State.UNKNOWN;
12865 } else {
12866 simState = icc.getState();
12867 }
12868 }
12869 }
12870 return simState.ordinal();
12871 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012872
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012873 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12874 boolean enableLogcat,
12875 long logcatStartTimestampMillis, boolean enableTelecomDump,
12876 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012877 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012878 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12879 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12880 ecdDataBuilder
12881 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12882 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012883 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012884 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012885 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012886 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12887 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012888 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12889 Executors.newCachedThreadPool(), db,
12890 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012891 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012892 }
12893
12894 /**
12895 * Request telephony to persist state for debugging emergency call failures.
12896 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012897 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012898 * @param enableLogcat whether to collect logcat output
12899 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12900 * @param enableTelecomDump whether to collect telecom dumpsys
12901 * @param enableTelephonyDump whether to collect telephony dumpsys
12902 */
12903 @Override
12904 @RequiresPermission(android.Manifest.permission.DUMP)
12905 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12906 long logcatStartTimestampMillis, boolean enableTelecomDump,
12907 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012908 // Verify that the caller has READ_DROPBOX_DATA permission.
12909 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12910 && Flags.enableReadDropboxPermission()) {
12911 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12912 "persistEmergencyCallDiagnosticData");
12913 } else {
12914 // Otherwise, enforce legacy permission.
12915 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12916 "persistEmergencyCallDiagnosticData");
12917 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012918 final long identity = Binder.clearCallingIdentity();
12919 try {
12920 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12921 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12922
12923 } finally {
12924 Binder.restoreCallingIdentity(identity);
12925 }
12926 }
12927
Hui Wang9b5793a2022-12-05 14:38:06 -060012928 /**
12929 * Get current cell broadcast ranges.
12930 */
12931 @Override
12932 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12933 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12934 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12935 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012936
12937 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12938 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12939
Hui Wang9b5793a2022-12-05 14:38:06 -060012940 final long identity = Binder.clearCallingIdentity();
12941 try {
12942 return getPhone(subId).getCellBroadcastIdRanges();
12943 } finally {
12944 Binder.restoreCallingIdentity(identity);
12945 }
12946 }
12947
12948 /**
12949 * Set reception of cell broadcast messages with the list of the given ranges
12950 *
12951 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12952 */
12953 @Override
12954 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12955 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12956 @Nullable IIntegerConsumer callback) {
12957 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12958 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012959
12960 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12961 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
12962
Hui Wang9b5793a2022-12-05 14:38:06 -060012963 final long identity = Binder.clearCallingIdentity();
12964 try {
12965 Phone phone = getPhoneFromSubId(subId);
12966 if (DBG) {
12967 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12968 }
12969 phone.setCellBroadcastIdRanges(ranges, result -> {
12970 if (callback != null) {
12971 try {
12972 callback.accept(result);
12973 } catch (RemoteException e) {
12974 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12975 }
12976 }
12977 });
12978 } finally {
12979 Binder.restoreCallingIdentity(identity);
12980 }
12981 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012982
12983 /**
12984 * Returns whether the device supports the domain selection service.
12985 *
12986 * @return {@code true} if the device supports the domain selection service.
12987 */
12988 @Override
12989 public boolean isDomainSelectionSupported() {
12990 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12991 "isDomainSelectionSupported");
12992
12993 final long identity = Binder.clearCallingIdentity();
12994 try {
12995 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12996 } finally {
12997 Binder.restoreCallingIdentity(identity);
12998 }
12999 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013000
13001 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013002 * Returns whether the AOSP domain selection service is supported.
13003 *
13004 * @return {@code true} if the AOSP domain selection service is supported,
13005 * {@code false} otherwise.
13006 */
13007 @Override
13008 public boolean isAospDomainSelectionService() {
13009 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13010 "isAospDomainSelectionService");
13011
13012 final long identity = Binder.clearCallingIdentity();
13013 try {
13014 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13015 String dssComponentName = mApp.getResources().getString(
13016 R.string.config_domain_selection_service_component_name);
13017 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13018 TelephonyDomainSelectionService.class.getName());
13019 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13020 + ", aosp=" + componentName.flattenToString());
13021 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13022 }
13023 } finally {
13024 Binder.restoreCallingIdentity(identity);
13025 }
13026 return false;
13027 }
13028
13029 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013030 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13031 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13032 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013033 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013034 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013035 * @param enableSatellite {@code true} to enable the satellite modem and
13036 * {@code false} to disable.
13037 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013038 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013039 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013040 *
13041 * @throws SecurityException if the caller doesn't have the required permission.
13042 */
13043 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013044 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013045 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013046 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013047 if (enableSatellite) {
13048 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13049 @Override
13050 protected void onReceiveResult(int resultCode, Bundle resultData) {
13051 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13052 + ", resultData=" + resultData);
13053 boolean isAllowed = false;
13054 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13055 callback::accept);
13056 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13057 if (resultData != null
13058 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13059 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13060 } else {
13061 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13062 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013063 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013064 result.accept(resultCode);
13065 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013066 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013067 if (isAllowed) {
13068 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013069 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013070 } else {
13071 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13072 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013073 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013074 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013075 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013076 subId, resultReceiver);
13077 } else {
13078 // No need to check if satellite is allowed at current location when disabling satellite
13079 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013080 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013081 }
Sarah Chin503828c2023-02-01 23:54:20 -080013082 }
13083
13084 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013085 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013086 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013087 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013088 * @param result The result receiver that returns whether the satellite modem is enabled
13089 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013090 *
13091 * @throws SecurityException if the caller doesn't have the required permission.
13092 */
13093 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013094 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13095 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013096 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013097 }
13098
13099 /**
Sarah Chin43457982023-02-15 17:50:38 -080013100 * Request to get whether the satellite service demo mode is enabled.
13101 *
13102 * @param subId The subId of the subscription to check whether the satellite demo mode
13103 * is enabled for.
13104 * @param result The result receiver that returns whether the satellite demo mode is enabled
13105 * if the request is successful or an error code if the request failed.
13106 *
13107 * @throws SecurityException if the caller doesn't have the required permission.
13108 */
13109 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013110 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13111 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13112 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013113 }
13114
13115 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013116 * Request to get whether the satellite service is enabled with emergency mode.
13117 *
13118 * @param subId The subId of the subscription to check whether the satellite demo mode
13119 * is enabled for.
13120 * @param result The result receiver that returns whether the satellite emergency mode is
13121 * enabled if the request is successful or an error code if the request failed.
13122 *
13123 * @throws SecurityException if the caller doesn't have the required permission.
13124 */
13125 @Override
13126 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13127 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13128 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13129 }
13130
13131 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013132 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013133 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013134 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013135 * @param result The result receiver that returns whether the satellite service is supported on
13136 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013137 */
13138 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013139 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013140 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013141 }
13142
13143 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013144 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013145 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013146 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013147 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13148 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013149 *
13150 * @throws SecurityException if the caller doesn't have required permission.
13151 */
13152 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013153 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13154 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013155 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013156 }
13157
13158 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013159 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013160 * This can be called by the pointing UI when the user starts pointing to the satellite.
13161 * Modem should continue to report the pointing input as the device or satellite moves.
13162 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013163 * @param subId The subId of the subscription to start satellite transmission updates for.
13164 * @param resultCallback The callback to get the result of the request.
13165 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013166 *
13167 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013168 */
13169 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013170 public void startSatelliteTransmissionUpdates(int subId,
13171 @NonNull IIntegerConsumer resultCallback,
13172 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13173 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13174 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013175 }
13176
13177 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013178 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013179 * This can be called by the pointing UI when the user stops pointing to the satellite.
13180 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013181 * @param subId The subId of the subscription to stop satellite transmission updates for.
13182 * @param resultCallback The callback to get the result of the request.
13183 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13184 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013185 *
13186 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013187 */
13188 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013189 public void stopSatelliteTransmissionUpdates(int subId,
13190 @NonNull IIntegerConsumer resultCallback,
13191 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13192 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13193 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013194 }
13195
13196 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013197 * Register the subscription with a satellite provider.
13198 * This is needed to register the subscription if the provider allows dynamic registration.
13199 *
13200 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013201 * @param token The token to be used as a unique identifier for provisioning with satellite
13202 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013203 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013204 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013205 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013206 * @return The signal transport used by the caller to cancel the provision request,
13207 * or {@code null} if the request failed.
13208 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013209 * @throws SecurityException if the caller doesn't have the required permission.
13210 */
13211 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013212 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013213 @NonNull String token, @NonNull byte[] provisionData,
13214 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013215 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013216 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13217 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013218 }
13219
13220 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013221 * Unregister the device/subscription with the satellite provider.
13222 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013223 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013224 * should report as deprovisioned.
13225 *
13226 * @param subId The subId of the subscription to be deprovisioned.
13227 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013228 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013229 *
13230 * @throws SecurityException if the caller doesn't have the required permission.
13231 */
13232 @Override
13233 public void deprovisionSatelliteService(int subId,
13234 @NonNull String token, @NonNull IIntegerConsumer callback) {
13235 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013236 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013237 }
13238
13239 /**
Sarah Chin43457982023-02-15 17:50:38 -080013240 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013241 *
Sarah Chin43457982023-02-15 17:50:38 -080013242 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013243 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013244 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013245 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013246 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013247 * @throws SecurityException if the caller doesn't have the required permission.
13248 */
13249 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013250 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13251 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013252 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013253 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013254 }
13255
13256 /**
Sarah Chin43457982023-02-15 17:50:38 -080013257 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013258 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013259 *
Sarah Chin43457982023-02-15 17:50:38 -080013260 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013261 * @param callback The callback that was passed to
13262 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013263 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013264 * @throws SecurityException if the caller doesn't have the required permission.
13265 */
13266 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013267 public void unregisterForSatelliteProvisionStateChanged(
13268 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013269 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013270 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013271 }
13272
13273 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013274 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013275 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013276 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013277 * @param result The result receiver that returns whether the device is provisioned with a
13278 * satellite provider if the request is successful or an error code if the
13279 * request failed.
13280 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013281 * @throws SecurityException if the caller doesn't have the required permission.
13282 */
13283 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013284 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13285 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013286 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013287 }
13288
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013289 /**
Sarah Chin43457982023-02-15 17:50:38 -080013290 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013291 *
Sarah Chin43457982023-02-15 17:50:38 -080013292 * @param subId The subId of the subscription to register for satellite modem state changed.
13293 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013294 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013295 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013296 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013297 * @throws SecurityException if the caller doesn't have the required permission.
13298 */
13299 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013300 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013301 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013302 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013303 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013304 }
13305
13306 /**
Sarah Chin43457982023-02-15 17:50:38 -080013307 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013308 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013309 *
Sarah Chin43457982023-02-15 17:50:38 -080013310 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013311 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013312 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013313 *
13314 * @throws SecurityException if the caller doesn't have the required permission.
13315 */
13316 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013317 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013318 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013319 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13320 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013321 }
13322
13323 /**
13324 * Register to receive incoming datagrams over satellite.
13325 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013326 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013327 * @param callback The callback to handle incoming datagrams over satellite.
13328 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013329 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013330 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013331 * @throws SecurityException if the caller doesn't have the required permission.
13332 */
13333 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013334 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013335 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013336 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13337 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013338 }
13339
13340 /**
13341 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013342 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013343 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013344 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13345 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013346 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013347 *
13348 * @throws SecurityException if the caller doesn't have the required permission.
13349 */
13350 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013351 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013352 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013353 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13354 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013355 }
13356
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013357 /**
13358 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013359 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013360 * This method requests modem to check if there are any pending datagrams to be received over
13361 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013362 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013363 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013364 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013365 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013366 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013367 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013368 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013369 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13370 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13371 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013372 }
13373
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013374 /**
13375 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013376 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013377 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13378 * input to this method. Datagram received here will be passed down to modem without any
13379 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013380 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013381 * @param subId The subId of the subscription to send satellite datagrams for.
13382 * @param datagramType datagram type indicating whether the datagram is of type
13383 * SOS_SMS or LOCATION_SHARING.
13384 * @param datagram encoded gateway datagram which is encrypted by the caller.
13385 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013386 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13387 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013388 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013389 *
13390 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013391 */
13392 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013393 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013394 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13395 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013396 enforceSatelliteCommunicationPermission("sendDatagram");
13397 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13398 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013399 }
13400
Sarah Chindf715ec2023-02-13 13:46:24 -080013401 /**
13402 * Request to get whether satellite communication is allowed for the current location.
13403 *
13404 * @param subId The subId of the subscription to check whether satellite communication is
13405 * allowed for the current location for.
13406 * @param result The result receiver that returns whether satellite communication is allowed
13407 * for the current location if the request is successful or an error code
13408 * if the request failed.
13409 *
13410 * @throws SecurityException if the caller doesn't have the required permission.
13411 */
13412 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013413 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013414 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013415 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13416 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13417 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013418 }
13419
13420 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013421 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013422 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013423 * @param subId The subId to get the time after which the satellite will be visible for.
13424 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013425 * be visible if the request is successful or an error code if the request failed.
13426 *
13427 * @throws SecurityException if the caller doesn't have the required permission.
13428 */
13429 @Override
13430 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13431 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013432 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013433 }
13434
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013435 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013436 * Inform that Device is aligned to satellite for demo mode.
13437 *
13438 * @param subId The subId to get the time after which the satellite will be visible for.
13439 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13440 * {@code false} Device fails to align with the satellite for demo mode.
13441 *
13442 * @throws SecurityException if the caller doesn't have required permission.
13443 */
13444 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13445
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013446 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013447 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013448 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013449 }
13450
13451 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013452 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13453 * by modem.
13454 *
13455 * @param subId The subId of the subscription to request for.
13456 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013457 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013458 * operation.
13459 *
13460 * @throws SecurityException if the caller doesn't have required permission.
13461 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013462 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013463 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13464 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013465 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013466 final long identity = Binder.clearCallingIdentity();
13467 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013468 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013469 } finally {
13470 Binder.restoreCallingIdentity(identity);
13471 }
13472 }
13473
13474 /**
13475 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13476 * by modem.
13477 *
13478 * @param subId The subId of the subscription to request for.
13479 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013480 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013481 * operation.
13482 *
13483 * @throws SecurityException if the caller doesn't have required permission.
13484 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013485 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013486 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13487 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013488 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013489 final long identity = Binder.clearCallingIdentity();
13490 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013491 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013492 } finally {
13493 Binder.restoreCallingIdentity(identity);
13494 }
13495 }
13496
13497 /**
13498 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013499 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013500 *
13501 * @param subId The subId of the subscription to request for.
13502 *
13503 * @return Integer array of reasons for disallowing satellite communication.
13504 *
13505 * @throws SecurityException if the caller doesn't have the required permission.
13506 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013507 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013508 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013509 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013510 final long identity = Binder.clearCallingIdentity();
13511 try {
13512 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013513 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013514 return reasonSet.stream().mapToInt(i->i).toArray();
13515 } finally {
13516 Binder.restoreCallingIdentity(identity);
13517 }
13518 }
13519
13520 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013521 * Request to get the signal strength of the satellite connection.
13522 *
13523 * @param subId The subId of the subscription to request for.
13524 * @param result Result receiver to get the error code of the request and the current signal
13525 * strength of the satellite connection.
13526 *
13527 * @throws SecurityException if the caller doesn't have required permission.
13528 */
13529 @Override
13530 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13531 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13532 final long identity = Binder.clearCallingIdentity();
13533 try {
13534 mSatelliteController.requestNtnSignalStrength(subId, result);
13535 } finally {
13536 Binder.restoreCallingIdentity(identity);
13537 }
13538 }
13539
13540 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013541 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13542 * is not successful, a {@link ServiceSpecificException} that contains
13543 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013544 *
13545 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013546 * @param callback The callback to handle the NTN signal strength changed event. If the
13547 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13548 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13549 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13550 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013551 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013552 * @throws SecurityException If the caller doesn't have the required permission.
13553 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013554 */
13555 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013556 public void registerForNtnSignalStrengthChanged(int subId,
13557 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013558 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13559 final long identity = Binder.clearCallingIdentity();
13560 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013561 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013562 } finally {
13563 Binder.restoreCallingIdentity(identity);
13564 }
13565 }
13566
13567 /**
13568 * Unregisters for NTN signal strength changed from satellite modem.
13569 * If callback was not registered before, the request will be ignored.
13570 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013571 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13572 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013573 * @param callback The callback that was passed to
13574 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13575 *
13576 * @throws SecurityException if the caller doesn't have the required permission.
13577 */
13578 @Override
13579 public void unregisterForNtnSignalStrengthChanged(
13580 int subId, @NonNull INtnSignalStrengthCallback callback) {
13581 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13582 final long identity = Binder.clearCallingIdentity();
13583 try {
13584 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13585 } finally {
13586 Binder.restoreCallingIdentity(identity);
13587 }
13588 }
13589
13590 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013591 * Registers for satellite capabilities change event from the satellite service.
13592 *
13593 * @param subId The subId of the subscription to request for.
13594 * @param callback The callback to handle the satellite capabilities changed event.
13595 *
13596 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13597 *
13598 * @throws SecurityException if the caller doesn't have required permission.
13599 */
13600 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013601 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013602 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013603 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013604 final long identity = Binder.clearCallingIdentity();
13605 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013606 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013607 } finally {
13608 Binder.restoreCallingIdentity(identity);
13609 }
13610 }
13611
13612 /**
13613 * Unregisters for satellite capabilities change event from the satellite service.
13614 * If callback was not registered before, the request will be ignored.
13615 *
13616 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13617 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013618 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013619 *
13620 * @throws SecurityException if the caller doesn't have required permission.
13621 */
13622 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013623 public void unregisterForCapabilitiesChanged(int subId,
13624 @NonNull ISatelliteCapabilitiesCallback callback) {
13625 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013626 final long identity = Binder.clearCallingIdentity();
13627 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013628 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013629 } finally {
13630 Binder.restoreCallingIdentity(identity);
13631 }
13632 }
13633
13634 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013635 * Registers for the satellite supported state changed.
13636 *
13637 * @param subId The subId of the subscription to register for supported state changed.
13638 * @param callback The callback to handle the satellite supported state changed event.
13639 *
13640 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13641 *
13642 * @throws SecurityException if the caller doesn't have the required permission.
13643 */
13644 @Override
13645 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13646 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13647 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13648 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13649 }
13650
13651 /**
13652 * Unregisters for the satellite supported state changed.
13653 * If callback was not registered before, the request will be ignored.
13654 *
13655 * @param subId The subId of the subscription to unregister for supported state changed.
13656 * @param callback The callback that was passed to
13657 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13658 *
13659 * @throws SecurityException if the caller doesn't have the required permission.
13660 */
13661 @Override
13662 public void unregisterForSatelliteSupportedStateChanged(
13663 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13664 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13665 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13666 }
13667
13668 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013669 * This API can be used by only CTS to update satellite vendor service package name.
13670 *
13671 * @param servicePackageName The package name of the satellite vendor service.
13672 * @return {@code true} if the satellite vendor service is set successfully,
13673 * {@code false} otherwise.
13674 */
13675 public boolean setSatelliteServicePackageName(String servicePackageName) {
13676 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13677 TelephonyPermissions.enforceShellOnly(
13678 Binder.getCallingUid(), "setSatelliteServicePackageName");
13679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13680 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13681 "setSatelliteServicePackageName");
13682 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13683 }
13684
13685 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013686 * This API can be used by only CTS to update satellite gateway service package name.
13687 *
13688 * @param servicePackageName The package name of the satellite gateway service.
13689 * @return {@code true} if the satellite gateway service is set successfully,
13690 * {@code false} otherwise.
13691 */
13692 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13693 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13694 TelephonyPermissions.enforceShellOnly(
13695 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13697 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13698 "setSatelliteGatewayServicePackageName");
13699 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13700 }
13701
13702 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013703 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13704 *
13705 * @param packageName The package name of the satellite pointing UI app.
13706 * @param className The class name of the satellite pointing UI app.
13707 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13708 * {@code false} otherwise.
13709 */
13710 public boolean setSatellitePointingUiClassName(
13711 @Nullable String packageName, @Nullable String className) {
13712 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13713 + ", className=" + className);
13714 TelephonyPermissions.enforceShellOnly(
13715 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13717 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13718 "setSatelliteGatewayServicePackageName");
13719 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13720 }
13721
13722 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013723 * This API can be used by only CTS to update the timeout duration in milliseconds that
13724 * satellite should stay at listening mode to wait for the next incoming page before disabling
13725 * listening mode.
13726 *
13727 * @param timeoutMillis The timeout duration in millisecond.
13728 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13729 */
13730 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13731 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13732 TelephonyPermissions.enforceShellOnly(
13733 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13735 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13736 "setSatelliteListeningTimeoutDuration");
13737 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13738 }
13739
13740 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013741 * This API can be used by only CTS to override the timeout durations used by the
13742 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013743 *
13744 * @param timeoutMillis The timeout duration in millisecond.
13745 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13746 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013747 public boolean setDatagramControllerTimeoutDuration(
13748 boolean reset, int timeoutType, long timeoutMillis) {
13749 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13750 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013751 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013752 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13754 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013755 "setDatagramControllerTimeoutDuration");
13756 return mSatelliteController.setDatagramControllerTimeoutDuration(
13757 reset, timeoutType, timeoutMillis);
13758 }
13759
13760 /**
13761 * This API can be used by only CTS to override the timeout durations used by the
13762 * SatelliteController module.
13763 *
13764 * @param timeoutMillis The timeout duration in millisecond.
13765 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13766 */
13767 public boolean setSatelliteControllerTimeoutDuration(
13768 boolean reset, int timeoutType, long timeoutMillis) {
13769 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13770 + reset + ", timeoutMillis=" + timeoutMillis);
13771 TelephonyPermissions.enforceShellOnly(
13772 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13774 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13775 "setSatelliteControllerTimeoutDuration");
13776 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13777 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013778 }
13779
13780 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013781 * This API can be used in only testing to override connectivity status in monitoring emergency
13782 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13783 *
13784 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13785 * of the following values to enable the override:
13786 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13787 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13788 * To disable the override, use -1 for handoverType.
13789 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13790 * delaySeconds after the emergency call starts.
13791 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13792 */
13793 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13794 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13795 TelephonyPermissions.enforceShellOnly(
13796 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13798 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13799 "setEmergencyCallToSatelliteHandoverType");
13800 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13801 handoverType, delaySeconds);
13802 }
13803
13804 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013805 * This API can be used in only testing to override oem-enabled satellite provision status.
13806 *
13807 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13808 * otherwise.
13809 * @param isProvisioned The overriding provision status.
13810 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13811 */
13812 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13813 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13814 + ", isProvisioned=" + isProvisioned);
13815 TelephonyPermissions.enforceShellOnly(
13816 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13818 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13819 "setOemEnabledSatelliteProvisionStatus");
13820 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13821 }
13822
13823 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013824 * This API should be used by only CTS tests to forcefully set telephony country codes.
13825 *
13826 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13827 */
13828 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13829 Map cachedNetworkCountryCodes, String locationCountryCode,
13830 long locationCountryCodeTimestampNanos) {
13831 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13832 + String.join(", ", currentNetworkCountryCodes)
13833 + ", locationCountryCode=" + locationCountryCode
13834 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13835 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13836 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13837 TelephonyPermissions.enforceShellOnly(
13838 Binder.getCallingUid(), "setCachedLocationCountryCode");
13839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13840 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13841 "setCachedLocationCountryCode");
13842 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13843 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13844 locationCountryCodeTimestampNanos);
13845 }
13846
13847 /**
13848 * This API should be used by only CTS tests to override the overlay configs of satellite
13849 * access controller.
13850 *
13851 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13852 * otherwise.
13853 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13854 */
13855 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13856 String s2CellFile, long locationFreshDurationNanos,
13857 List<String> satelliteCountryCodes) {
13858 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13859 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13860 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13861 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13862 ? String.join(", ", satelliteCountryCodes) : null));
13863 TelephonyPermissions.enforceShellOnly(
13864 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13866 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13867 "setSatelliteAccessControlOverlayConfigs");
13868 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13869 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13870 }
13871
13872 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013873 * This API can be used by only CTS to override the cached value for the device overlay config
13874 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13875 * outgoing satellite datagrams should be sent to modem in demo mode.
13876 *
13877 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13878 * satellite modem or not.
13879 *
13880 * @return {@code true} if the operation is successful, {@code false} otherwise.
13881 */
13882 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13883 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13884 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13885 + "disabled");
13886 return false;
13887 }
13888 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13889 TelephonyPermissions.enforceShellOnly(
13890 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13892 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13893 "setShouldSendDatagramToModemInDemoMode");
13894 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13895 shouldSendToModemInDemoMode);
13896 }
13897
13898 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000013899 * Sets the service defined in ComponentName to be bound.
13900 *
13901 * This should only be used for testing.
13902 * @return {@code true} if the DomainSelectionService to bind to was set,
13903 * {@code false} otherwise.
13904 */
13905 @Override
13906 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
13907 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
13908
13909 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13910 "setDomainSelectionServiceOverride");
13911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13912 getDefaultSubscription(), "setDomainSelectionServiceOverride");
13913
13914 final long identity = Binder.clearCallingIdentity();
13915 try {
13916 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13917 return DomainSelectionResolver.getInstance()
13918 .setDomainSelectionServiceOverride(componentName);
13919 }
13920 } finally {
13921 Binder.restoreCallingIdentity(identity);
13922 }
13923 return false;
13924 }
13925
13926 /**
13927 * Clears the DomainSelectionService override.
13928 *
13929 * This should only be used for testing.
13930 * @return {@code true} if the DomainSelectionService override was cleared,
13931 * {@code false} otherwise.
13932 */
13933 @Override
13934 public boolean clearDomainSelectionServiceOverride() {
13935 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
13936
13937 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
13938 "clearDomainSelectionServiceOverride");
13939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13940 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
13941
13942 final long identity = Binder.clearCallingIdentity();
13943 try {
13944 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13945 return DomainSelectionResolver.getInstance()
13946 .clearDomainSelectionServiceOverride();
13947 }
13948 } finally {
13949 Binder.restoreCallingIdentity(identity);
13950 }
13951 return false;
13952 }
13953
13954 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000013955 * Enable or disable notifications sent for cellular identifier disclosure events.
13956 *
13957 * Disclosure events are defined as instances where a device has sent a cellular identifier
13958 * on the Non-access stratum (NAS) before a security context is established. As a result the
13959 * identifier is sent in the clear, which has privacy implications for the user.
13960 *
13961 * @param enable if notifications about disclosure events should be enabled
13962 * @throws SecurityException if the caller does not have the required privileges
13963 * @throws UnsupportedOperationException if the modem does not support this feature.
13964 */
13965 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013966 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000013967 enforceModifyPermission();
13968 checkForIdentifierDisclosureNotificationSupport();
13969
13970 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
13971 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
13972 editor.apply();
13973
13974 // Each phone instance is responsible for updating its respective modem immediately
13975 // after we've made a preference change.
13976 for (Phone phone : PhoneFactory.getPhones()) {
13977 phone.handleIdentifierDisclosureNotificationPreferenceChange();
13978 }
13979 }
13980
13981 /**
13982 * Get whether or not cellular identifier disclosure notifications are enabled.
13983 *
13984 * @throws SecurityException if the caller does not have the required privileges
13985 * @throws UnsupportedOperationException if the modem does not support this feature.
13986 */
13987 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000013988 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000013989 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
13990 checkForIdentifierDisclosureNotificationSupport();
13991 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
13992 }
13993
13994 /**
Michael Groover826b71d2023-12-21 22:08:06 -060013995 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
13996 * are in use by the cellular modem.
13997 *
13998 * @throws IllegalStateException if the Telephony process is not currently available
13999 * @throws SecurityException if the caller does not have the required privileges
14000 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14001 * and integrity algorithms in use
14002 * @hide
14003 */
14004 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014005 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014006 enforceModifyPermission();
14007 checkForNullCipherNotificationSupport();
14008
14009 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14010 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14011 editor.apply();
14012
14013 // Each phone instance is responsible for updating its respective modem immediately
14014 // after a preference change.
14015 for (Phone phone : PhoneFactory.getPhones()) {
14016 phone.handleNullCipherNotificationPreferenceChanged();
14017 }
14018 }
14019
14020 /**
14021 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14022 * cellular modem.
14023 *
14024 * @throws IllegalStateException if the Telephony process is not currently available
14025 * @throws SecurityException if the caller does not have the required privileges
14026 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14027 * and integrity algorithms in use
14028 * @hide
14029 */
14030 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14031 public boolean isNullCipherNotificationsEnabled() {
14032 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14033 checkForNullCipherNotificationSupport();
14034 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14035 }
14036
14037 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014038 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14039 *
14040 * <p>This method behaves in one of the following ways:
14041 * <ul>
14042 * <li>return true : if the calling package has the appop permission {@link
14043 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14044 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14045 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14046 * Owner device identifier access check, or the calling package has carrier privileges</>
14047 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14048 * </ul>
14049 */
14050 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14051 String callingPackage, @Nullable String callingFeatureId, String message) {
14052 for (Phone phone : PhoneFactory.getPhones()) {
14053 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14054 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14055 return true;
14056 }
14057 }
14058 return false;
14059 }
arunvoddud7401012022-12-15 16:08:12 +000014060
14061 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014062 * @return The subscription manager service instance.
14063 */
14064 public SubscriptionManagerService getSubscriptionManagerService() {
14065 return SubscriptionManagerService.getInstance();
14066 }
14067
14068 /**
arunvoddud7401012022-12-15 16:08:12 +000014069 * Class binds the consumer[callback] and carrierId.
14070 */
14071 private static class CallerCallbackInfo {
14072 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014073 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014074
Steve Statia28b7cb32024-03-11 23:58:50 +000014075 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014076 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014077 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014078 }
14079
14080 public Consumer<Integer> getConsumer() {
14081 return mConsumer;
14082 }
14083
Steve Statia28b7cb32024-03-11 23:58:50 +000014084 public Set<Integer> getCarrierIds() {
14085 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014086 }
14087 }
joonhunshin4ac60942023-11-15 15:23:39 +000014088
14089 /*
14090 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14091 * But the context that is passed in is unused if the phone app is already alive.
14092 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14093 */
14094 @VisibleForTesting
14095 public void setPackageManager(PackageManager packageManager) {
14096 mPackageManager = packageManager;
14097 }
14098
14099 /*
Nate Myren453c3472024-03-13 11:28:11 -070014100 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14101 * But the context that is passed in is unused if the phone app is already alive.
14102 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14103 */
14104 @VisibleForTesting
14105 public void setAppOpsManager(AppOpsManager appOps) {
14106 mAppOps = appOps;
14107 }
14108
14109 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014110 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14111 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14112 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14113 */
14114 @VisibleForTesting
14115 public void setFeatureFlags(FeatureFlags featureFlags) {
14116 mFeatureFlags = featureFlags;
14117 }
14118
14119 /**
14120 * Make sure the device has required telephony feature
14121 *
14122 * @throws UnsupportedOperationException if the device does not have required telephony feature
14123 */
14124 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14125 @NonNull String telephonyFeature, @NonNull String methodName) {
14126 if (callingPackage == null || mPackageManager == null) {
14127 return;
14128 }
14129
14130 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14131 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014132 Binder.getCallingUserHandle())
14133 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14134 // Skip to check associated telephony feature,
14135 // if compatibility change is not enabled for the current process or
14136 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014137 return;
14138 }
14139
14140 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14141 throw new UnsupportedOperationException(
14142 methodName + " is unsupported without " + telephonyFeature);
14143 }
14144 }
youngtaecha5d483d52024-04-29 17:05:45 +000014145
14146 /**
14147 * Registers for the satellite communication allowed state changed.
14148 *
14149 * @param subId The subId of the subscription to register for the satellite communication
14150 * allowed state changed.
14151 * @param callback The callback to handle the satellite communication allowed
14152 * state changed event.
14153 *
14154 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14155 *
14156 * @throws SecurityException if the caller doesn't have the required permission.
14157 */
14158 @Override
14159 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14160 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14161 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14162 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14163 subId, callback);
14164 }
14165
14166 /**
14167 * Unregisters for the satellite communication allowed state changed.
14168 * If callback was not registered before, the request will be ignored.
14169 *
14170 * @param subId The subId of the subscription to unregister for the satellite communication
14171 * allowed state changed.
14172 * @param callback The callback that was passed to
14173 * {@link #registerForCommunicationAllowedStateChanged(int,
14174 * ISatelliteCommunicationAllowedStateCallback)}. *
14175 * @throws SecurityException if the caller doesn't have the required permission.
14176 */
14177 @Override
14178 public void unregisterForCommunicationAllowedStateChanged(
14179 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14180 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14181 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14182 }
Jack Yufa8ed012023-02-11 15:42:28 -080014183}