blob: 308ef407c71fd7aa89d3618ab21cf43a08bfbb6b [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;
Hyosun Kim8bac3be2024-06-28 13:35:30 +0000168import android.telephony.satellite.ProvisionSubscriberId;
Sarah Chin503828c2023-02-01 23:54:20 -0800169import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000170import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800171import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800172import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800173import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800175import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700176import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800178import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800179
Andrew Lee312e8172014-10-23 17:01:36 -0700180import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800181import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800182import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800183import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800184import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700186import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700187import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800188import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800189import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700190import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800192import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700193import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800194import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800195import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800196import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700197import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000198import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700199import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800200import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800202import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800203import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800204import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700205import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700206import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700207import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700209import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800210import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700211import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700212import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700213import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700214import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800215import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800216import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700217import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000218import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700219import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700220import com.android.internal.telephony.SmsPermissions;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800221import com.android.internal.telephony.TelephonyCountryDetector;
Peter Wang59571be2020-01-27 12:35:15 +0800222import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800223import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700224import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000225import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800226import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700227import com.android.internal.telephony.euicc.EuiccConnector;
Sarah Chincc5446f2023-10-23 17:57:19 -0700228import com.android.internal.telephony.flags.FeatureFlags;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800229import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700230import com.android.internal.telephony.imsphone.ImsPhone;
231import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000232import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800233import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000234import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800235import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
236import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700237import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700238import com.android.internal.telephony.uicc.IccIoResult;
239import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700241import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800242import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700243import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000244import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800245import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000246import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800247import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000248import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700249import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700250import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800251import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800252import com.android.phone.callcomposer.CallComposerPictureManager;
253import com.android.phone.callcomposer.CallComposerPictureTransfer;
254import com.android.phone.callcomposer.ImageData;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800255import com.android.phone.satellite.accesscontrol.SatelliteAccessController;
Hyosun Kim240214a2023-11-02 13:30:15 +0000256import com.android.phone.satellite.entitlement.SatelliteEntitlementController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700257import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700258import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000259import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700260import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800261import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700262import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700263import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800264import com.android.server.feature.flags.Flags;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800265import com.android.services.telephony.TelecomAccountRegistry;
266import com.android.services.telephony.TelephonyConnectionService;
Hunsuk Choi9c69a802024-04-11 20:39:23 +0000267import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800268import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800269
Hall Liu82694d52020-12-11 18:22:04 -0800270import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700271import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800272import java.io.IOException;
273import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700274import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800276import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000277import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800278import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800279import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800280import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800281import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100282import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800283import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700284import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800285import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800286import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700287import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800288import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800289import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800290import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
292/**
293 * Implementation of the ITelephony interface.
294 */
Santos Cordon117fee72014-05-16 17:56:12 -0700295public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 private static final String LOG_TAG = "PhoneInterfaceManager";
297 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
298 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800299 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300
301 // Message codes used with mMainThreadHandler
302 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700303 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
304 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700305 private static final int CMD_OPEN_CHANNEL = 9;
306 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
307 private static final int CMD_CLOSE_CHANNEL = 11;
308 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800309 private static final int CMD_NV_READ_ITEM = 13;
310 private static final int EVENT_NV_READ_ITEM_DONE = 14;
311 private static final int CMD_NV_WRITE_ITEM = 15;
312 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
313 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
314 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700315 private static final int CMD_RESET_MODEM_CONFIG = 19;
316 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800317 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
318 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800319 private static final int CMD_SEND_ENVELOPE = 25;
320 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700321 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
322 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
323 private static final int CMD_EXCHANGE_SIM_IO = 31;
324 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800325 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
326 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700327 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
328 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700329 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
330 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700331 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
332 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
333 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
334 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700335 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
336 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
337 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
338 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700339 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800340 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
341 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000342 private static final int CMD_SWITCH_SLOTS = 50;
343 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700344 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
345 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
346 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
347 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
348 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
349 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
350 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
351 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700352 private static final int CMD_GET_ALL_CELL_INFO = 60;
353 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
354 private static final int CMD_GET_CELL_LOCATION = 62;
355 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700356 private static final int CMD_MODEM_REBOOT = 64;
357 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700358 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
359 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800360 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
361 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700362 private static final int CMD_GET_MODEM_STATUS = 70;
363 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700364 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
365 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700366 private static final int CMD_ERASE_MODEM_CONFIG = 74;
367 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800368 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
369 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
370 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
371 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800372 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
373 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800374 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800375 private static final int CMD_GET_CALL_FORWARDING = 83;
376 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
377 private static final int CMD_SET_CALL_FORWARDING = 85;
378 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
379 private static final int CMD_GET_CALL_WAITING = 87;
380 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
381 private static final int CMD_SET_CALL_WAITING = 89;
382 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700383 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
384 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
385 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
386 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700387 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
388 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800389 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
390 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800391 private static final int CMD_SET_DATA_THROTTLING = 99;
392 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800393 private static final int CMD_SET_SIM_POWER = 101;
394 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800395 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
396 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
397 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
398 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800399 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
400 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000401 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800402 private static final int CMD_GET_SLICING_CONFIG = 110;
403 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800404 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700405 private static final int CMD_ENABLE_VONR = 113;
406 private static final int EVENT_ENABLE_VONR_DONE = 114;
407 private static final int CMD_IS_VONR_ENABLED = 115;
408 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700409 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
410 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000411
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800412 // Parameters of select command.
413 private static final int SELECT_COMMAND = 0xA4;
414 private static final int SELECT_P1 = 0x04;
415 private static final int SELECT_P2 = 0;
416 private static final int SELECT_P3 = 0x10;
417
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000418 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
419 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
Gil Cukierman06403e12023-11-29 16:33:03 +0000420 // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2
421 private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202;
Michael Groover826b71d2023-12-21 22:08:06 -0600422 // Null cipher notification support was added in IRadioNetwork 2.2
423 private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202;
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000424
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 /** The singleton instance. */
426 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800427 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428
Sarah Chin4beb2b72023-02-14 14:47:54 -0800429 private final PhoneGlobals mApp;
joonhunshin4ac60942023-11-15 15:23:39 +0000430 private FeatureFlags mFeatureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -0800431 private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800432 private final CallManager mCM;
433 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000434
435 private final SatelliteController mSatelliteController;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800436 private final SatelliteAccessController mSatelliteAccessController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800437 private final UserManager mUserManager;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800438 private final MainThreadHandler mMainThreadHandler;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800439 private final SharedPreferences mTelephonySharedPreferences;
440 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800441 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Nate Myren453c3472024-03-13 11:28:11 -0700442 private AppOpsManager mAppOps;
joonhunshin4ac60942023-11-15 15:23:39 +0000443 private PackageManager mPackageManager;
joonhunshinf624b2a2024-04-18 04:42:12 +0000444 private final int mVendorApiLevel;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Peter Wangdafb9ac2020-01-15 14:13:38 -0800446 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800447 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800448 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800449 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800450
Derek Tan97ebb422014-09-05 16:55:38 -0700451 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
452 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800453 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800454 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700455
Michelecea4cf22018-12-21 15:00:11 -0800456 // String to store multi SIM allowed
457 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
458
Derek Tan740e1672017-06-27 14:56:27 -0700459 // The AID of ISD-R.
460 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
461
yinxub1bed742017-04-17 11:45:04 -0700462 private NetworkScanRequestTracker mNetworkScanRequestTracker;
463
David Kelly5e06a7f2018-03-12 14:10:59 +0000464 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
465 private static final int MANUFACTURER_CODE_LENGTH = 8;
466
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800467 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800468 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800469
Sarah Chin2ec39f62022-08-31 17:03:26 -0700470 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
471 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
472
Derek Tan89e89d42014-07-08 17:00:10 -0700473 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700474 * Experiment flag to enable erase modem config on reset network, default value is false
475 */
476 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
477 "reset_network_erase_modem_config_enabled";
478
Rambo Wang0f050d82021-02-12 11:43:36 -0800479 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800480
Gary Jian76280a42022-12-07 16:18:33 +0800481 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
482
sandeepjsb6c87872021-09-27 15:34:44 +0000483 /**
484 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
485 * one ICCID active at the same time.
486 * Apps should use below API signatures if targeting SDK is T and beyond.
487 *
488 * @hide
489 */
490 @ChangeId
491 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
492 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800493
Naina Nallurid63128d2019-09-17 14:10:30 -0700494 /**
Chen Xu540470b2021-12-14 17:15:47 -0800495 * Apps targeting on Android T and beyond will get exception whenever icc close channel
496 * operation fails.
497 */
498 @ChangeId
499 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
500 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
501
502 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 * A request object to use for transmitting data to an ICC.
504 */
505 private static final class IccAPDUArgument {
506 public int channel, cla, command, p1, p2, p3;
507 public String data;
508
509 public IccAPDUArgument(int channel, int cla, int command,
510 int p1, int p2, int p3, String data) {
511 this.channel = channel;
512 this.cla = cla;
513 this.command = command;
514 this.p1 = p1;
515 this.p2 = p2;
516 this.p3 = p3;
517 this.data = data;
518 }
519 }
520
521 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700522 * A request object to use for transmitting data to an ICC.
523 */
524 private static final class ManualNetworkSelectionArgument {
525 public OperatorInfo operatorInfo;
526 public boolean persistSelection;
527
528 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
529 this.operatorInfo = operatorInfo;
530 this.persistSelection = persistSelection;
531 }
532 }
533
Sarah Chin71b3a852022-09-28 15:54:19 -0700534 private static final class PurchasePremiumCapabilityArgument {
535 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700536 public @NonNull IIntegerConsumer callback;
537
538 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800539 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700540 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700541 this.callback = callback;
542 }
543 }
544
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700545 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
547 * request after sending. The main thread will notify the request when it is complete.
548 */
549 private static final class MainThreadRequest {
550 /** The argument to use for the request */
551 public Object argument;
552 /** The result of the request that is run on the main thread */
553 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800554 // The subscriber id that this request applies to. Defaults to
555 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
556 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700557
Nathan Harold92bed182018-10-12 18:16:49 -0700558 // In cases where subId is unavailable, the caller needs to specify the phone.
559 public Phone phone;
560
vagdeviaf9a5b92018-08-15 16:01:53 -0700561 public WorkSource workSource;
562
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700563 public MainThreadRequest(Object argument) {
564 this.argument = argument;
565 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800566
Nathan Harold92bed182018-10-12 18:16:49 -0700567 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
568 this.argument = argument;
569 if (phone != null) {
570 this.phone = phone;
571 }
572 this.workSource = workSource;
573 }
574
vagdeviaf9a5b92018-08-15 16:01:53 -0700575 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800576 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800577 if (subId != null) {
578 this.subId = subId;
579 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700580 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 }
583
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800584 private static final class IncomingThirdPartyCallArgs {
585 public final ComponentName component;
586 public final String callId;
587 public final String callerDisplayName;
588
589 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
590 String callerDisplayName) {
591 this.component = component;
592 this.callId = callId;
593 this.callerDisplayName = callerDisplayName;
594 }
595 }
596
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700597 /**
598 * A handler that processes messages on the main thread in the phone process. Since many
599 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
600 * inbound binder threads to the main thread in the phone process. The Binder thread
601 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
602 * on, which will be notified when the operation completes and will contain the result of the
603 * request.
604 *
605 * <p>If a MainThreadRequest object is provided in the msg.obj field,
606 * note that request.result must be set to something non-null for the calling thread to
607 * unblock.
608 */
609 private final class MainThreadHandler extends Handler {
610 @Override
611 public void handleMessage(Message msg) {
612 MainThreadRequest request;
613 Message onCompleted;
614 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000615 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800617 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700618
619 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 case CMD_HANDLE_USSD_REQUEST: {
621 request = (MainThreadRequest) msg.obj;
622 final Phone phone = getPhoneFromRequest(request);
623 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800624 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700626
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 if (!isUssdApiAllowed(request.subId)) {
628 // Carrier does not support use of this API, return failure.
629 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
630 UssdResponse response = new UssdResponse(ussdRequest, null);
631 Bundle returnData = new Bundle();
632 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
633 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700634
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 request.result = true;
636 notifyRequester(request);
637 return;
638 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700639
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 try {
641 request.result = phone != null
642 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
643 } catch (CallStateException cse) {
644 request.result = false;
645 }
646 // Wake up the requesting thread
647 notifyRequester(request);
648 break;
pkanwar32d516d2016-10-14 19:37:38 -0700649 }
650
Yorke Lee716f67e2015-06-17 15:39:16 -0700651 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700652 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700653 final Phone phone = getPhoneFromRequest(request);
654 request.result = phone != null ?
655 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
656 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700657 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700659 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000665 uiccPort = getUiccPortFromRequest(request);
666 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700667 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800668 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700670 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800672 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000673 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800674 iccArgument.channel, iccArgument.cla, iccArgument.command,
675 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
676 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 break;
679
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 ar = (AsyncResult) msg.obj;
682 request = (MainThreadRequest) ar.userObj;
683 if (ar.exception == null && ar.result != null) {
684 request.result = ar.result;
685 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800686 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 if (ar.result == null) {
688 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800689 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800691 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 } else {
693 loge("iccTransmitApduLogicalChannel: Unknown exception");
694 }
695 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 break;
698
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
700 request = (MainThreadRequest) msg.obj;
701 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000702 uiccPort = getUiccPortFromRequest(request);
703 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800705 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 } else {
708 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800709 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000710 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800711 iccArgument.cla, iccArgument.command, iccArgument.p1,
712 iccArgument.p2,
713 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700714 }
715 break;
716
717 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
718 ar = (AsyncResult) msg.obj;
719 request = (MainThreadRequest) ar.userObj;
720 if (ar.exception == null && ar.result != null) {
721 request.result = ar.result;
722 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800723 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 if (ar.result == null) {
725 loge("iccTransmitApduBasicChannel: Empty response");
726 } else if (ar.exception instanceof CommandException) {
727 loge("iccTransmitApduBasicChannel: CommandException: " +
728 ar.exception);
729 } else {
730 loge("iccTransmitApduBasicChannel: Unknown exception");
731 }
732 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 break;
735
736 case CMD_EXCHANGE_SIM_IO:
737 request = (MainThreadRequest) msg.obj;
738 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000739 uiccPort = getUiccPortFromRequest(request);
740 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800742 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 } else {
745 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
746 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000747 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700748 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
749 iccArgument.data, onCompleted);
750 }
751 break;
752
753 case EVENT_EXCHANGE_SIM_IO_DONE:
754 ar = (AsyncResult) msg.obj;
755 request = (MainThreadRequest) ar.userObj;
756 if (ar.exception == null && ar.result != null) {
757 request.result = ar.result;
758 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800759 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700760 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700761 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 break;
763
Derek Tan4d5e5c12014-02-04 11:54:58 -0800764 case CMD_SEND_ENVELOPE:
765 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000766 uiccPort = getUiccPortFromRequest(request);
767 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700768 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800769 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700771 } else {
772 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800773 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700774 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800775 break;
776
777 case EVENT_SEND_ENVELOPE_DONE:
778 ar = (AsyncResult) msg.obj;
779 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700780 if (ar.exception == null && ar.result != null) {
781 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800782 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800783 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700784 if (ar.result == null) {
785 loge("sendEnvelopeWithStatus: Empty response");
786 } else if (ar.exception instanceof CommandException) {
787 loge("sendEnvelopeWithStatus: CommandException: " +
788 ar.exception);
789 } else {
790 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
791 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800792 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700793 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800794 break;
795
Shishir Agrawal566b7612013-10-28 14:41:00 -0700796 case CMD_OPEN_CHANNEL:
797 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000798 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800799 IccLogicalChannelRequest openChannelRequest =
800 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000801 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700802 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800803 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800804 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700805 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700806 } else {
807 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800808 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
809 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700810 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700811 break;
812
813 case EVENT_OPEN_CHANNEL_DONE:
814 ar = (AsyncResult) msg.obj;
815 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700816 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700817 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700818 int[] result = (int[]) ar.result;
819 int channelId = result[0];
820 byte[] selectResponse = null;
821 if (result.length > 1) {
822 selectResponse = new byte[result.length - 1];
823 for (int i = 1; i < result.length; ++i) {
824 selectResponse[i - 1] = (byte) result[i];
825 }
826 }
827 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800828 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800829
830 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700831 if (uiccPort == null) {
832 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
833 } else {
834 IccLogicalChannelRequest channelRequest =
835 (IccLogicalChannelRequest) request.argument;
836 channelRequest.channel = channelId;
837 uiccPort.onLogicalChannelOpened(channelRequest);
838 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700840 if (ar.result == null) {
841 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700842 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700843 if (ar.exception != null) {
844 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
845 }
846
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700847 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700848 if (ar.exception instanceof CommandException) {
849 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800850 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700851 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700852 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700853 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700854 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700855 }
856 }
857 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800858 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700859 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700860 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700861 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700862 break;
863
864 case CMD_CLOSE_CHANNEL:
865 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000866 uiccPort = getUiccPortFromRequest(request);
867 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700868 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800869 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800870 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800871 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700872 } else {
873 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000874 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700875 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700876 break;
877
878 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800879 ar = (AsyncResult) msg.obj;
880 request = (MainThreadRequest) ar.userObj;
881 if (ar.exception == null) {
882 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800883 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700884 if (uiccPort == null) {
885 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
886 } else {
887 final int channelId = (Integer) request.argument;
888 uiccPort.onLogicalChannelClosed(channelId);
889 }
Chen Xu540470b2021-12-14 17:15:47 -0800890 } else {
891 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800892 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800893 if (ar.exception instanceof CommandException) {
894 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
895 CommandException.Error error =
896 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800897 if (error == CommandException.Error.INVALID_ARGUMENTS) {
898 // should only throw exceptions from the binder threads.
899 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800900 "iccCloseLogicalChannel: invalid argument ");
901 }
902 } else {
903 loge("iccCloseLogicalChannel: Unknown exception");
904 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800905 request.result = (exception != null) ? exception :
906 new IllegalStateException(
907 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800908 }
909 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800910 break;
911
912 case CMD_NV_READ_ITEM:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800915 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
916 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800917 break;
918
919 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700920 ar = (AsyncResult) msg.obj;
921 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800922 if (ar.exception == null && ar.result != null) {
923 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700924 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800925 request.result = "";
926 if (ar.result == null) {
927 loge("nvReadItem: Empty response");
928 } else if (ar.exception instanceof CommandException) {
929 loge("nvReadItem: CommandException: " +
930 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700931 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800932 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700933 }
934 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700935 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700936 break;
937
Jake Hambye994d462014-02-03 13:10:13 -0800938 case CMD_NV_WRITE_ITEM:
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
941 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800942 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700943 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800944 break;
945
946 case EVENT_NV_WRITE_ITEM_DONE:
947 handleNullReturnEvent(msg, "nvWriteItem");
948 break;
949
950 case CMD_NV_WRITE_CDMA_PRL:
951 request = (MainThreadRequest) msg.obj;
952 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800953 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800954 break;
955
956 case EVENT_NV_WRITE_CDMA_PRL_DONE:
957 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
958 break;
959
chen xu6dac5ab2018-10-26 17:39:23 -0700960 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800961 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700962 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800963 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800964 break;
965
chen xu6dac5ab2018-10-26 17:39:23 -0700966 case EVENT_RESET_MODEM_CONFIG_DONE:
967 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800968 break;
969
Sooraj Sasindran37444802020-08-11 10:40:43 -0700970 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
973 request);
974 Phone phone = getPhoneFromRequest(request);
975 if (phone != null) {
976 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
977 } else {
978 loge("isNRDualConnectivityEnabled: No phone object");
979 request.result = false;
980 notifyRequester(request);
981 }
982 break;
983 }
984
985 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
988 if (ar.exception == null && ar.result != null) {
989 request.result = ar.result;
990 } else {
991 // request.result must be set to something non-null
992 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700993 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700994 request.result = ar.result;
995 } else {
996 request.result = false;
997 }
998 if (ar.result == null) {
999 loge("isNRDualConnectivityEnabled: Empty response");
1000 } else if (ar.exception instanceof CommandException) {
1001 loge("isNRDualConnectivityEnabled: CommandException: "
1002 + ar.exception);
1003 } else {
1004 loge("isNRDualConnectivityEnabled: Unknown exception");
1005 }
1006 }
1007 notifyRequester(request);
1008 break;
1009
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001010 case CMD_IS_VONR_ENABLED: {
1011 request = (MainThreadRequest) msg.obj;
1012 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1013 request);
1014 Phone phone = getPhoneFromRequest(request);
1015 if (phone != null) {
1016 phone.isVoNrEnabled(onCompleted, request.workSource);
1017 } else {
1018 loge("isVoNrEnabled: No phone object");
1019 request.result = false;
1020 notifyRequester(request);
1021 }
1022 break;
1023 }
1024
1025 case EVENT_IS_VONR_ENABLED_DONE:
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 if (ar.exception == null && ar.result != null) {
1029 request.result = ar.result;
1030 } else {
1031 // request.result must be set to something non-null
1032 // for the calling thread to unblock
1033 if (ar.result != null) {
1034 request.result = ar.result;
1035 } else {
1036 request.result = false;
1037 }
1038 if (ar.result == null) {
1039 loge("isVoNrEnabled: Empty response");
1040 } else if (ar.exception instanceof CommandException) {
1041 loge("isVoNrEnabled: CommandException: "
1042 + ar.exception);
1043 } else {
1044 loge("isVoNrEnabled: Unknown exception");
1045 }
1046 }
1047 notifyRequester(request);
1048 break;
1049
Sooraj Sasindran37444802020-08-11 10:40:43 -07001050 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1053 Phone phone = getPhoneFromRequest(request);
1054 if (phone != null) {
1055 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1056 request.workSource);
1057 } else {
1058 loge("enableNrDualConnectivity: No phone object");
1059 request.result =
1060 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1061 notifyRequester(request);
1062 }
1063 break;
1064 }
1065
1066 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 if (ar.exception == null) {
1070 request.result =
1071 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1072 } else {
1073 request.result =
1074 TelephonyManager
1075 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1076 if (ar.exception instanceof CommandException) {
1077 CommandException.Error error =
1078 ((CommandException) (ar.exception)).getCommandError();
1079 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1080 request.result =
1081 TelephonyManager
1082 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001083 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1084 request.result =
1085 TelephonyManager
1086 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001087 }
1088 loge("enableNrDualConnectivity" + ": CommandException: "
1089 + ar.exception);
1090 } else {
1091 loge("enableNrDualConnectivity" + ": Unknown exception");
1092 }
1093 }
1094 notifyRequester(request);
1095 break;
1096 }
1097
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001098 case CMD_ENABLE_VONR: {
1099 request = (MainThreadRequest) msg.obj;
1100 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1101 Phone phone = getPhoneFromRequest(request);
1102 if (phone != null) {
1103 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1104 request.workSource);
1105 } else {
1106 loge("setVoNrEnabled: No phone object");
1107 request.result =
1108 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1109 notifyRequester(request);
1110 }
1111 break;
1112 }
1113
1114 case EVENT_ENABLE_VONR_DONE: {
1115 ar = (AsyncResult) msg.obj;
1116 request = (MainThreadRequest) ar.userObj;
1117 if (ar.exception == null) {
1118 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1119 } else {
1120 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1121 if (ar.exception instanceof CommandException) {
1122 CommandException.Error error =
1123 ((CommandException) (ar.exception)).getCommandError();
1124 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1125 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1126 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1127 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1128 } else {
1129 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1130 }
1131 loge("setVoNrEnabled" + ": CommandException: "
1132 + ar.exception);
1133 } else {
1134 loge("setVoNrEnabled" + ": Unknown exception");
1135 }
1136 }
1137 notifyRequester(request);
1138 break;
1139 }
1140
SongFerngWang3ef3e072020-12-21 16:41:52 +08001141 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001142 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001143 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1144 request);
1145 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001146 break;
1147
SongFerngWang3ef3e072020-12-21 16:41:52 +08001148 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001149 ar = (AsyncResult) msg.obj;
1150 request = (MainThreadRequest) ar.userObj;
1151 if (ar.exception == null && ar.result != null) {
1152 request.result = ar.result; // Integer
1153 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301154 // request.result must be set to something non-null
1155 // for the calling thread to unblock
1156 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001157 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001158 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001159 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001160 loge("getAllowedNetworkTypesBitmask: CommandException: "
1161 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001162 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001163 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001164 }
1165 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001166 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001167 break;
1168
SongFerngWang3ef3e072020-12-21 16:41:52 +08001169 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001170 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001171 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1172 request);
1173 Pair<Integer, Long> reasonWithNetworkTypes =
1174 (Pair<Integer, Long>) request.argument;
1175 getPhoneFromRequest(request).setAllowedNetworkTypes(
1176 reasonWithNetworkTypes.first,
1177 reasonWithNetworkTypes.second,
1178 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001179 break;
1180
SongFerngWang3ef3e072020-12-21 16:41:52 +08001181 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1182 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001183 break;
1184
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001185 case CMD_SET_VOICEMAIL_NUMBER:
1186 request = (MainThreadRequest) msg.obj;
1187 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1188 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001189 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1190 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001191 break;
1192
1193 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1194 handleNullReturnEvent(msg, "setVoicemailNumber");
1195 break;
1196
Stuart Scott54788802015-03-30 13:18:01 -07001197 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1198 request = (MainThreadRequest) msg.obj;
1199 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1200 request);
1201 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1202 break;
1203
1204 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1205 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1206 break;
1207
Shishir Agrawal302c8692015-06-19 13:49:39 -07001208 case CMD_PERFORM_NETWORK_SCAN:
1209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1211 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1212 break;
1213
Hall Liu27d24262020-09-18 19:04:59 -07001214 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001215 request = (MainThreadRequest) msg.obj;
1216 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001217 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1218 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1219 request.argument;
1220 int callForwardingReason = args.first;
1221 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001222 break;
Hall Liu27d24262020-09-18 19:04:59 -07001223 }
1224 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001225 ar = (AsyncResult) msg.obj;
1226 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001227 TelephonyManager.CallForwardingInfoCallback callback =
1228 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1229 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001230 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001231 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001232 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1233 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1234 // Service Class is a bit mask per 3gpp 27.007. Search for
1235 // any service for voice call.
1236 if ((callForwardInfo.serviceClass
1237 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001238 callForwardingInfo = new CallForwardingInfo(
1239 callForwardInfo.status
1240 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001241 callForwardInfo.reason,
1242 callForwardInfo.number,
1243 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001244 break;
1245 }
1246 }
1247 // Didn't find a call forward info for voice call.
1248 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001249 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1250 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001251 }
Hall Liu27d24262020-09-18 19:04:59 -07001252 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001253 } else {
1254 if (ar.result == null) {
1255 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1256 }
1257 if (ar.exception != null) {
1258 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1259 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001260 int errorCode = TelephonyManager
1261 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001262 if (ar.exception instanceof CommandException) {
1263 CommandException.Error error =
1264 ((CommandException) (ar.exception)).getCommandError();
1265 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001266 errorCode = TelephonyManager
1267 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001268 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001269 errorCode = TelephonyManager
1270 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001271 }
1272 }
Hall Liu27d24262020-09-18 19:04:59 -07001273 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001274 }
Shuo Qian4a594052020-01-23 11:59:30 -08001275 break;
Hall Liu27d24262020-09-18 19:04:59 -07001276 }
Shuo Qian4a594052020-01-23 11:59:30 -08001277
Hall Liu27d24262020-09-18 19:04:59 -07001278 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001279 request = (MainThreadRequest) msg.obj;
1280 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001281 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001282 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001283 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1284 request.argument).first;
1285 request.phone.setCallForwardingOption(
1286 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001287 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001288 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001289 callForwardingInfoToSet.getReason(),
1290 callForwardingInfoToSet.getNumber(),
1291 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1292 break;
Hall Liu27d24262020-09-18 19:04:59 -07001293 }
Shuo Qian4a594052020-01-23 11:59:30 -08001294
Hall Liu27d24262020-09-18 19:04:59 -07001295 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001296 ar = (AsyncResult) msg.obj;
1297 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001298 Consumer<Integer> callback =
1299 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1300 request.argument).second;
1301 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001302 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001303 int errorCode = TelephonyManager.CallForwardingInfoCallback
1304 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001305 if (ar.exception instanceof CommandException) {
1306 CommandException.Error error =
1307 ((CommandException) (ar.exception)).getCommandError();
1308 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001309 errorCode = TelephonyManager.CallForwardingInfoCallback
1310 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001311 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001312 errorCode = TelephonyManager.CallForwardingInfoCallback
1313 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001314 }
1315 }
1316 callback.accept(errorCode);
1317 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001318 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001319 }
Shuo Qian4a594052020-01-23 11:59:30 -08001320 break;
Hall Liu27d24262020-09-18 19:04:59 -07001321 }
Shuo Qian4a594052020-01-23 11:59:30 -08001322
Hall Liu27d24262020-09-18 19:04:59 -07001323 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001324 request = (MainThreadRequest) msg.obj;
1325 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1326 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1327 break;
Hall Liu27d24262020-09-18 19:04:59 -07001328 }
Shuo Qian4a594052020-01-23 11:59:30 -08001329
Hall Liu27d24262020-09-18 19:04:59 -07001330 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001331 ar = (AsyncResult) msg.obj;
1332 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001333 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001334 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001335 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001336 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001337 // Service Class is a bit mask per 3gpp 27.007.
1338 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001339 if (callForwardResults.length > 1
1340 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001341 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001342 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001343 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1344 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001345 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001346 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001347 }
1348 } else {
1349 if (ar.result == null) {
1350 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1351 }
1352 if (ar.exception != null) {
1353 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1354 }
1355 if (ar.exception instanceof CommandException) {
1356 CommandException.Error error =
1357 ((CommandException) (ar.exception)).getCommandError();
1358 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001359 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001360 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001361 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1362 callWaitingStatus =
1363 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001364 }
1365 }
1366 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001367 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001368 break;
Hall Liu27d24262020-09-18 19:04:59 -07001369 }
Shuo Qian4a594052020-01-23 11:59:30 -08001370
Hall Liu27d24262020-09-18 19:04:59 -07001371 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001372 request = (MainThreadRequest) msg.obj;
1373 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001374 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1375 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001376 break;
Hall Liu27d24262020-09-18 19:04:59 -07001377 }
Shuo Qian4a594052020-01-23 11:59:30 -08001378
Hall Liu27d24262020-09-18 19:04:59 -07001379 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001380 ar = (AsyncResult) msg.obj;
1381 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001382 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1383 Consumer<Integer> callback =
1384 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1385 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001386 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001387 if (ar.exception instanceof CommandException) {
1388 CommandException.Error error =
1389 ((CommandException) (ar.exception)).getCommandError();
1390 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1391 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001392 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1393 callback.accept(
1394 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001395 } else {
1396 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1397 }
1398 } else {
1399 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1400 }
1401 } else {
1402 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1403 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001404 }
Shuo Qian4a594052020-01-23 11:59:30 -08001405 break;
Hall Liu27d24262020-09-18 19:04:59 -07001406 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001407 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1408 ar = (AsyncResult) msg.obj;
1409 request = (MainThreadRequest) ar.userObj;
1410 CellNetworkScanResult cellScanResult;
1411 if (ar.exception == null && ar.result != null) {
1412 cellScanResult = new CellNetworkScanResult(
1413 CellNetworkScanResult.STATUS_SUCCESS,
1414 (List<OperatorInfo>) ar.result);
1415 } else {
1416 if (ar.result == null) {
1417 loge("getCellNetworkScanResults: Empty response");
1418 }
1419 if (ar.exception != null) {
1420 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1421 }
1422 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1423 if (ar.exception instanceof CommandException) {
1424 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001425 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001426 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1427 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1428 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1429 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1430 }
1431 }
1432 cellScanResult = new CellNetworkScanResult(errorCode, null);
1433 }
1434 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001435 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001436 break;
1437
1438 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1439 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001440 ManualNetworkSelectionArgument selArg =
1441 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001442 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1443 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001444 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1445 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001446 break;
1447
1448 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 if (ar.exception == null) {
1452 request.result = true;
1453 } else {
1454 request.result = false;
1455 loge("setNetworkSelectionModeManual " + ar.exception);
1456 }
1457 notifyRequester(request);
1458 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001459 break;
1460
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001461 case CMD_GET_MODEM_ACTIVITY_INFO:
1462 request = (MainThreadRequest) msg.obj;
1463 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001464 if (defaultPhone != null) {
1465 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001466 } else {
1467 ResultReceiver result = (ResultReceiver) request.argument;
1468 Bundle bundle = new Bundle();
1469 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001470 new ModemActivityInfo(0, 0, 0,
1471 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001472 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001473 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001474 break;
1475
Hall Liud0f208c2020-10-14 16:54:44 -07001476 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001477 ar = (AsyncResult) msg.obj;
1478 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001479 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001480 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001481 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001482 if (mLastModemActivityInfo == null) {
1483 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1484 mLastModemActivitySpecificInfo[0] =
1485 new ActivityStatsTechSpecificInfo(
1486 0,
1487 0,
1488 new int[ModemActivityInfo.getNumTxPowerLevels()],
1489 0);
1490 mLastModemActivityInfo =
1491 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1492 }
1493
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001494 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001495 // Update the last modem activity info and the result of the request.
1496 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1497 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001498 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001499 } else {
1500 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001501 }
Kai Shi917fdc62022-11-28 14:01:02 -08001502 // This is needed to decouple ret from mLastModemActivityInfo
1503 // We don't want to return mLastModemActivityInfo which is updated
1504 // inside mergeModemActivityInfo()
1505 ret = new ModemActivityInfo(
1506 mLastModemActivityInfo.getTimestampMillis(),
1507 mLastModemActivityInfo.getSleepTimeMillis(),
1508 mLastModemActivityInfo.getIdleTimeMillis(),
1509 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001510
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001511 } else {
1512 if (ar.result == null) {
1513 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001514 error = TelephonyManager.ModemActivityInfoException
1515 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001516 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001517 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001518 error = TelephonyManager.ModemActivityInfoException
1519 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001520 } else {
1521 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001522 error = TelephonyManager.ModemActivityInfoException
1523 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001524 }
1525 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001526 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001527 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001528 bundle.putParcelable(
1529 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001530 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001531 } else {
1532 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1533 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001534 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001535 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001536 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001537 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001538
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001539 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001540 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001541 CarrierRestrictionRules argument =
1542 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001543 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001544 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001546 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001547
1548 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1549 ar = (AsyncResult) msg.obj;
1550 request = (MainThreadRequest) ar.userObj;
1551 if (ar.exception == null && ar.result != null) {
1552 request.result = ar.result;
1553 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001554 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1555 if (ar.exception instanceof CommandException) {
1556 loge("setAllowedCarriers: CommandException: " + ar.exception);
1557 CommandException.Error error =
1558 ((CommandException) (ar.exception)).getCommandError();
1559 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1560 request.result =
1561 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1562 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001563 } else {
1564 loge("setAllowedCarriers: Unknown exception");
1565 }
1566 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001567 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001568 break;
1569
1570 case CMD_GET_ALLOWED_CARRIERS:
1571 request = (MainThreadRequest) msg.obj;
1572 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001573 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001574 break;
1575
1576 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 if (ar.exception == null && ar.result != null) {
1580 request.result = ar.result;
1581 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001582 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001583 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001584 if (ar.result == null) {
1585 loge("getAllowedCarriers: Empty response");
1586 } else if (ar.exception instanceof CommandException) {
1587 loge("getAllowedCarriers: CommandException: " +
1588 ar.exception);
1589 } else {
1590 loge("getAllowedCarriers: Unknown exception");
1591 }
1592 }
arunvoddud7401012022-12-15 16:08:12 +00001593 if (request.argument != null) {
1594 // This is for the implementation of carrierRestrictionStatus.
1595 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1596 Consumer<Integer> callback = callbackInfo.getConsumer();
Steve Statia28b7cb32024-03-11 23:58:50 +00001597 Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds();
arunvoddud7401012022-12-15 16:08:12 +00001598 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1599 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1600 CarrierRestrictionRules carrierRestrictionRules =
1601 (CarrierRestrictionRules) ar.result;
1602 int carrierId = -1;
1603 try {
1604 CarrierIdentifier carrierIdentifier =
1605 carrierRestrictionRules.getAllowedCarriers().get(0);
1606 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1607 carrierIdentifier);
1608 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1609 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1610 }
1611 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
Steve Statia28b7cb32024-03-11 23:58:50 +00001612 int restrictedStatus =
1613 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED;
1614 if (carrierId != -1 && callerCarrierIds.contains(carrierId) &&
1615 lockStatus == restrictedStatus) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001616 lockStatus = TelephonyManager
1617 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001618 }
1619 } else {
1620 Rlog.e(LOG_TAG,
1621 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1622 }
1623 callback.accept(lockStatus);
1624 } else {
1625 // This is for the implementation of getAllowedCarriers.
1626 notifyRequester(request);
1627 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001628 break;
1629
Nathan Haroldb3014052017-01-25 15:57:32 -08001630 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 if (ar.exception == null && ar.result != null) {
1634 request.result = ar.result;
1635 } else {
1636 request.result = new IllegalArgumentException(
1637 "Failed to retrieve Forbidden Plmns");
1638 if (ar.result == null) {
1639 loge("getForbiddenPlmns: Empty response");
1640 } else {
1641 loge("getForbiddenPlmns: Unknown exception");
1642 }
1643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001644 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001645 break;
1646
1647 case CMD_GET_FORBIDDEN_PLMNS:
1648 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001649 uiccPort = getUiccPortFromRequest(request);
1650 if (uiccPort == null) {
1651 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001652 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001653 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001654 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001655 break;
1656 }
1657 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001658 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001659 if (uiccApp == null) {
1660 loge("getForbiddenPlmns() no app with specified type -- "
1661 + appType);
1662 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001663 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001664 break;
1665 } else {
1666 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1667 + " specified type -- " + appType);
1668 }
1669 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1670 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001671 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001672 break;
1673
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001674 case CMD_SWITCH_SLOTS:
1675 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001676 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001677 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001678 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001679 break;
1680
1681 case EVENT_SWITCH_SLOTS_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001685 notifyRequester(request);
1686 break;
1687 case CMD_GET_NETWORK_SELECTION_MODE:
1688 request = (MainThreadRequest) msg.obj;
1689 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1690 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1691 break;
1692
1693 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1694 ar = (AsyncResult) msg.obj;
1695 request = (MainThreadRequest) ar.userObj;
1696 if (ar.exception != null) {
1697 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1698 } else {
1699 int mode = ((int[]) ar.result)[0];
1700 if (mode == 0) {
1701 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1702 } else {
1703 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1704 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001706 notifyRequester(request);
1707 break;
1708 case CMD_GET_CDMA_ROAMING_MODE:
1709 request = (MainThreadRequest) msg.obj;
1710 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1711 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1712 break;
1713 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 if (ar.exception != null) {
1717 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1718 } else {
1719 request.result = ((int[]) ar.result)[0];
1720 }
1721 notifyRequester(request);
1722 break;
1723 case CMD_SET_CDMA_ROAMING_MODE:
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1726 int mode = (int) request.argument;
1727 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1728 break;
1729 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1730 ar = (AsyncResult) msg.obj;
1731 request = (MainThreadRequest) ar.userObj;
1732 request.result = ar.exception == null;
1733 notifyRequester(request);
1734 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001735 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1736 request = (MainThreadRequest) msg.obj;
1737 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1738 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1739 break;
1740 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
1743 if (ar.exception != null) {
1744 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1745 } else {
1746 request.result = ((int[]) ar.result)[0];
1747 }
1748 notifyRequester(request);
1749 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001750 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1751 request = (MainThreadRequest) msg.obj;
1752 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1753 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001754 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1755 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001756 break;
1757 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1758 ar = (AsyncResult) msg.obj;
1759 request = (MainThreadRequest) ar.userObj;
1760 request.result = ar.exception == null;
1761 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001762 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001763 case CMD_GET_ALL_CELL_INFO:
1764 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001765 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001766 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001767 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001768 case EVENT_GET_ALL_CELL_INFO_DONE:
1769 ar = (AsyncResult) msg.obj;
1770 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001771 // If a timeout occurs, the response will be null
1772 request.result = (ar.exception == null && ar.result != null)
1773 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001774 synchronized (request) {
1775 request.notifyAll();
1776 }
1777 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001778 case CMD_REQUEST_CELL_INFO_UPDATE:
1779 request = (MainThreadRequest) msg.obj;
1780 request.phone.requestCellInfoUpdate(request.workSource,
1781 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1782 break;
1783 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1784 ar = (AsyncResult) msg.obj;
1785 request = (MainThreadRequest) ar.userObj;
1786 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1787 try {
1788 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001789 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001790 cb.onError(
1791 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1792 ar.exception.getClass().getName(),
1793 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001794 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001795 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001796 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001797 } else {
1798 // use the result as returned
1799 cb.onCellInfo((List<CellInfo>) ar.result);
1800 }
1801 } catch (RemoteException re) {
1802 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1803 }
1804 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001805 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001806 request = (MainThreadRequest) msg.obj;
1807 WorkSource ws = (WorkSource) request.argument;
1808 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001809 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001810 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001811 }
1812 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001813 ar = (AsyncResult) msg.obj;
1814 request = (MainThreadRequest) ar.userObj;
1815 if (ar.exception == null) {
1816 request.result = ar.result;
1817 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001818 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001819 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001820 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001821 }
1822
1823 synchronized (request) {
1824 request.notifyAll();
1825 }
1826 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001827 }
chen xu6dac5ab2018-10-26 17:39:23 -07001828 case CMD_MODEM_REBOOT:
1829 request = (MainThreadRequest) msg.obj;
1830 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001831 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001832 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001833 case EVENT_CMD_MODEM_REBOOT_DONE:
1834 handleNullReturnEvent(msg, "rebootModem");
1835 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001836 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001837 request = (MainThreadRequest) msg.obj;
1838 boolean enable = (boolean) request.argument;
1839 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001840 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001841 PhoneConfigurationManager.getInstance()
1842 .enablePhone(request.phone, enable, onCompleted);
1843 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001844 }
Michele Berionne5e411512020-11-13 02:36:59 +00001845 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001846 ar = (AsyncResult) msg.obj;
1847 request = (MainThreadRequest) ar.userObj;
1848 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001849 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001850 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001851 if ((boolean) request.result) {
1852 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1853 updateModemStateMetrics();
1854 } else {
1855 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1856 + ar.exception);
1857 }
1858 notifyRequester(request);
1859 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001860 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001861 case CMD_GET_MODEM_STATUS:
1862 request = (MainThreadRequest) msg.obj;
1863 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1864 PhoneConfigurationManager.getInstance()
1865 .getPhoneStatusFromModem(request.phone, onCompleted);
1866 break;
1867 case EVENT_GET_MODEM_STATUS_DONE:
1868 ar = (AsyncResult) msg.obj;
1869 request = (MainThreadRequest) ar.userObj;
1870 int id = request.phone.getPhoneId();
1871 if (ar.exception == null && ar.result != null) {
1872 request.result = ar.result;
1873 //update the cache as modem status has changed
1874 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1875 (boolean) request.result);
1876 } else {
1877 // Return true if modem status cannot be retrieved. For most cases,
1878 // modem status is on. And for older version modems, GET_MODEM_STATUS
1879 // and disable modem are not supported. Modem is always on.
1880 // TODO: this should be fixed in R to support a third
1881 // status UNKNOWN b/131631629
1882 request.result = true;
1883 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1884 + ar.exception);
1885 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001886 notifyRequester(request);
1887 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001888 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1889 request = (MainThreadRequest) msg.obj;
1890 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1891 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1892 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1893 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1894 break;
1895 }
1896 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1897 ar = (AsyncResult) msg.obj;
1898 request = (MainThreadRequest) ar.userObj;
1899 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1900 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1901 args.second.accept(ar.exception == null);
1902 notifyRequester(request);
1903 break;
1904 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001905 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1906 request = (MainThreadRequest) msg.obj;
1907 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1908 Phone phone = getPhoneFromRequest(request);
1909 if (phone != null) {
1910 phone.getSystemSelectionChannels(onCompleted);
1911 } else {
1912 loge("getSystemSelectionChannels: No phone object");
1913 request.result = new ArrayList<RadioAccessSpecifier>();
1914 notifyRequester(request);
1915 }
1916 break;
1917 }
1918 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1919 ar = (AsyncResult) msg.obj;
1920 request = (MainThreadRequest) ar.userObj;
1921 if (ar.exception == null && ar.result != null) {
1922 request.result = ar.result;
1923 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001924 request.result = new IllegalStateException(
1925 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001926 if (ar.result == null) {
1927 loge("getSystemSelectionChannels: Empty response");
1928 } else {
1929 loge("getSystemSelectionChannels: Unknown exception");
1930 }
1931 }
1932 notifyRequester(request);
1933 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001934 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1935 ar = (AsyncResult) msg.obj;
1936 request = (MainThreadRequest) ar.userObj;
1937 if (ar.exception == null && ar.result != null) {
1938 request.result = ar.result;
1939 } else {
1940 request.result = -1;
1941 loge("Failed to set Forbidden Plmns");
1942 if (ar.result == null) {
1943 loge("setForbidenPlmns: Empty response");
1944 } else if (ar.exception != null) {
1945 loge("setForbiddenPlmns: Exception: " + ar.exception);
1946 request.result = -1;
1947 } else {
1948 loge("setForbiddenPlmns: Unknown exception");
1949 }
1950 }
1951 notifyRequester(request);
1952 break;
1953 case CMD_SET_FORBIDDEN_PLMNS:
1954 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001955 uiccPort = getUiccPortFromRequest(request);
1956 if (uiccPort == null) {
1957 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001958 request.result = -1;
1959 notifyRequester(request);
1960 break;
1961 }
1962 Pair<Integer, List<String>> setFplmnsArgs =
1963 (Pair<Integer, List<String>>) request.argument;
1964 appType = setFplmnsArgs.first;
1965 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001966 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001967 if (uiccApp == null) {
1968 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1969 request.result = -1;
1970 loge("Failed to get UICC App");
1971 notifyRequester(request);
1972 } else {
1973 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1974 ((SIMRecords) uiccApp.getIccRecords())
1975 .setForbiddenPlmns(onCompleted, fplmns);
1976 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001977 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001978 case CMD_ERASE_MODEM_CONFIG:
1979 request = (MainThreadRequest) msg.obj;
1980 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1981 defaultPhone.eraseModemConfig(onCompleted);
1982 break;
1983 case EVENT_ERASE_MODEM_CONFIG_DONE:
1984 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001985 break;
zoey chene02881a2019-12-30 16:11:23 +08001986
Kai Shif70f46f2021-03-03 13:59:46 -08001987 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1988 request = (MainThreadRequest) msg.obj;
1989 request.result = defaultPhone.eraseDataInSharedPreferences();
1990 notifyRequester(request);
1991 break;
1992
zoey chene02881a2019-12-30 16:11:23 +08001993 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1994 request = (MainThreadRequest) msg.obj;
1995 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1996 Pair<String, String> changed = (Pair<String, String>) request.argument;
1997 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1998 changed.first, changed.second, onCompleted);
1999 break;
2000 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2001 ar = (AsyncResult) msg.obj;
2002 request = (MainThreadRequest) ar.userObj;
2003 if (ar.exception == null) {
2004 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002005 // If the operation is successful, update the PIN storage
2006 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2007 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002008 UiccController.getInstance().getPinStorage()
2009 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002010 } else {
2011 request.result = msg.arg1;
2012 }
2013 notifyRequester(request);
2014 break;
2015
Michele Berionne5e411512020-11-13 02:36:59 +00002016 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002017 request = (MainThreadRequest) msg.obj;
2018 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2019 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2020 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2021 enabled.first, enabled.second, onCompleted);
2022 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002023 }
zoey chene02881a2019-12-30 16:11:23 +08002024 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2025 ar = (AsyncResult) msg.obj;
2026 request = (MainThreadRequest) ar.userObj;
2027 if (ar.exception == null) {
2028 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002029 // If the operation is successful, update the PIN storage
2030 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2031 int phoneId = getPhoneFromRequest(request).getPhoneId();
2032 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002033 UiccController.getInstance().getPinStorage()
2034 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002035 } else {
2036 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2037 }
zoey chene02881a2019-12-30 16:11:23 +08002038 } else {
2039 request.result = msg.arg1;
2040 }
Michele Berionne5e411512020-11-13 02:36:59 +00002041
2042
zoey chene02881a2019-12-30 16:11:23 +08002043 notifyRequester(request);
2044 break;
2045
Peter Wangdafb9ac2020-01-15 14:13:38 -08002046 case MSG_NOTIFY_USER_ACTIVITY:
2047 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002048 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002049 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2050 getDefaultPhone().getContext().sendBroadcastAsUser(
2051 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2052 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002053
2054 case CMD_SET_DATA_THROTTLING: {
2055 request = (MainThreadRequest) msg.obj;
2056 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2057 DataThrottlingRequest dataThrottlingRequest =
2058 (DataThrottlingRequest) request.argument;
2059 Phone phone = getPhoneFromRequest(request);
2060 if (phone != null) {
2061 phone.setDataThrottling(onCompleted,
2062 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2063 dataThrottlingRequest.getCompletionDurationMillis());
2064 } else {
2065 loge("setDataThrottling: No phone object");
2066 request.result =
2067 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2068 notifyRequester(request);
2069 }
2070
2071 break;
2072 }
2073 case EVENT_SET_DATA_THROTTLING_DONE:
2074 ar = (AsyncResult) msg.obj;
2075 request = (MainThreadRequest) ar.userObj;
2076
2077 if (ar.exception == null) {
2078 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2079 } else if (ar.exception instanceof CommandException) {
2080 loge("setDataThrottling: CommandException: " + ar.exception);
2081 CommandException.Error error =
2082 ((CommandException) (ar.exception)).getCommandError();
2083
2084 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2085 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002086 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002087 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2088 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002089 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2090 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002091 } else {
2092 request.result =
2093 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2094 }
2095 } else {
2096 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2097 }
2098 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2099 notifyRequester(request);
2100 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002101
2102 case CMD_SET_SIM_POWER: {
2103 request = (MainThreadRequest) msg.obj;
2104 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2105 request = (MainThreadRequest) msg.obj;
2106 int stateToSet =
2107 ((Pair<Integer, IIntegerConsumer>)
2108 request.argument).first;
2109 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2110 break;
2111 }
2112 case EVENT_SET_SIM_POWER_DONE: {
2113 ar = (AsyncResult) msg.obj;
2114 request = (MainThreadRequest) ar.userObj;
2115 IIntegerConsumer callback =
2116 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2117 if (ar.exception != null) {
2118 loge("setSimPower exception: " + ar.exception);
2119 int errorCode = TelephonyManager.CallForwardingInfoCallback
2120 .RESULT_ERROR_UNKNOWN;
2121 if (ar.exception instanceof CommandException) {
2122 CommandException.Error error =
2123 ((CommandException) (ar.exception)).getCommandError();
2124 if (error == CommandException.Error.SIM_ERR) {
2125 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2126 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2127 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2128 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2129 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2130 } else {
2131 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2132 }
2133 }
2134 try {
2135 callback.accept(errorCode);
2136 } catch (RemoteException e) {
2137 // Ignore if the remote process is no longer available to call back.
2138 Log.w(LOG_TAG, "setSimPower: callback not available.");
2139 }
2140 } else {
2141 try {
2142 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2143 } catch (RemoteException e) {
2144 // Ignore if the remote process is no longer available to call back.
2145 Log.w(LOG_TAG, "setSimPower: callback not available.");
2146 }
2147 }
2148 break;
2149 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002150 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2151 request = (MainThreadRequest) msg.obj;
2152
2153 final Phone phone = getPhoneFromRequest(request);
2154 if (phone == null || phone.getServiceStateTracker() == null) {
2155 request.result = new IllegalStateException("Phone or SST is null");
2156 notifyRequester(request);
2157 break;
2158 }
2159
2160 Pair<Integer, SignalStrengthUpdateRequest> pair =
2161 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2162 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2163 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002164 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002165 request.subId, pair.first /*callingUid*/,
2166 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002167 break;
2168 }
2169 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2170 ar = (AsyncResult) msg.obj;
2171 request = (MainThreadRequest) ar.userObj;
2172 // request.result will be the exception of ar if present, true otherwise.
2173 // Be cautious not to leave result null which will wait() forever
2174 request.result = ar.exception != null ? ar.exception : true;
2175 notifyRequester(request);
2176 break;
2177 }
2178 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2179 request = (MainThreadRequest) msg.obj;
2180
2181 Phone phone = getPhoneFromRequest(request);
2182 if (phone == null || phone.getServiceStateTracker() == null) {
2183 request.result = new IllegalStateException("Phone or SST is null");
2184 notifyRequester(request);
2185 break;
2186 }
2187
2188 Pair<Integer, SignalStrengthUpdateRequest> pair =
2189 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2190 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2191 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002192 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002193 request.subId, pair.first /*callingUid*/,
2194 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002195 break;
2196 }
2197 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2198 ar = (AsyncResult) msg.obj;
2199 request = (MainThreadRequest) ar.userObj;
2200 request.result = ar.exception != null ? ar.exception : true;
2201 notifyRequester(request);
2202 break;
2203 }
Jordan Liu109698e2020-11-24 14:50:34 -08002204
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002205 case CMD_GET_SLICING_CONFIG: {
2206 request = (MainThreadRequest) msg.obj;
2207 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2208 request.phone.getSlicingConfig(onCompleted);
2209 break;
2210 }
2211 case EVENT_GET_SLICING_CONFIG_DONE: {
2212 ar = (AsyncResult) msg.obj;
2213 request = (MainThreadRequest) ar.userObj;
2214 ResultReceiver result = (ResultReceiver) request.argument;
2215
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002216 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002217 Bundle bundle = new Bundle();
2218 int resultCode = 0;
2219 if (ar.exception != null) {
2220 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2221 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002222 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002223 } else if (ar.result == null) {
2224 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002225 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002226 } else {
2227 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002228 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2229 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002230 }
2231
2232 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002233 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002234 }
2235 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2236 result.send(resultCode, bundle);
2237 notifyRequester(request);
2238 break;
2239 }
2240
Sarah Chin71b3a852022-09-28 15:54:19 -07002241 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242 request = (MainThreadRequest) msg.obj;
2243 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002244 PurchasePremiumCapabilityArgument arg =
2245 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chincc5446f2023-10-23 17:57:19 -07002246 SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
2247 .purchasePremiumCapability(arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002248 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002249 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002250
Sarah Chin71b3a852022-09-28 15:54:19 -07002251 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002252 ar = (AsyncResult) msg.obj;
2253 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002254 PurchasePremiumCapabilityArgument arg =
2255 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002256 try {
2257 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002258 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002259 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002260 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chinff8b1802023-04-11 14:22:14 -07002261 + ", result="
Sarah Chin2ec39f62022-08-31 17:03:26 -07002262 + TelephonyManager.convertPurchaseResultToString(result));
2263 } catch (RemoteException e) {
2264 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002265 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002266 + " failed: " + e;
2267 if (DBG) log(logStr);
2268 AnomalyReporter.reportAnomaly(
2269 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2270 }
2271 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002272 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002273
Michele Berionne5e411512020-11-13 02:36:59 +00002274 case CMD_PREPARE_UNATTENDED_REBOOT:
2275 request = (MainThreadRequest) msg.obj;
2276 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002277 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002278 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002279 notifyRequester(request);
2280 break;
2281
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 default:
2283 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2284 break;
2285 }
2286 }
Jake Hambye994d462014-02-03 13:10:13 -08002287
Pengquan Menga1bb6272018-09-06 09:59:22 -07002288 private void notifyRequester(MainThreadRequest request) {
2289 synchronized (request) {
2290 request.notifyAll();
2291 }
2292 }
2293
Jake Hambye994d462014-02-03 13:10:13 -08002294 private void handleNullReturnEvent(Message msg, String command) {
2295 AsyncResult ar = (AsyncResult) msg.obj;
2296 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2297 if (ar.exception == null) {
2298 request.result = true;
2299 } else {
2300 request.result = false;
2301 if (ar.exception instanceof CommandException) {
2302 loge(command + ": CommandException: " + ar.exception);
2303 } else {
2304 loge(command + ": Unknown exception");
2305 }
2306 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002307 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 }
2310
2311 /**
2312 * Posts the specified command to be executed on the main thread,
2313 * waits for the request to complete, and returns the result.
2314 * @see #sendRequestAsync
2315 */
2316 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002317 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2318 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002319 }
2320
2321 /**
2322 * Posts the specified command to be executed on the main thread,
2323 * waits for the request to complete, and returns the result.
2324 * @see #sendRequestAsync
2325 */
2326 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2327 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002328 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002329 }
2330
2331 /**
2332 * Posts the specified command to be executed on the main thread,
2333 * waits for the request to complete, and returns the result.
2334 * @see #sendRequestAsync
2335 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002336 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002337 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2338 }
2339
2340 /**
2341 * Posts the specified command to be executed on the main thread,
2342 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2343 * if not timeout or null otherwise.
2344 * @see #sendRequestAsync
2345 */
2346 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2347 long timeoutInMs) {
2348 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002349 }
2350
2351 /**
2352 * Posts the specified command to be executed on the main thread,
2353 * waits for the request to complete, and returns the result.
2354 * @see #sendRequestAsync
2355 */
Nathan Harold92bed182018-10-12 18:16:49 -07002356 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002357 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002358 }
2359
2360 /**
2361 * Posts the specified command to be executed on the main thread,
2362 * waits for the request to complete, and returns the result.
2363 * @see #sendRequestAsync
2364 */
2365 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002366 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2367 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002368 }
2369
2370 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002371 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2372 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2373 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002374 * @see #sendRequestAsync
2375 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002376 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2377 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2379 throw new RuntimeException("This method will deadlock if called from the main thread.");
2380 }
2381
Nathan Harold92bed182018-10-12 18:16:49 -07002382 MainThreadRequest request = null;
2383 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2384 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2385 } else if (phone != null) {
2386 request = new MainThreadRequest(argument, phone, workSource);
2387 } else {
2388 request = new MainThreadRequest(argument, subId, workSource);
2389 }
2390
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 Message msg = mMainThreadHandler.obtainMessage(command, request);
2392 msg.sendToTarget();
2393
Rambo Wang0f050d82021-02-12 11:43:36 -08002394
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002396 if (timeoutInMs >= 0) {
2397 // Wait for at least timeoutInMs before returning null request result
2398 long now = SystemClock.elapsedRealtime();
2399 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002400 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002401 try {
2402 request.wait(deadline - now);
2403 } catch (InterruptedException e) {
2404 // Do nothing, go back and check if request is completed or timeout
2405 } finally {
2406 now = SystemClock.elapsedRealtime();
2407 }
2408 }
2409 } else {
2410 // Wait for the request to complete
2411 while (request.result == null) {
2412 try {
2413 request.wait();
2414 } catch (InterruptedException e) {
2415 // Do nothing, go back and wait until the request is complete
2416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 }
2418 }
2419 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002420 if (request.result == null) {
2421 Log.wtf(LOG_TAG,
2422 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 return request.result;
2425 }
2426
2427 /**
2428 * Asynchronous ("fire and forget") version of sendRequest():
2429 * Posts the specified command to be executed on the main thread, and
2430 * returns immediately.
2431 * @see #sendRequest
2432 */
2433 private void sendRequestAsync(int command) {
2434 mMainThreadHandler.sendEmptyMessage(command);
2435 }
2436
2437 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002438 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002439 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002440 */
2441 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002442 sendRequestAsync(command, argument, null, null);
2443 }
2444
2445 /**
2446 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2447 * @see {@link #sendRequest(int,Object)}
2448 */
2449 private void sendRequestAsync(
2450 int command, Object argument, Phone phone, WorkSource workSource) {
2451 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002452 Message msg = mMainThreadHandler.obtainMessage(command, request);
2453 msg.sendToTarget();
2454 }
2455
2456 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 * Initialize the singleton PhoneInterfaceManager instance.
2458 * This is only done once, at startup, from PhoneApp.onCreate().
2459 */
Sarah Chincc5446f2023-10-23 17:57:19 -07002460 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 synchronized (PhoneInterfaceManager.class) {
2462 if (sInstance == null) {
Sarah Chincc5446f2023-10-23 17:57:19 -07002463 sInstance = new PhoneInterfaceManager(app, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 } else {
2465 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2466 }
2467 return sInstance;
2468 }
2469 }
2470
2471 /** Private constructor; @see init() */
Sarah Chincc5446f2023-10-23 17:57:19 -07002472 private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 mApp = app;
Sarah Chincc5446f2023-10-23 17:57:19 -07002474 mFeatureFlags = featureFlags;
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -08002475 mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002477 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002478 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002479 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2481 mMainThreadHandler = new MainThreadHandler();
Sarah Chin4beb2b72023-02-14 14:47:54 -08002482 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002483 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002484 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002485 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002486 mNotifyUserActivity = new AtomicBoolean(false);
joonhunshin4ac60942023-11-15 15:23:39 +00002487 mPackageManager = app.getPackageManager();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08002488 mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance(
2489 getDefaultPhone().getContext(), featureFlags);
joonhunshinf624b2a2024-04-18 04:42:12 +00002490 mVendorApiLevel = SystemProperties.getInt(
2491 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
2492
Tyler Gunn64144d92022-03-17 14:16:41 -07002493 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002494 publish();
arunvoddud7401012022-12-15 16:08:12 +00002495 CarrierAllowListInfo.loadInstance(mApp);
Hyosun Kim240214a2023-11-02 13:30:15 +00002496
2497 // Create the SatelliteEntitlementController singleton, for using the get the
2498 // entitlementStatus for satellite service.
2499 SatelliteEntitlementController.make(mApp, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002502 @VisibleForTesting
2503 public SharedPreferences getSharedPreferences() {
2504 return mTelephonySharedPreferences;
2505 }
2506
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002507 /**
2508 * Get the default phone for this device.
2509 */
2510 @VisibleForTesting
2511 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002512 Phone thePhone = getPhone(getDefaultSubscription());
2513 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2514 }
2515
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 private void publish() {
2517 if (DBG) log("publish: " + this);
2518
Peter Wangc035ce42020-01-08 21:00:22 -08002519 TelephonyFrameworkInitializer
2520 .getTelephonyServiceManager()
2521 .getTelephonyServiceRegisterer()
2522 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 }
2524
Stuart Scott584921c2015-01-15 17:10:34 -08002525 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002526 if (request.phone != null) {
2527 return request.phone;
2528 } else {
2529 return getPhoneFromSubId(request.subId);
2530 }
2531 }
2532
2533 private Phone getPhoneFromSubId(int subId) {
2534 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2535 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002536 }
2537
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002538 /**
2539 * Get phone object associated with a subscription.
2540 * Return default phone if phone object associated with subscription is null
2541 * @param subId - subscriptionId
2542 * @return phone object associated with a subscription or default phone if null.
2543 */
Ling Mac28f0212023-03-24 16:07:15 -07002544 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002545 Phone phone = getPhoneFromSubId(subId);
2546 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002547 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002548 phone = getDefaultPhone();
2549 }
2550 return phone;
2551 }
2552
Rambo Wange53e07d2022-05-10 13:01:13 -07002553 @Nullable
2554 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002555 Phone phone = getPhoneFromRequest(request);
2556 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002557 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002558 }
2559
Ling Mac28f0212023-03-24 16:07:15 -07002560 /**
2561 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2562 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2563 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2564 * @return The Phone associated the sub Id
2565 */
2566 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002567 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569
Kai Shif70f46f2021-03-03 13:59:46 -08002570 private void sendEraseModemConfig(@NonNull Phone phone) {
2571 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2572 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2573 }
2574
2575 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2576 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2577 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002578 }
2579
Peter Wang44b186e2020-01-13 23:33:09 -08002580 private boolean isImsAvailableOnDevice() {
2581 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2582 if (pm == null) {
2583 // For some reason package manger is not available.. This will fail internally anyway,
2584 // so do not throw error and allow.
2585 return true;
2586 }
2587 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2588 }
2589
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590 public void dial(String number) {
joonhunshin4ac60942023-11-15 15:23:39 +00002591 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2592 PackageManager.FEATURE_TELEPHONY_CALLING, "dial");
2593
Wink Savilleadd7cc52014-09-08 14:23:09 -07002594 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002595 }
2596
Wink Savilleb564aae2014-10-23 10:18:09 -07002597 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598 if (DBG) log("dial: " + number);
2599 // No permission check needed here: This is just a wrapper around the
2600 // ACTION_DIAL intent, which is available to any app since it puts up
2601 // the UI before it does anything.
2602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 final long identity = Binder.clearCallingIdentity();
2604 try {
2605 String url = createTelUrl(number);
2606 if (url == null) {
2607 return;
2608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610 // PENDING: should we just silently fail if phone is offhook or ringing?
2611 PhoneConstants.State state = mCM.getState(subId);
2612 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2613 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2614 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2615 mApp.startActivity(intent);
2616 }
2617 } finally {
2618 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 }
2620 }
2621
2622 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002623 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002624 }
2625
Wink Savilleb564aae2014-10-23 10:18:09 -07002626 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 if (DBG) log("call: " + number);
2628
2629 // This is just a wrapper around the ACTION_CALL intent, but we still
2630 // need to do a permission check since we're calling startActivity()
2631 // from the context of the phone app.
2632 enforceCallPermission();
2633
Jordan Liu1617b712019-07-10 15:06:26 -07002634 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 != AppOpsManager.MODE_ALLOWED) {
2636 return;
2637 }
2638
joonhunshin4ac60942023-11-15 15:23:39 +00002639 enforceTelephonyFeatureWithException(callingPackage,
2640 PackageManager.FEATURE_TELEPHONY_CALLING, "call");
2641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 String url = createTelUrl(number);
2645 if (url == null) {
2646 return;
2647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649 boolean isValid = false;
2650 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2651 if (slist != null) {
2652 for (SubscriptionInfo subInfoRecord : slist) {
2653 if (subInfoRecord.getSubscriptionId() == subId) {
2654 isValid = true;
2655 break;
2656 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002657 }
Wink Saville08874612014-08-31 19:19:58 -07002658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 if (!isValid) {
2660 return;
2661 }
Wink Saville08874612014-08-31 19:19:58 -07002662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2664 intent.putExtra(SUBSCRIPTION_KEY, subId);
2665 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2666 mApp.startActivity(intent);
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 }
2671
Wink Savilleb564aae2014-10-23 10:18:09 -07002672 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002673 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002674 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2675 }
2676
Wink Savilleb564aae2014-10-23 10:18:09 -07002677 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002678 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002679 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2680 }
2681
Wink Savilleb564aae2014-10-23 10:18:09 -07002682 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
joonhunshin4ac60942023-11-15 15:23:39 +00002685 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2686 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
2687 "supplyPinReportResultForSubscriber");
2688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 final long identity = Binder.clearCallingIdentity();
2690 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002691 Phone phone = getPhone(subId);
2692 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 checkSimPin.start();
2694 return checkSimPin.unlockSim(null, pin);
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
2697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699
Wink Savilleb564aae2014-10-23 10:18:09 -07002700 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
joonhunshin4ac60942023-11-15 15:23:39 +00002703 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2704 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber");
2705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706 final long identity = Binder.clearCallingIdentity();
2707 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002708 Phone phone = getPhone(subId);
2709 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 checkSimPuk.start();
2711 return checkSimPuk.unlockSim(puk, pin);
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
2714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 }
2716
2717 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002718 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 * a synchronous one.
2720 */
2721 private static class UnlockSim extends Thread {
2722
2723 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002724 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725
2726 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002727 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2728 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729
2730 // For replies from SimCard interface
2731 private Handler mHandler;
2732
2733 // For async handler to identify request type
2734 private static final int SUPPLY_PIN_COMPLETE = 100;
arunvoddu7bf930c2024-05-20 04:24:40 +00002735 private static final int SUPPLY_PIN_DELAYED = 101;
2736 private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000;
2737 private static final UUID SUPPLY_PIN_UUID = UUID.fromString(
2738 "d3768135-4323-491d-a6c8-bda01fc89040");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739
Michele Berionne5e411512020-11-13 02:36:59 +00002740 UnlockSim(int phoneId, IccCard simCard) {
2741 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 mSimCard = simCard;
2743 }
2744
2745 @Override
2746 public void run() {
2747 Looper.prepare();
2748 synchronized (UnlockSim.this) {
2749 mHandler = new Handler() {
2750 @Override
2751 public void handleMessage(Message msg) {
2752 AsyncResult ar = (AsyncResult) msg.obj;
2753 switch (msg.what) {
2754 case SUPPLY_PIN_COMPLETE:
2755 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2756 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002757 mRetryCount = msg.arg1;
2758 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002759 CommandException.Error error = null;
2760 if (ar.exception instanceof CommandException) {
2761 error = ((CommandException) (ar.exception))
2762 .getCommandError();
2763 }
2764 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002765 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002766 } else if (error == CommandException.Error.ABORTED) {
2767 /* When UiccCardApp dispose, handle message and return
2768 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002769 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002770 } else {
2771 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2772 }
2773 } else {
2774 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 mDone = true;
arunvoddu7bf930c2024-05-20 04:24:40 +00002777 removeMessages(SUPPLY_PIN_DELAYED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 UnlockSim.this.notifyAll();
2779 }
2780 break;
arunvoddu7bf930c2024-05-20 04:24:40 +00002781 case SUPPLY_PIN_DELAYED:
2782 if(!mDone) {
2783 String logStr = "Delay in receiving SIM PIN response ";
2784 if (DBG) log(logStr);
2785 AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr);
2786 }
2787 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002788 }
2789 }
2790 };
2791 UnlockSim.this.notifyAll();
2792 }
2793 Looper.loop();
2794 }
2795
2796 /*
2797 * Use PIN or PUK to unlock SIM card
2798 *
2799 * If PUK is null, unlock SIM card with PIN
2800 *
2801 * If PUK is not null, unlock SIM card with PUK and set PIN code
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302802 *
2803 * Besides, since it is reused in class level, the thread's looper will be stopped to avoid
2804 * its thread leak.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 */
Wink Saville9de0f752013-10-22 19:04:03 -07002806 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002807
2808 while (mHandler == null) {
2809 try {
2810 wait();
2811 } catch (InterruptedException e) {
2812 Thread.currentThread().interrupt();
2813 }
2814 }
2815 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2816
2817 if (puk == null) {
2818 mSimCard.supplyPin(pin, callback);
2819 } else {
2820 mSimCard.supplyPuk(puk, pin, callback);
2821 }
2822
2823 while (!mDone) {
2824 try {
2825 Log.d(LOG_TAG, "wait for done");
arunvoddu7bf930c2024-05-20 04:24:40 +00002826 mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED,
2827 SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 wait();
2829 } catch (InterruptedException e) {
2830 // Restore the interrupted status
2831 Thread.currentThread().interrupt();
2832 }
2833 }
2834 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002835 int[] resultArray = new int[2];
2836 resultArray[0] = mResult;
2837 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002838
2839 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002840 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002841 }
Mengjun Leng7ddbbfc2023-08-17 11:53:32 +05302842 // This instance is no longer reused, so quit its thread's looper.
2843 mHandler.getLooper().quitSafely();
Michele Berionne5e411512020-11-13 02:36:59 +00002844
Wink Saville9de0f752013-10-22 19:04:03 -07002845 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 }
2847 }
2848
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002849 /**
2850 * This method has been removed due to privacy and stability concerns.
2851 */
2852 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002853 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002854 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2855 return;
Wink Saville36469e72014-06-11 15:17:00 -07002856 }
2857
Nathan Harold1f889d82020-06-04 17:05:26 -07002858 @Override
2859 public void updateServiceLocationWithPackageName(String callingPackage) {
2860 mApp.getSystemService(AppOpsManager.class)
2861 .checkPackage(Binder.getCallingUid(), callingPackage);
2862
Nathan Haroldf096d982020-11-18 17:18:06 -08002863 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002864 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2865 // Callers targeting S have no business invoking this method.
2866 return;
2867 }
2868
2869 LocationAccessPolicy.LocationPermissionResult locationResult =
2870 LocationAccessPolicy.checkLocationPermission(mApp,
2871 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2872 .setCallingPackage(callingPackage)
2873 .setCallingFeatureId(null)
2874 .setCallingPid(Binder.getCallingPid())
2875 .setCallingUid(Binder.getCallingUid())
2876 .setMethod("updateServiceLocation")
2877 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2878 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2879 .build());
2880 // Apps that lack location permission have no business calling this method;
2881 // however, because no permission was declared in the public API, denials must
2882 // all be "soft".
2883 switch (locationResult) {
2884 case DENIED_HARD: /* fall through */
2885 case DENIED_SOFT:
2886 return;
2887 }
2888
2889 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 final long identity = Binder.clearCallingIdentity();
2891 try {
Ling Mac28f0212023-03-24 16:07:15 -07002892 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893 } finally {
2894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 }
2897
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002898 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002899 @Override
2900 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002901 return isRadioOnWithFeature(callingPackage, null);
2902 }
2903
2904
2905 @Override
2906 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2907 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2908 callingFeatureId);
2909 }
2910
2911 @Deprecated
2912 @Override
2913 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2914 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002915 }
2916
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002917 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002918 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2919 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002921 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002922 return false;
2923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924
joonhunshin4ac60942023-11-15 15:23:39 +00002925 enforceTelephonyFeatureWithException(callingPackage,
2926 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature");
2927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 return isRadioOnForSubscriber(subId);
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
2933 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002934 }
2935
2936 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 final Phone phone = getPhone(subId);
2940 if (phone != null) {
2941 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2942 } else {
2943 return false;
2944 }
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 }
2949
2950 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002951 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 }
Wink Saville36469e72014-06-11 15:17:00 -07002953
Wink Savilleb564aae2014-10-23 10:18:09 -07002954 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002955 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956
joonhunshin4ac60942023-11-15 15:23:39 +00002957 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2958 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber");
2959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 final long identity = Binder.clearCallingIdentity();
2961 try {
2962 final Phone phone = getPhone(subId);
2963 if (phone != null) {
2964 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2965 }
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002968 }
Wink Saville36469e72014-06-11 15:17:00 -07002969 }
2970
2971 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002972 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002973 }
2974
Wink Savilleb564aae2014-10-23 10:18:09 -07002975 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002976 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977
2978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 final Phone phone = getPhone(subId);
2981 if (phone == null) {
2982 return false;
2983 }
2984 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2985 toggleRadioOnOffForSubscriber(subId);
2986 }
2987 return true;
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 }
Wink Saville36469e72014-06-11 15:17:00 -07002992
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002993 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002994 enforceReadPrivilegedPermission("needMobileRadioShutdown");
joonhunshin4ac60942023-11-15 15:23:39 +00002995
2996 enforceTelephonyFeatureWithException(getCurrentPackageName(),
2997 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown");
2998
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002999 /*
3000 * If any of the Radios are available, it will need to be
3001 * shutdown. So return true if any Radio is available.
3002 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 final long identity = Binder.clearCallingIdentity();
3004 try {
3005 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3006 Phone phone = PhoneFactory.getPhone(i);
3007 if (phone != null && phone.isRadioAvailable()) return true;
3008 }
3009 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3010 return false;
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003013 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003014 }
3015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003017 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 enforceModifyPermission();
3019
joonhunshin4ac60942023-11-15 15:23:39 +00003020 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3021 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios");
3022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3026 logv("Shutting down Phone " + i);
3027 shutdownRadioUsingPhoneId(i);
3028 }
3029 } finally {
3030 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003031 }
3032 }
3033
3034 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003035 Phone phone = PhoneFactory.getPhone(phoneId);
3036 if (phone != null && phone.isRadioAvailable()) {
3037 phone.shutdownRadio();
3038 }
3039 }
3040
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003042 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043
Ling Ma83dc5ea2023-01-12 15:06:04 -08003044 if (!turnOn) {
3045 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3046 }
3047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3051 if (defaultPhone != null) {
3052 defaultPhone.setRadioPower(turnOn);
3053 return true;
3054 } else {
3055 loge("There's no default phone.");
3056 return false;
3057 }
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003060 }
Wink Saville36469e72014-06-11 15:17:00 -07003061 }
3062
Wink Savilleb564aae2014-10-23 10:18:09 -07003063 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065
Ling Ma83dc5ea2023-01-12 15:06:04 -08003066 if (!turnOn) {
3067 log("setRadioPowerForSubscriber off: subId=" + subId
3068 + ",callingPackage=" + getCurrentPackageName());
3069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 final Phone phone = getPhone(subId);
3073 if (phone != null) {
3074 phone.setRadioPower(turnOn);
3075 return true;
3076 } else {
3077 return false;
3078 }
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003082 }
3083
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003084 /**
3085 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3086 * no reason to power it off. When any of the voters want to power it off, it will be turned
3087 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3088 * powering it off, and these radio off votes will be cleared.
3089 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3090 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3091 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3092 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3093 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3094 * check its vote.
3095 *
3096 * @param subId The subscription ID.
3097 * @param reason The reason for powering off radio.
3098 * @return true on success and false on failure.
3099 */
3100 public boolean requestRadioPowerOffForReason(int subId,
3101 @TelephonyManager.RadioPowerReason int reason) {
3102 enforceModifyPermission();
3103
joonhunshin4ac60942023-11-15 15:23:39 +00003104 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3105 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason");
3106
Ling Ma83dc5ea2023-01-12 15:06:04 -08003107 log("requestRadioPowerOffForReason: subId=" + subId
3108 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003109 final long identity = Binder.clearCallingIdentity();
3110 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003111 boolean result = false;
3112 for (Phone phone : PhoneFactory.getPhones()) {
3113 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003114 phone.setRadioPowerForReason(false, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003115 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003116 if (!result) {
3117 loge("requestRadioPowerOffForReason: no phone exists");
3118 }
3119 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
3123 }
3124
3125 /**
3126 * Remove the vote on powering off the radio for a reason, as requested by
3127 * {@link requestRadioPowerOffForReason}.
3128 *
3129 * @param subId The subscription ID.
3130 * @param reason The reason for powering off radio.
3131 * @return true on success and false on failure.
3132 */
3133 public boolean clearRadioPowerOffForReason(int subId,
3134 @TelephonyManager.RadioPowerReason int reason) {
3135 enforceModifyPermission();
3136
joonhunshin4ac60942023-11-15 15:23:39 +00003137 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3138 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason");
3139
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003140 final long identity = Binder.clearCallingIdentity();
3141 try {
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003142 boolean result = false;
3143 for (Phone phone : PhoneFactory.getPhones()) {
3144 result = true;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003145 phone.setRadioPowerForReason(true, reason);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003146 }
Thomas Nguyen45d46d62023-09-28 21:11:06 -07003147 if (!result) {
3148 loge("clearRadioPowerOffForReason: no phone exists");
3149 }
3150 return result;
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
3154 }
3155
3156 /**
3157 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3158 *
3159 * @param subId The subscription ID.
3160 * @param callingPackage The package making the call.
3161 * @param callingFeatureId The feature in the package.
3162 * @return List of reasons for powering off radio.
3163 */
3164 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3165 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3166
joonhunshin4ac60942023-11-15 15:23:39 +00003167 enforceTelephonyFeatureWithException(callingPackage,
3168 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons");
3169
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003170 final long identity = Binder.clearCallingIdentity();
3171 List result = new ArrayList();
3172 try {
3173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3174 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3175 return result;
3176 }
3177
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003178 final Phone phone = getPhoneFromSubIdOrDefault(subId);
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003179 if (phone != null) {
3180 result.addAll(phone.getRadioPowerOffReasons());
Thomas Nguyenb47fc3c2023-04-06 13:30:32 -07003181 } else {
3182 loge("getRadioPowerOffReasons: phone is null");
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003183 }
3184 } finally {
3185 Binder.restoreCallingIdentity(identity);
3186 }
3187 return result;
3188 }
3189
Wink Saville36469e72014-06-11 15:17:00 -07003190 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003191 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003192 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194
joonhunshin4ac60942023-11-15 15:23:39 +00003195 enforceTelephonyFeatureWithException(callingPackage,
3196 PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity");
3197
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198 final long identity = Binder.clearCallingIdentity();
3199 try {
Jack Yu285100e2022-12-02 22:48:35 -08003200 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003202 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003203 phone.getDataSettingsManager().setDataEnabled(
3204 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 return true;
3206 } else {
3207 return false;
3208 }
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 }
3213
Wink Saville36469e72014-06-11 15:17:00 -07003214 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003215 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003216 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003217 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218
joonhunshin4ac60942023-11-15 15:23:39 +00003219 enforceTelephonyFeatureWithException(callingPackage,
3220 PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity");
3221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222 final long identity = Binder.clearCallingIdentity();
3223 try {
Jack Yu285100e2022-12-02 22:48:35 -08003224 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225 final Phone phone = getPhone(subId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00003226 if (phone != null && phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003227 phone.getDataSettingsManager().setDataEnabled(
3228 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 return true;
3230 } else {
3231 return false;
3232 }
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003236 }
3237
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003239 public boolean isDataConnectivityPossible(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003240 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3241 PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible");
3242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003243 final long identity = Binder.clearCallingIdentity();
3244 try {
3245 final Phone phone = getPhone(subId);
3246 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003247 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 } else {
3249 return false;
3250 }
3251 } finally {
3252 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003254 }
3255
3256 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003257 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003258 }
3259
pkanwarae03a6b2016-11-06 20:37:09 -08003260 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003261 enforceCallPermission();
3262
joonhunshin4ac60942023-11-15 15:23:39 +00003263 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3264 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest");
3265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3269 return;
3270 }
3271 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3272 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3273 } finally {
3274 Binder.restoreCallingIdentity(identity);
3275 }
pkanwar32d516d2016-10-14 19:37:38 -07003276 };
3277
Wink Savilleb564aae2014-10-23 10:18:09 -07003278 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003279 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280
joonhunshin4ac60942023-11-15 15:23:39 +00003281 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3282 PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber");
3283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284 final long identity = Binder.clearCallingIdentity();
3285 try {
3286 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3287 return false;
3288 }
3289 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003293 }
3294
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003295 /**
3296 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3297 * tag on getCallState Binder call.
3298 */
3299 @Deprecated
3300 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003301 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003302 if (CompatChanges.isChangeEnabled(
3303 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3304 Binder.getCallingUid())) {
3305 // Do not allow this API to be called on API version 31+, it should only be
3306 // called on old apps using this Binder call directly.
3307 throw new SecurityException("This method can only be used for applications "
3308 + "targeting API version 30 or less.");
3309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310 final long identity = Binder.clearCallingIdentity();
3311 try {
Ling Mac28f0212023-03-24 16:07:15 -07003312 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3313 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
3317 }
3318
3319 @Override
3320 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3321 if (CompatChanges.isChangeEnabled(
3322 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3323 Binder.getCallingUid())) {
3324 // Check READ_PHONE_STATE for API version 31+
3325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3326 featureId, "getCallStateForSubscription")) {
3327 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3328 + "targeting API level 31+.");
3329 }
3330 }
joonhunshin4ac60942023-11-15 15:23:39 +00003331
3332 enforceTelephonyFeatureWithException(callingPackage,
3333 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription");
3334
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3339 PhoneConstantConversions.convertCallState(phone.getState());
3340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003343 }
3344
Sanket Padawe356d7632015-06-22 14:03:32 -07003345 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003346 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003347 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003348 }
3349
3350 @Override
3351 public int getDataStateForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003352 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3353 PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId");
3354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 final long identity = Binder.clearCallingIdentity();
3356 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003357 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003359 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003360 } else {
3361 return PhoneConstantConversions.convertDataState(
3362 PhoneConstants.DataState.DISCONNECTED);
3363 }
3364 } finally {
3365 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003367 }
3368
Sanket Padawe356d7632015-06-22 14:03:32 -07003369 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003370 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003371 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003372 }
3373
3374 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003375 public @DataActivityType int getDataActivityForSubId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003376 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3377 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId");
3378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003379 final long identity = Binder.clearCallingIdentity();
3380 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003381 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003383 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003384 } else {
3385 return TelephonyManager.DATA_ACTIVITY_NONE;
3386 }
3387 } finally {
3388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 }
3391
3392 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003393 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003394 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003395 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003396
3397 LocationAccessPolicy.LocationPermissionResult locationResult =
3398 LocationAccessPolicy.checkLocationPermission(mApp,
3399 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3400 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003401 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003402 .setCallingPid(Binder.getCallingPid())
3403 .setCallingUid(Binder.getCallingUid())
3404 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003405 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003406 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3407 .build());
3408 switch (locationResult) {
3409 case DENIED_HARD:
3410 throw new SecurityException("Not allowed to access cell location");
3411 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003412 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3413 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003414 }
3415
joonhunshin4ac60942023-11-15 15:23:39 +00003416 enforceTelephonyFeatureWithException(callingPackage,
3417 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation");
3418
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003419 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003423 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003424 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
Svetoslav64fad262015-04-14 14:35:21 -07003428 }
3429
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003430 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003431 public String getNetworkCountryIsoForPhone(int phoneId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003432 if (!mApp.getResources().getBoolean(
3433 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3434 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3435 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone");
3436 }
joonhunshin4ac60942023-11-15 15:23:39 +00003437
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003438 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3439 // registered cell info, so return a NULL country instead.
3440 final long identity = Binder.clearCallingIdentity();
3441 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003442 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3443 // Get default phone in this case.
3444 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3445 }
Jack Yu285100e2022-12-02 22:48:35 -08003446 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003448 if (phone == null) return "";
3449 ServiceStateTracker sst = phone.getServiceStateTracker();
3450 if (sst == null) return "";
3451 LocaleTracker lt = sst.getLocaleTracker();
3452 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003453 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003454 } finally {
3455 Binder.restoreCallingIdentity(identity);
3456 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003457 }
3458
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003459 /**
3460 * This method was removed due to potential issues caused by performing partial
3461 * updates of service state, and lack of a credible use case.
3462 *
3463 * This has the ability to break the telephony implementation by disabling notification of
3464 * changes in device connectivity. DO NOT USE THIS!
3465 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003466 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003467 public void enableLocationUpdates() {
3468 mApp.enforceCallingOrSelfPermission(
3469 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003470 }
3471
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003472 /**
3473 * This method was removed due to potential issues caused by performing partial
3474 * updates of service state, and lack of a credible use case.
3475 *
3476 * This has the ability to break the telephony implementation by disabling notification of
3477 * changes in device connectivity. DO NOT USE THIS!
3478 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003479 @Override
3480 public void disableLocationUpdates() {
3481 mApp.enforceCallingOrSelfPermission(
3482 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483 }
3484
3485 @Override
3486 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003487 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3488 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003489 try {
3490 mApp.getSystemService(AppOpsManager.class)
3491 .checkPackage(Binder.getCallingUid(), callingPackage);
3492 } catch (SecurityException e) {
3493 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3494 throw e;
3495 }
3496
Nathan Haroldf096d982020-11-18 17:18:06 -08003497 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003498 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3499 throw new SecurityException(
3500 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3501 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003502
Jordan Liu1617b712019-07-10 15:06:26 -07003503 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003504 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3505 return null;
3506 }
Svetoslav64fad262015-04-14 14:35:21 -07003507
joonhunshin4ac60942023-11-15 15:23:39 +00003508 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3509 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo");
3510
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003511 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003512
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003513 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003514 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003515
Nathan Haroldf180aac2018-06-01 18:43:55 -07003516 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3517 for (CellInfo ci : info) {
3518 if (ci instanceof CellInfoGsm) {
3519 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3520 } else if (ci instanceof CellInfoWcdma) {
3521 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003523 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003524 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 }
3526
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003527 private List<CellInfo> getCachedCellInfo() {
3528 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3529 for (Phone phone : PhoneFactory.getPhones()) {
3530 List<CellInfo> info = phone.getAllCellInfo();
3531 if (info != null) cellInfos.addAll(info);
3532 }
3533 return cellInfos;
3534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003535
3536 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003537 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003538 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003539 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003540
3541 LocationAccessPolicy.LocationPermissionResult locationResult =
3542 LocationAccessPolicy.checkLocationPermission(mApp,
3543 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3544 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003545 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003546 .setCallingPid(Binder.getCallingPid())
3547 .setCallingUid(Binder.getCallingUid())
3548 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003549 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003550 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3551 .build());
3552 switch (locationResult) {
3553 case DENIED_HARD:
3554 throw new SecurityException("Not allowed to access cell info");
3555 case DENIED_SOFT:
3556 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003557 }
3558
Nathan Haroldf096d982020-11-18 17:18:06 -08003559 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003560 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3561 return getCachedCellInfo();
3562 }
3563
joonhunshin4ac60942023-11-15 15:23:39 +00003564 enforceTelephonyFeatureWithException(callingPackage,
3565 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo");
3566
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003567 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003568 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3572 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003573 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003574 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575 if (info != null) cellInfos.addAll(info);
3576 }
3577 return cellInfos;
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003580 }
3581 }
3582
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003583 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003584 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3585 String callingFeatureId) {
3586 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3587 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003588 }
3589
3590 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003591 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3592 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003593 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003594 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003595 }
3596
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003597 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3598 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003599 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003600 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003601
3602 LocationAccessPolicy.LocationPermissionResult locationResult =
3603 LocationAccessPolicy.checkLocationPermission(mApp,
3604 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3605 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003606 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003607 .setCallingPid(Binder.getCallingPid())
3608 .setCallingUid(Binder.getCallingUid())
3609 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003610 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3611 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003612 .build());
3613 switch (locationResult) {
3614 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003615 if (TelephonyPermissions
3616 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003617 // Safetynet logging for b/154934934
3618 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3619 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003620 throw new SecurityException("Not allowed to access cell info");
3621 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003622 if (TelephonyPermissions
3623 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003624 // Safetynet logging for b/154934934
3625 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3626 }
Nathan Harold5320c422019-05-09 10:26:08 -07003627 try {
3628 cb.onCellInfo(new ArrayList<CellInfo>());
3629 } catch (RemoteException re) {
3630 // Drop without consequences
3631 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003632 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003633 }
3634
joonhunshin4ac60942023-11-15 15:23:39 +00003635 enforceTelephonyFeatureWithException(callingPackage,
3636 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal");
Nathan Harolda939a962019-05-09 10:13:47 -07003637
3638 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003639 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3640
3641 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3642 }
3643
3644 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003645 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003646 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003647 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003651 Phone phone = getPhone(subId);
3652 if (phone == null) {
3653 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3654 } else {
3655 phone.setCellInfoListRate(rateInMillis, workSource);
3656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003660 }
3661
Shishir Agrawala9f32182016-04-12 12:00:16 -07003662 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003663 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003664 Phone phone = PhoneFactory.getPhone(slotIndex);
3665 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003666 return null;
3667 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003668 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003669 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003670 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003671 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003672 return null;
3673 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003674
joonhunshin4ac60942023-11-15 15:23:39 +00003675 enforceTelephonyFeatureWithException(callingPackage,
3676 PackageManager.FEATURE_TELEPHONY_GSM, "getImeiForSlot");
3677
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003678 final long identity = Binder.clearCallingIdentity();
3679 try {
3680 return phone.getImei();
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
3683 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003684 }
3685
3686 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003687 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3688 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3689 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3690 callingFeatureId, "getPrimaryImei")) {
3691 throw new SecurityException("Caller does not have permission");
3692 }
joonhunshin4ac60942023-11-15 15:23:39 +00003693
3694 enforceTelephonyFeatureWithException(callingPackage,
3695 PackageManager.FEATURE_TELEPHONY_GSM, "getPrimaryImei");
3696
arunvoddud5c6ce02022-12-11 06:03:12 +00003697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 for (Phone phone : PhoneFactory.getPhones()) {
3700 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3701 return phone.getImei();
3702 }
3703 }
3704 throw new UnsupportedOperationException("Operation not supported");
3705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
3708 }
3709
3710 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003711 public String getTypeAllocationCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003712 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3713 PackageManager.FEATURE_TELEPHONY_GSM, "getTypeAllocationCodeForSlot");
3714
David Kelly5e06a7f2018-03-12 14:10:59 +00003715 Phone phone = PhoneFactory.getPhone(slotIndex);
3716 String tac = null;
3717 if (phone != null) {
3718 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003719 try {
3720 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3721 } catch (IndexOutOfBoundsException e) {
3722 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3723 return null;
3724 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003725 }
3726 return tac;
3727 }
3728
3729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003730 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003731 try {
3732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3733 } catch (SecurityException se) {
3734 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3735 throw new SecurityException("Package " + callingPackage + " does not belong to "
3736 + Binder.getCallingUid());
3737 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003738 Phone phone = PhoneFactory.getPhone(slotIndex);
3739 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003740 return null;
3741 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742
Jeff Davidson913390f2018-02-23 17:11:49 -08003743 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003744 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003745 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003746 return null;
3747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748
joonhunshin4ac60942023-11-15 15:23:39 +00003749 enforceTelephonyFeatureWithException(callingPackage,
3750 PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot");
3751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 return phone.getMeid();
3755 } finally {
3756 Binder.restoreCallingIdentity(identity);
3757 }
Jack Yu2af8d712017-03-15 17:14:14 -07003758 }
3759
3760 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003761 public String getManufacturerCodeForSlot(int slotIndex) {
joonhunshin4ac60942023-11-15 15:23:39 +00003762 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3763 PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot");
3764
David Kelly5e06a7f2018-03-12 14:10:59 +00003765 Phone phone = PhoneFactory.getPhone(slotIndex);
3766 String manufacturerCode = null;
3767 if (phone != null) {
3768 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003769 try {
3770 manufacturerCode =
3771 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3772 } catch (IndexOutOfBoundsException e) {
3773 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3774 return null;
3775 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003776 }
3777 return manufacturerCode;
3778 }
3779
3780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003781 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3782 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003783 Phone phone = PhoneFactory.getPhone(slotIndex);
3784 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003785 return null;
3786 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003787 int subId = phone.getSubId();
3788 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003789 mApp, subId, callingPackage, callingFeatureId,
3790 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003791 return null;
3792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793
joonhunshin4ac60942023-11-15 15:23:39 +00003794 enforceTelephonyFeatureWithException(callingPackage,
3795 PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot");
3796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 return phone.getDeviceSvn();
3800 } finally {
3801 Binder.restoreCallingIdentity(identity);
3802 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003803 }
3804
fionaxu43304da2017-11-27 22:51:16 -08003805 @Override
3806 public int getSubscriptionCarrierId(int subId) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07003807 if (!mApp.getResources().getBoolean(
3808 com.android.internal.R.bool.config_force_phone_globals_creation)) {
3809 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3810 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId");
3811 }
joonhunshin4ac60942023-11-15 15:23:39 +00003812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 final Phone phone = getPhone(subId);
3816 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3817 } finally {
3818 Binder.restoreCallingIdentity(identity);
3819 }
fionaxu43304da2017-11-27 22:51:16 -08003820 }
3821
3822 @Override
3823 public String getSubscriptionCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003824 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3825 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName");
3826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 final Phone phone = getPhone(subId);
3830 return phone == null ? null : phone.getCarrierName();
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
3833 }
fionaxu43304da2017-11-27 22:51:16 -08003834 }
3835
calvinpanffe225e2018-11-01 19:43:06 +08003836 @Override
chen xu0026ca62019-03-06 15:28:50 -08003837 public int getSubscriptionSpecificCarrierId(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003838 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3839 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId");
3840
chen xu25637222018-11-04 17:17:00 -08003841 final long identity = Binder.clearCallingIdentity();
3842 try {
3843 final Phone phone = getPhone(subId);
3844 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003845 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003846 } finally {
3847 Binder.restoreCallingIdentity(identity);
3848 }
3849 }
3850
3851 @Override
chen xu0026ca62019-03-06 15:28:50 -08003852 public String getSubscriptionSpecificCarrierName(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00003853 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3854 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
3855 "getSubscriptionSpecificCarrierName");
3856
chen xu25637222018-11-04 17:17:00 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003860 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003861 } finally {
3862 Binder.restoreCallingIdentity(identity);
3863 }
3864 }
3865
chen xu651eec72018-11-11 19:03:44 -08003866 @Override
chen xu864e11c2018-12-06 22:10:03 -08003867 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3868 if (!isSubscriptionMccMnc) {
3869 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3870 }
chen xu651eec72018-11-11 19:03:44 -08003871 final Phone phone = PhoneFactory.getPhone(slotIndex);
3872 if (phone == null) {
3873 return TelephonyManager.UNKNOWN_CARRIER_ID;
3874 }
joonhunshin4ac60942023-11-15 15:23:39 +00003875
3876 enforceTelephonyFeatureWithException(getCurrentPackageName(),
3877 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc");
3878
chen xu651eec72018-11-11 19:03:44 -08003879 final long identity = Binder.clearCallingIdentity();
3880 try {
3881 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
3884 }
3885 }
3886
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003887 //
3888 // Internal helper methods.
3889 //
3890
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003891 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003892 * Make sure the caller is the calling package itself
3893 *
3894 * @throws SecurityException if the caller is not the calling package
3895 */
3896 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3897 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003898 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3899 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003900 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003901 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003902 } catch (PackageManager.NameNotFoundException e) {
3903 // packageUid is -1
3904 }
3905 if (packageUid != callingUid) {
3906 throw new SecurityException(message + ": Package " + callingPackage
3907 + " does not belong to " + callingUid);
3908 }
3909 }
3910
3911 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003912 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3913 *
3914 * @throws SecurityException if the caller does not have the required permission
3915 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003916 @VisibleForTesting
3917 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003918 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3919 }
3920
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003921 /**
arunvoddud7401012022-12-15 16:08:12 +00003922 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003923 *
3924 * @throws SecurityException if the caller does not have the required permission
3925 */
3926 @VisibleForTesting
3927 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003928 enforceReadPermission(null);
3929 }
3930
3931 /**
3932 * Make sure the caller has the READ_PHONE_STATE permissions.
3933 *
3934 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3935 */
3936 @VisibleForTesting
3937 public void enforceReadPermission(String msg) {
3938 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003939 }
3940
Shuo Qian3b6ee772019-11-13 17:43:31 -08003941 private void enforceActiveEmergencySessionPermission() {
3942 mApp.enforceCallingOrSelfPermission(
3943 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3944 }
3945
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003946 /**
3947 * Make sure the caller has the CALL_PHONE permission.
3948 *
3949 * @throws SecurityException if the caller does not have the required permission
3950 */
3951 private void enforceCallPermission() {
3952 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3953 }
3954
paulhu5a773602019-08-23 19:17:33 +08003955 private void enforceSettingsPermission() {
3956 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003957 }
3958
Michele Berionne5e411512020-11-13 02:36:59 +00003959 private void enforceRebootPermission() {
3960 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3961 }
3962
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003963 /**
3964 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3965 * @param message - log message to print.
3966 * @throws SecurityException if the caller does not have the required permission
3967 */
3968 private void enforceSatelliteCommunicationPermission(String message) {
3969 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3970 }
3971
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +00003972 /**
3973 * Make sure the caller has PACKAGE_USAGE_STATS permission.
3974 * @param message - log message to print.
3975 * @throws SecurityException if the caller does not have the required permission
3976 */
3977 private void enforcePackageUsageStatsPermission(String message) {
3978 mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message);
3979 }
3980
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003981 private String createTelUrl(String number) {
3982 if (TextUtils.isEmpty(number)) {
3983 return null;
3984 }
3985
Jake Hambye994d462014-02-03 13:10:13 -08003986 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003987 }
3988
Ihab Awadf9e92732013-12-05 18:02:52 -08003989 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003990 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003991 }
3992
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003993 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003994 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003995 }
3996
Ihab Awadf9e92732013-12-05 18:02:52 -08003997 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003998 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003999 }
4000
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004001 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004002 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004003 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004004 }
4005
Sanket Padawe356d7632015-06-22 14:03:32 -07004006 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004007 public int getActivePhoneTypeForSlot(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07004008 if (!mApp.getResources().getBoolean(
4009 com.android.internal.R.bool.config_force_phone_globals_creation)) {
4010 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4011 PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot");
4012 }
joonhunshin4ac60942023-11-15 15:23:39 +00004013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 final Phone phone = PhoneFactory.getPhone(slotIndex);
4017 if (phone == null) {
4018 return PhoneConstants.PHONE_TYPE_NONE;
4019 } else {
4020 return phone.getPhoneType();
4021 }
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004025 }
4026
4027 /**
4028 * Returns the CDMA ERI icon index to display
4029 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004031 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4032 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4033 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004034 }
4035
Sanket Padawe356d7632015-06-22 14:03:32 -07004036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004037 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4038 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004040 mApp, subId, callingPackage, callingFeatureId,
4041 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004042 return -1;
4043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044
joonhunshin4ac60942023-11-15 15:23:39 +00004045 enforceTelephonyFeatureWithException(callingPackage,
4046 PackageManager.FEATURE_TELEPHONY_CDMA,
4047 "getCdmaEriIconIndexForSubscriber");
4048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 final Phone phone = getPhone(subId);
4052 if (phone != null) {
4053 return phone.getCdmaEriIconIndex();
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 icon mode,
4064 * 0 - ON
4065 * 1 - FLASHING
4066 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004067 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004068 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4069 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4070 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004071 }
4072
Sanket Padawe356d7632015-06-22 14:03:32 -07004073 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004074 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4075 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004077 mApp, subId, callingPackage, callingFeatureId,
4078 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004079 return -1;
4080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081
4082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 final Phone phone = getPhone(subId);
4085 if (phone != null) {
4086 return phone.getCdmaEriIconMode();
4087 } else {
4088 return -1;
4089 }
4090 } finally {
4091 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004093 }
4094
4095 /**
4096 * Returns the CDMA ERI text,
4097 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004098 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004099 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4100 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4101 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004102 }
4103
Sanket Padawe356d7632015-06-22 14:03:32 -07004104 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004105 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4106 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004108 mApp, subId, callingPackage, callingFeatureId,
4109 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004110 return null;
4111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112
4113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 final Phone phone = getPhone(subId);
4116 if (phone != null) {
4117 return phone.getCdmaEriText();
4118 } else {
4119 return null;
4120 }
4121 } finally {
4122 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004124 }
4125
4126 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004127 * Returns the CDMA MDN.
4128 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004129 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004130 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4132 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004133
joonhunshin4ac60942023-11-15 15:23:39 +00004134 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4135 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn");
4136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004140 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 return phone.getLine1Number();
4142 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004143 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144 return null;
4145 }
4146 } finally {
4147 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004148 }
4149 }
4150
4151 /**
4152 * Returns the CDMA MIN.
4153 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004154 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004155 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4157 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004158
joonhunshin4ac60942023-11-15 15:23:39 +00004159 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4160 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin");
4161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 final Phone phone = getPhone(subId);
4165 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4166 return phone.getCdmaMin();
4167 } else {
4168 return null;
4169 }
4170 } finally {
4171 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004172 }
4173 }
4174
Hall Liud892bec2018-11-30 14:51:45 -08004175 @Override
4176 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4177 INumberVerificationCallback callback, String callingPackage) {
4178 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4179 != PERMISSION_GRANTED) {
4180 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4181 }
4182 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4183
4184 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4185 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004186 throw new SecurityException("Calling package must be configured in the device config: "
4187 + "calling package: " + callingPackage
4188 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004189 }
4190
joonhunshin4ac60942023-11-15 15:23:39 +00004191 enforceTelephonyFeatureWithException(callingPackage,
4192 PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification");
4193
Hall Liud892bec2018-11-30 14:51:45 -08004194 if (range == null) {
4195 throw new NullPointerException("Range must be non-null");
4196 }
4197
4198 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004199 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004200
4201 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4202 }
4203
Junda Liuca05d5d2014-08-14 22:36:34 -07004204 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004205 * Returns true if CDMA provisioning needs to run.
4206 */
4207 public boolean needsOtaServiceProvisioning() {
joonhunshin4ac60942023-11-15 15:23:39 +00004208 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4209 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning");
4210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 final long identity = Binder.clearCallingIdentity();
4212 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004213 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004217 }
4218
4219 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004220 * Sets the voice mail number of a given subId.
4221 */
4222 @Override
4223 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004224 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4225 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226
joonhunshin4ac60942023-11-15 15:23:39 +00004227 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4228 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber");
4229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230 final long identity = Binder.clearCallingIdentity();
4231 try {
4232 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4233 new Pair<String, String>(alphaTag, number), new Integer(subId));
4234 return success;
4235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004238 }
4239
Ta-wei Yen87c49842016-05-13 21:19:52 -07004240 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004241 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4242 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004243 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4244 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004245 if (!TextUtils.equals(callingPackage, systemDialer)) {
4246 throw new SecurityException("caller must be system dialer");
4247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248
joonhunshin4ac60942023-11-15 15:23:39 +00004249 enforceTelephonyFeatureWithException(callingPackage,
4250 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings");
4251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 final long identity = Binder.clearCallingIdentity();
4253 try {
4254 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4255 if (phoneAccountHandle == null) {
4256 return null;
4257 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004258 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004261 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004262 }
4263
4264 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004265 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4266 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004267 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004268 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 mApp, subId, callingPackage, callingFeatureId,
4270 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004271 return null;
4272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273
joonhunshin4ac60942023-11-15 15:23:39 +00004274 enforceTelephonyFeatureWithException(callingPackage,
4275 PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName");
4276
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004277 final long identity = Binder.clearCallingIdentity();
4278 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004279 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004283 }
4284
4285 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004286 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4287 VisualVoicemailSmsFilterSettings settings) {
4288 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart1c55f992024-06-06 22:34:33 +00004289 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004290 enforceTelephonyFeatureWithException(callingPackage,
4291 PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292 final long identity = Binder.clearCallingIdentity();
4293 try {
4294 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004295 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004299 }
4300
4301 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004302 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4303 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Thomas Stuart9aee7c72024-06-28 17:33:03 +00004304 enforceVisualVoicemailPackage(callingPackage, subId);
joonhunshin4ac60942023-11-15 15:23:39 +00004305 enforceTelephonyFeatureWithException(callingPackage,
4306 PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter");
4307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004311 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312 } finally {
4313 Binder.restoreCallingIdentity(identity);
4314 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004315 }
4316
4317 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004318 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4319 String callingPackage, int subId) {
4320 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321
4322 final long identity = Binder.clearCallingIdentity();
4323 try {
4324 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004325 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004329 }
4330
4331 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004332 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004333 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334
4335 final long identity = Binder.clearCallingIdentity();
4336 try {
4337 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004338 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004342 }
4343
4344 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004345 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4346 String callingAttributionTag, int subId, String number, int port, String text,
4347 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004348 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004349 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004350 enforceSendSmsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00004351
4352 enforceTelephonyFeatureWithException(callingPackage,
4353 PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber");
4354
Amit Mahajandccb3f12019-05-13 13:48:32 -07004355 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004356 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4357 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004358 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004359
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004360 /**
fionaxu0152e512016-11-14 13:36:14 -08004361 * Sets the voice activation state of a given subId.
4362 */
4363 @Override
4364 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4366 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367
joonhunshin4ac60942023-11-15 15:23:39 +00004368 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4369 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState");
4370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371 final long identity = Binder.clearCallingIdentity();
4372 try {
4373 final Phone phone = getPhone(subId);
4374 if (phone != null) {
4375 phone.setVoiceActivationState(activationState);
4376 } else {
4377 loge("setVoiceActivationState fails with invalid subId: " + subId);
4378 }
4379 } finally {
4380 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004381 }
4382 }
4383
4384 /**
4385 * Sets the data activation state of a given subId.
4386 */
4387 @Override
4388 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4390 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004391
joonhunshin4ac60942023-11-15 15:23:39 +00004392 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4393 PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState");
4394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395 final long identity = Binder.clearCallingIdentity();
4396 try {
4397 final Phone phone = getPhone(subId);
4398 if (phone != null) {
4399 phone.setDataActivationState(activationState);
4400 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004401 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 }
4403 } finally {
4404 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004405 }
4406 }
4407
4408 /**
4409 * Returns the voice activation state of a given subId.
4410 */
4411 @Override
4412 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004413 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414
joonhunshin4ac60942023-11-15 15:23:39 +00004415 enforceTelephonyFeatureWithException(callingPackage,
4416 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState");
4417
fionaxu0152e512016-11-14 13:36:14 -08004418 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 final long identity = Binder.clearCallingIdentity();
4420 try {
4421 if (phone != null) {
4422 return phone.getVoiceActivationState();
4423 } else {
4424 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4425 }
4426 } finally {
4427 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004428 }
4429 }
4430
4431 /**
4432 * Returns the data activation state of a given subId.
4433 */
4434 @Override
4435 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004436 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437
joonhunshin4ac60942023-11-15 15:23:39 +00004438 enforceTelephonyFeatureWithException(callingPackage,
4439 PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState");
4440
fionaxu0152e512016-11-14 13:36:14 -08004441 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 final long identity = Binder.clearCallingIdentity();
4443 try {
4444 if (phone != null) {
4445 return phone.getDataActivationState();
4446 } else {
4447 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4448 }
4449 } finally {
4450 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004451 }
4452 }
4453
4454 /**
Wink Saville36469e72014-06-11 15:17:00 -07004455 * Returns the unread count of voicemails for a subId
4456 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004458 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4459 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004461 mApp, subId, callingPackage, callingFeatureId,
4462 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004463 return 0;
4464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004465 final long identity = Binder.clearCallingIdentity();
4466 try {
4467 final Phone phone = getPhone(subId);
4468 if (phone != null) {
4469 return phone.getVoiceMessageCount();
4470 } else {
4471 return 0;
4472 }
4473 } finally {
4474 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004476 }
4477
4478 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004479 * returns true, if the device is in a state where both voice and data
4480 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004481 */
4482 @Override
4483 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00004484 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4485 PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed");
4486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 final long identity = Binder.clearCallingIdentity();
4488 try {
Ling Mac28f0212023-03-24 16:07:15 -07004489 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004493 }
4494
4495 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004496 * Send the dialer code if called from the current default dialer or the caller has
4497 * carrier privilege.
4498 * @param inputCode The dialer code to send
4499 */
4500 @Override
4501 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004502 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004503 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004504 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4505 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004506 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004507 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004508 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004509 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004510
joonhunshin4ac60942023-11-15 15:23:39 +00004511 enforceTelephonyFeatureWithException(callingPackage,
4512 PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode");
4513
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 final long identity = Binder.clearCallingIdentity();
4515 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004516 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
fionaxu235cc5e2017-03-06 22:25:57 -08004520 }
4521
Pengquan Menga1bb6272018-09-06 09:59:22 -07004522 @Override
4523 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004524 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004525 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4526 mApp, subId, "getNetworkSelectionMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004527
4528 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4529 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode");
4530
shilufc958392020-01-20 11:36:01 -08004531 final long identity = Binder.clearCallingIdentity();
4532 try {
4533 if (!isActiveSubscription(subId)) {
4534 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4535 }
4536 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4537 } finally {
4538 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004540 }
4541
Brad Ebinger35c841c2018-10-01 10:40:55 -07004542 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004543 public boolean isInEmergencySmsMode() {
4544 enforceReadPrivilegedPermission("isInEmergencySmsMode");
joonhunshin4ac60942023-11-15 15:23:39 +00004545
4546 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4547 PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode");
4548
Brad Ebingerb2b65522019-03-15 13:48:47 -07004549 final long identity = Binder.clearCallingIdentity();
4550 try {
4551 for (Phone phone : PhoneFactory.getPhones()) {
4552 if (phone.isInEmergencySmsMode()) {
4553 return true;
4554 }
4555 }
4556 } finally {
4557 Binder.restoreCallingIdentity(identity);
4558 }
4559 return false;
4560 }
4561
shilu366312e2019-12-17 09:28:10 -08004562 /**
4563 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4564 * @param subId The subscription to use to check the configuration.
4565 * @param c The callback that will be used to send the result.
4566 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004567 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004568 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4569 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004570 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004571 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004572
4573 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4574 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4575 "IMS not available on device.");
4576 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004577 final long token = Binder.clearCallingIdentity();
4578 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004579 int slotId = getSlotIndexOrException(subId);
4580 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004581
4582 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4583 if (controller != null) {
4584 ImsManager imsManager = controller.getImsManager(subId);
4585 if (imsManager != null) {
4586 imsManager.addRegistrationCallbackForSubscription(c, subId);
4587 } else {
4588 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4589 }
4590 } else {
4591 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4592 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004593 } catch (ImsException e) {
4594 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004595 } finally {
4596 Binder.restoreCallingIdentity(token);
4597 }
4598 }
4599
shilu366312e2019-12-17 09:28:10 -08004600 /**
4601 * 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 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004605 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004606 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004607 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004608 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004609 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4610 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4611 }
Meng Wangafbc5852019-09-19 17:37:13 -07004612 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004613
Meng Wangafbc5852019-09-19 17:37:13 -07004614 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004615 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4616 if (controller != null) {
4617 ImsManager imsManager = controller.getImsManager(subId);
4618 if (imsManager != null) {
4619 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4620 } else {
4621 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4622 + "is inactive, ignoring unregister.");
4623 // If the ImsManager is not valid, just return, since the callback
4624 // will already have been removed internally.
4625 }
4626 }
Meng Wangafbc5852019-09-19 17:37:13 -07004627 } finally {
4628 Binder.restoreCallingIdentity(token);
4629 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 }
4631
Brad Ebingera34a6c22019-10-22 17:36:18 -07004632 /**
Hidayat Khan99ea48f2023-12-11 04:37:45 +00004633 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4634 * @param subId The subscription to use to check the configuration.
4635 * @param c The callback that will be used to send the result.
4636 */
4637 @Override
4638 public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c)
4639 throws RemoteException {
4640 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4641 mApp, subId, "registerImsEmergencyRegistrationCallback");
4642
4643 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4644 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4645 "IMS not available on device.");
4646 }
4647 final long token = Binder.clearCallingIdentity();
4648 try {
4649 int slotId = getSlotIndexOrException(subId);
4650 verifyImsMmTelConfiguredOrThrow(slotId);
4651
4652 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4653 if (controller != null) {
4654 ImsManager imsManager = controller.getImsManager(subId);
4655 if (imsManager != null) {
4656 imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId);
4657 } else {
4658 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4659 }
4660 } else {
4661 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4662 }
4663 } catch (ImsException e) {
4664 throw new ServiceSpecificException(e.getCode());
4665 } finally {
4666 Binder.restoreCallingIdentity(token);
4667 }
4668 }
4669
4670 /**
4671 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4672 * @param subId The subscription to use to check the configuration.
4673 * @param c The callback that will be used to send the result.
4674 */
4675 @Override
4676 public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) {
4677 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4678 mApp, subId, "unregisterImsEmergencyRegistrationCallback");
4679 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4680 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4681 }
4682 final long token = Binder.clearCallingIdentity();
4683
4684 try {
4685 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4686 if (controller != null) {
4687 ImsManager imsManager = controller.getImsManager(subId);
4688 if (imsManager != null) {
4689 imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId);
4690 } else {
4691 Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId
4692 + "is inactive, ignoring unregister.");
4693 // If the ImsManager is not valid, just return, since the callback
4694 // will already have been removed internally.
4695 }
4696 }
4697 } finally {
4698 Binder.restoreCallingIdentity(token);
4699 }
4700 }
4701
4702 /**
Brad Ebingera34a6c22019-10-22 17:36:18 -07004703 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4704 */
4705 @Override
4706 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4707 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4708 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4709 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4710 "IMS not available on device.");
4711 }
4712 final long token = Binder.clearCallingIdentity();
4713 try {
4714 Phone phone = getPhone(subId);
4715 if (phone == null) {
4716 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4717 + subId + "'");
4718 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4719 }
4720 phone.getImsRegistrationState(regState -> {
4721 try {
4722 consumer.accept((regState == null)
4723 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4724 } catch (RemoteException e) {
4725 // Ignore if the remote process is no longer available to call back.
4726 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4727 }
4728 });
4729 } finally {
4730 Binder.restoreCallingIdentity(token);
4731 }
4732 }
4733
4734 /**
4735 * Get the transport type for the IMS service registration state.
4736 */
4737 @Override
4738 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004739 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004740 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004741 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4742 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4743 "IMS not available on device.");
4744 }
4745 final long token = Binder.clearCallingIdentity();
4746 try {
4747 Phone phone = getPhone(subId);
4748 if (phone == null) {
4749 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4750 + subId + "'");
4751 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4752 }
4753 phone.getImsRegistrationTech(regTech -> {
4754 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4755 int regTechConverted = (regTech == null)
4756 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4757 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4758 regTechConverted);
4759 try {
4760 consumer.accept(regTechConverted);
4761 } catch (RemoteException e) {
4762 // Ignore if the remote process is no longer available to call back.
4763 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4764 }
4765 });
4766 } finally {
4767 Binder.restoreCallingIdentity(token);
4768 }
4769 }
4770
shilu366312e2019-12-17 09:28:10 -08004771 /**
4772 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4773 * @param subId The subscription to use to check the configuration.
4774 * @param c The callback that will be used to send the result.
4775 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004776 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004777 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4778 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004779 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004780 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004781 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4782 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4783 "IMS not available on device.");
4784 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 final long token = Binder.clearCallingIdentity();
4786 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004787 int slotId = getSlotIndexOrException(subId);
4788 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004789
4790 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4791 if (controller != null) {
4792 ImsManager imsManager = controller.getImsManager(subId);
4793 if (imsManager != null) {
4794 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4795 } else {
4796 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4797 }
4798 } else {
4799 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4800 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004801 } catch (ImsException e) {
4802 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004803 } finally {
4804 Binder.restoreCallingIdentity(token);
4805 }
4806 }
4807
shilu366312e2019-12-17 09:28:10 -08004808 /**
4809 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4810 * @param subId The subscription to use to check the configuration.
4811 * @param c The callback that will be used to send the result.
4812 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004813 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004814 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004815 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004816 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004817 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4818 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4819 }
Meng Wangafbc5852019-09-19 17:37:13 -07004820
4821 final long token = Binder.clearCallingIdentity();
4822 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004823 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4824 if (controller != null) {
4825 ImsManager imsManager = controller.getImsManager(subId);
4826 if (imsManager != null) {
4827 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4828 } else {
4829 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4830 + " is inactive, ignoring unregister.");
4831 // If the ImsManager is not valid, just return, since the callback
4832 // will already have been removed internally.
4833 }
4834 }
Meng Wangafbc5852019-09-19 17:37:13 -07004835 } finally {
4836 Binder.restoreCallingIdentity(token);
4837 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004838 }
4839
4840 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004841 public boolean isCapable(int subId, int capability, int regTech) {
4842 enforceReadPrivilegedPermission("isCapable");
joonhunshin4ac60942023-11-15 15:23:39 +00004843
4844 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4845 FEATURE_TELEPHONY_IMS, "isCapable");
4846
Brad Ebinger35c841c2018-10-01 10:40:55 -07004847 final long token = Binder.clearCallingIdentity();
4848 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004849 int slotId = getSlotIndexOrException(subId);
4850 verifyImsMmTelConfiguredOrThrow(slotId);
4851 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4852 } catch (com.android.ims.ImsException e) {
4853 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4854 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004855 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004856 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4857 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004858 } finally {
4859 Binder.restoreCallingIdentity(token);
4860 }
4861 }
4862
4863 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004864 public boolean isAvailable(int subId, int capability, int regTech) {
4865 enforceReadPrivilegedPermission("isAvailable");
joonhunshin4ac60942023-11-15 15:23:39 +00004866
4867 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4868 FEATURE_TELEPHONY_IMS, "isAvailable");
4869
Brad Ebinger35c841c2018-10-01 10:40:55 -07004870 final long token = Binder.clearCallingIdentity();
4871 try {
4872 Phone phone = getPhone(subId);
4873 if (phone == null) return false;
4874 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004875 } catch (com.android.ims.ImsException e) {
4876 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4877 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004878 } finally {
4879 Binder.restoreCallingIdentity(token);
4880 }
4881 }
4882
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004883 /**
4884 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4885 * subscription.
4886 * @param subId The subscription to use to check the configuration.
4887 * @param callback The callback that will be used to send the result.
4888 * @param capability The MmTelFeature capability that will be used to send the result.
4889 * @param transportType The transport type of the MmTelFeature capability.
4890 */
4891 @Override
4892 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4893 int transportType) {
4894 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004895 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4896 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4897 "IMS not available on device.");
4898 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004899 final long token = Binder.clearCallingIdentity();
4900 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004901 int slotId = getSlotIndex(subId);
4902 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4903 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4904 + subId + "'");
4905 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4906 }
4907 verifyImsMmTelConfiguredOrThrow(slotId);
4908 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4909 transportType, aBoolean -> {
4910 try {
4911 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4912 } catch (RemoteException e) {
4913 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4914 + "running. Ignore");
4915 }
4916 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004917 } catch (ImsException e) {
4918 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004919 } finally {
4920 Binder.restoreCallingIdentity(token);
4921 }
4922 }
4923
shilu366312e2019-12-17 09:28:10 -08004924 /**
4925 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4926 * @param subId The subscription to use to check the configuration.
4927 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004928 @Override
4929 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004930 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004931 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004932
joonhunshin4ac60942023-11-15 15:23:39 +00004933 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4934 FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled");
4935
Brad Ebinger35c841c2018-10-01 10:40:55 -07004936 final long token = Binder.clearCallingIdentity();
4937 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004938 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004939 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004940 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004941 } catch (ImsException e) {
4942 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004943 } finally {
4944 Binder.restoreCallingIdentity(token);
4945 }
4946 }
4947
4948 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004949 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004951 "setAdvancedCallingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004952
4953 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4954 FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled");
4955
Brad Ebinger35c841c2018-10-01 10:40:55 -07004956 final long identity = Binder.clearCallingIdentity();
4957 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004958 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004959 // This setting doesn't require an active ImsService connection, so do not verify. The
4960 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004961 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004962 } catch (ImsException e) {
4963 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
4967 }
4968
shilu366312e2019-12-17 09:28:10 -08004969 /**
4970 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4971 * @param subId The subscription to use to check the configuration.
4972 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004973 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004974 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004975 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004976 mApp, subId, "isVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004977
4978 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4979 FEATURE_TELEPHONY_IMS, "isVtSettingEnabled");
4980
Brad Ebinger35c841c2018-10-01 10:40:55 -07004981 final long identity = Binder.clearCallingIdentity();
4982 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004983 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004984 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004985 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004986 } catch (ImsException e) {
4987 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004988 } finally {
4989 Binder.restoreCallingIdentity(identity);
4990 }
4991 }
4992
4993 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004994 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004996 "setVtSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00004997
4998 enforceTelephonyFeatureWithException(getCurrentPackageName(),
4999 FEATURE_TELEPHONY_IMS, "setVtSettingEnabled");
5000
Brad Ebinger35c841c2018-10-01 10:40:55 -07005001 final long identity = Binder.clearCallingIdentity();
5002 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005003 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005004 // This setting doesn't require an active ImsService connection, so do not verify. The
5005 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005006 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005007 } catch (ImsException e) {
5008 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
5011 }
5012 }
5013
shilu366312e2019-12-17 09:28:10 -08005014 /**
5015 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5016 * @param subId The subscription to use to check the configuration.
5017 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005018 @Override
5019 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005020 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005021 mApp, subId, "isVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005022
5023 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5024 FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled");
5025
Brad Ebinger35c841c2018-10-01 10:40:55 -07005026 final long identity = Binder.clearCallingIdentity();
5027 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005028 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005029 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005030 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005031 } catch (ImsException e) {
5032 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005033 } finally {
5034 Binder.restoreCallingIdentity(identity);
5035 }
5036 }
5037
5038 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005039 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005041 "setVoWiFiSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005042
5043 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5044 FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled");
5045
Brad Ebinger35c841c2018-10-01 10:40:55 -07005046 final long identity = Binder.clearCallingIdentity();
5047 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005048 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005049 // This setting doesn't require an active ImsService connection, so do not verify. The
5050 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005051 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005052 } catch (ImsException e) {
5053 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005054 } finally {
5055 Binder.restoreCallingIdentity(identity);
5056 }
5057 }
5058
shilu366312e2019-12-17 09:28:10 -08005059 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005060 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5061 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5062 * @param subId The subscription to use to check the configuration.
5063 */
5064 @Override
5065 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005066 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005067 mApp, subId, "isCrossSimCallingEnabledByUser");
joonhunshin4ac60942023-11-15 15:23:39 +00005068
5069 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5070 FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser");
5071
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005072 final long identity = Binder.clearCallingIdentity();
5073 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005074 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005075 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005076 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005077 } catch (ImsException e) {
5078 throw new ServiceSpecificException(e.getCode());
5079 } finally {
5080 Binder.restoreCallingIdentity(identity);
5081 }
5082 }
5083
5084 /**
5085 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5086 * Requires MODIFY_PHONE_STATE permission.
5087 * @param subId The subscription to use to check the configuration.
5088 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5089 * false otherwise
5090 */
5091 @Override
5092 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5094 "setCrossSimCallingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005095
5096 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5097 FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled");
5098
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005099 final long identity = Binder.clearCallingIdentity();
5100 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005101 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005102 // This setting doesn't require an active ImsService connection, so do not verify. The
5103 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005104 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005105 } catch (ImsException e) {
5106 throw new ServiceSpecificException(e.getCode());
5107 } finally {
5108 Binder.restoreCallingIdentity(identity);
5109 }
5110 }
5111
5112 /**
shilu366312e2019-12-17 09:28:10 -08005113 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5114 * @param subId The subscription to use to check the configuration.
5115 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005116 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005117
Brad Ebinger35c841c2018-10-01 10:40:55 -07005118 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005119 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005120 mApp, subId, "isVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005121
5122 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5123 FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled");
5124
Brad Ebinger35c841c2018-10-01 10:40:55 -07005125 final long identity = Binder.clearCallingIdentity();
5126 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005127 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005128 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005129 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005130 } catch (ImsException e) {
5131 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005132 } finally {
5133 Binder.restoreCallingIdentity(identity);
5134 }
5135 }
5136
5137 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005138 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005140 "setVoWiFiRoamingSettingEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005141
5142 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5143 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled");
5144
Brad Ebinger35c841c2018-10-01 10:40:55 -07005145 final long identity = Binder.clearCallingIdentity();
5146 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005147 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005148 // This setting doesn't require an active ImsService connection, so do not verify. The
5149 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005150 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005151 } catch (ImsException e) {
5152 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
5156 }
5157
5158 @Override
5159 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5161 "setVoWiFiNonPersistent");
joonhunshin4ac60942023-11-15 15:23:39 +00005162
5163 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5164 FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent");
5165
Brad Ebinger35c841c2018-10-01 10:40:55 -07005166 final long identity = Binder.clearCallingIdentity();
5167 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005168 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005169 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005170 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005171 } catch (ImsException e) {
5172 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
5176 }
5177
shilu366312e2019-12-17 09:28:10 -08005178 /**
5179 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5180 * @param subId The subscription to use to check the configuration.
5181 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005182 @Override
5183 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005184 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005185 mApp, subId, "getVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005186
5187 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5188 FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting");
5189
Brad Ebinger35c841c2018-10-01 10:40:55 -07005190 final long identity = Binder.clearCallingIdentity();
5191 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005192 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005193 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005194 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005195 } catch (ImsException e) {
5196 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005197 } finally {
5198 Binder.restoreCallingIdentity(identity);
5199 }
5200 }
5201
5202 @Override
5203 public void setVoWiFiModeSetting(int subId, int mode) {
5204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5205 "setVoWiFiModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005206
5207 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5208 FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting");
5209
Brad Ebinger35c841c2018-10-01 10:40:55 -07005210 final long identity = Binder.clearCallingIdentity();
5211 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005212 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005213 // This setting doesn't require an active ImsService connection, so do not verify. The
5214 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005215 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005216 } catch (ImsException e) {
5217 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
5221 }
5222
5223 @Override
5224 public int getVoWiFiRoamingModeSetting(int subId) {
5225 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005226
5227 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5228 FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting");
5229
Brad Ebinger35c841c2018-10-01 10:40:55 -07005230 final long identity = Binder.clearCallingIdentity();
5231 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005232 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005233 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005234 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005235 } catch (ImsException e) {
5236 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
5240 }
5241
5242 @Override
5243 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5245 "setVoWiFiRoamingModeSetting");
joonhunshin4ac60942023-11-15 15:23:39 +00005246
5247 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5248 FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting");
5249
Brad Ebinger35c841c2018-10-01 10:40:55 -07005250 final long identity = Binder.clearCallingIdentity();
5251 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005252 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005253 // This setting doesn't require an active ImsService connection, so do not verify. The
5254 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005255 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005256 } catch (ImsException e) {
5257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
5261 }
5262
5263 @Override
5264 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5266 "setRttCapabilityEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005267
5268 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5269 FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting");
5270
Brad Ebinger35c841c2018-10-01 10:40:55 -07005271 final long identity = Binder.clearCallingIdentity();
5272 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005273 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005274 // This setting doesn't require an active ImsService connection, so do not verify. The
5275 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005276 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005277 } catch (ImsException e) {
5278 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005279 } finally {
5280 Binder.restoreCallingIdentity(identity);
5281 }
5282 }
5283
shilu366312e2019-12-17 09:28:10 -08005284 /**
5285 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5286 * @param subId The subscription to use to check the configuration.
5287 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005288 @Override
5289 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005290 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005291 mApp, subId, "isTtyOverVolteEnabled");
joonhunshin4ac60942023-11-15 15:23:39 +00005292
5293 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5294 FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled");
5295
Brad Ebinger35c841c2018-10-01 10:40:55 -07005296 final long identity = Binder.clearCallingIdentity();
5297 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005298 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005299 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005300 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005301 } catch (ImsException e) {
5302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
5306 }
5307
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005308 @Override
5309 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5310 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005311
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005312 final long identity = Binder.clearCallingIdentity();
5313 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005314 if (!isImsAvailableOnDevice()) {
5315 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5316 "IMS not available on device.");
5317 }
5318 int slotId = getSlotIndexOrException(subId);
5319 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005320
5321 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5322 if (controller != null) {
5323 ImsManager imsManager = controller.getImsManager(subId);
5324 if (imsManager != null) {
5325 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5326 } else {
5327 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5328 }
5329 } else {
5330 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5331 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005332 } catch (ImsException e) {
5333 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005334 } finally {
5335 Binder.restoreCallingIdentity(identity);
5336 }
5337 }
5338
5339 @Override
5340 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5341 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005342
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005343 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005344 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5345 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5346 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005347 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005348 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5349 if (controller != null) {
5350 ImsManager imsManager = controller.getImsManager(subId);
5351 if (imsManager != null) {
5352 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5353 } else {
5354 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5355 + " is inactive, ignoring unregister.");
5356 // If the ImsManager is not valid, just return, since the callback will already
5357 // have been removed internally.
5358 }
5359 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
5363 }
5364
joonhunshincffb7fc2021-11-28 07:32:01 +00005365 @Override
5366 public void registerFeatureProvisioningChangedCallback(int subId,
5367 IFeatureProvisioningCallback callback) {
5368 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5369 mApp, subId, "registerFeatureProvisioningChangedCallback");
5370
5371 final long identity = Binder.clearCallingIdentity();
5372 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5373 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5374 }
5375
joonhunshin91bc1952022-04-29 08:47:15 +00005376 try {
5377 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5378 if (controller == null) {
5379 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5380 "Device does not support IMS");
5381 }
5382 controller.addFeatureProvisioningChangedCallback(subId, callback);
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
5385 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005386 }
5387
5388 @Override
5389 public void unregisterFeatureProvisioningChangedCallback(int subId,
5390 IFeatureProvisioningCallback callback) {
5391 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5392 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5393
5394 final long identity = Binder.clearCallingIdentity();
5395 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5396 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5397 }
5398
joonhunshin91bc1952022-04-29 08:47:15 +00005399 try {
5400 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5401 if (controller == null) {
5402 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5403 return;
5404 }
5405 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5406 } finally {
5407 Binder.restoreCallingIdentity(identity);
5408 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005409 }
allenwtsu99c623b2020-01-03 18:24:23 +08005410
5411 private void checkModifyPhoneStatePermission(int subId, String message) {
5412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5413 message);
5414 }
5415
allenwtsu99c623b2020-01-03 18:24:23 +08005416 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005417 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005418 boolean isProvisioned) {
5419 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5420
joonhunshin4ac60942023-11-15 15:23:39 +00005421 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5422 FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability");
5423
allenwtsu99c623b2020-01-03 18:24:23 +08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005426 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5427 if (controller == null) {
5428 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5429 return;
5430 }
5431 controller.setRcsProvisioningStatusForCapability(
5432 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005433 } finally {
5434 Binder.restoreCallingIdentity(identity);
5435 }
allenwtsu99c623b2020-01-03 18:24:23 +08005436 }
5437
5438
5439 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005440 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5441 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5442 mApp, subId, "getRcsProvisioningStatusForCapability");
5443
joonhunshin4ac60942023-11-15 15:23:39 +00005444 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5445 FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability");
5446
allenwtsu99c623b2020-01-03 18:24:23 +08005447 final long identity = Binder.clearCallingIdentity();
5448 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005449 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5450 if (controller == null) {
5451 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5452
5453 // device does not support IMS, this method will return true always.
5454 return true;
5455 }
5456 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005457 } finally {
5458 Binder.restoreCallingIdentity(identity);
5459 }
5460 }
5461
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005462 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005463 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5464 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005465 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005466
joonhunshin4ac60942023-11-15 15:23:39 +00005467 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5468 FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability");
5469
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005470 final long identity = Binder.clearCallingIdentity();
5471 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005472 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5473 if (controller == null) {
5474 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5475 return;
5476 }
5477 controller.setImsProvisioningStatusForCapability(
5478 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005479 } finally {
5480 Binder.restoreCallingIdentity(identity);
5481 }
5482 }
5483
5484 @Override
5485 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005486 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5487 mApp, subId, "getProvisioningStatusForCapability");
5488
joonhunshin4ac60942023-11-15 15:23:39 +00005489 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5490 FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability");
5491
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005492 final long identity = Binder.clearCallingIdentity();
5493 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005494 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5495 if (controller == null) {
5496 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005497
joonhunshin91bc1952022-04-29 08:47:15 +00005498 // device does not support IMS, this method will return true always.
5499 return true;
5500 }
5501 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005502 } finally {
5503 Binder.restoreCallingIdentity(identity);
5504 }
5505 }
5506
5507 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005508 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5509 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5510 mApp, subId, "isProvisioningRequiredForCapability");
5511
joonhunshin4ac60942023-11-15 15:23:39 +00005512 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5513 FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability");
5514
joonhunshincffb7fc2021-11-28 07:32:01 +00005515 final long identity = Binder.clearCallingIdentity();
5516 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005517 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5518 if (controller == null) {
5519 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5520
5521 // device does not support IMS, this method will return false
5522 return false;
5523 }
5524 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005525 } finally {
5526 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005527 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005528 }
5529
5530 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005531 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5532 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5533 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005534
joonhunshin4ac60942023-11-15 15:23:39 +00005535 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5536 FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability");
5537
joonhunshincffb7fc2021-11-28 07:32:01 +00005538 final long identity = Binder.clearCallingIdentity();
5539 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005540 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5541 if (controller == null) {
5542 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5543
5544 // device does not support IMS, this method will return false
5545 return false;
5546 }
5547 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005551 }
5552
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005553 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005554 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005555 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5556 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5557 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005558 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5559 mApp, subId, "getImsProvisioningInt");
5560
joonhunshin4ac60942023-11-15 15:23:39 +00005561 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5562 FEATURE_TELEPHONY_IMS, "getImsProvisioningInt");
5563
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005564 final long identity = Binder.clearCallingIdentity();
5565 try {
5566 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005567 int slotId = getSlotIndex(subId);
5568 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5569 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5570 + subId + "' for key:" + key);
5571 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5572 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005573
joonhunshin91bc1952022-04-29 08:47:15 +00005574 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5575 if (controller == null) {
5576 loge("getImsProvisioningInt: Device does not support IMS");
5577
5578 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5579 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5580 }
5581 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005582 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5583 return retVal;
5584 }
5585
calvinpanb5a34062021-02-08 19:59:36 +08005586 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005587 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005588 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5589 + subId + "' for key:" + key);
5590 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005591 } finally {
5592 Binder.restoreCallingIdentity(identity);
5593 }
5594 }
5595
5596 @Override
5597 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005598 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5599 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5600 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005601 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5602 mApp, subId, "getImsProvisioningString");
5603
joonhunshin4ac60942023-11-15 15:23:39 +00005604 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5605 FEATURE_TELEPHONY_IMS, "getImsProvisioningString");
5606
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005607 final long identity = Binder.clearCallingIdentity();
5608 try {
5609 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005610 int slotId = getSlotIndex(subId);
5611 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5612 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5613 + subId + "' for key:" + key);
5614 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5615 }
calvinpanb5a34062021-02-08 19:59:36 +08005616 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005617 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005618 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5619 + subId + "' for key:" + key);
5620 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
5624 }
5625
5626 @Override
5627 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005628 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5629 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5630 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5632 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005633
joonhunshin4ac60942023-11-15 15:23:39 +00005634 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5635 FEATURE_TELEPHONY_IMS, "setImsProvisioningInt");
5636
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005640 int slotId = getSlotIndex(subId);
5641 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5642 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5643 + subId + "' for key:" + key);
5644 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5645 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005646
joonhunshin91bc1952022-04-29 08:47:15 +00005647 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5648 if (controller == null) {
5649 loge("setImsProvisioningInt: Device does not support IMS");
5650
5651 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5652 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5653 }
5654 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005655 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5656 return retVal;
5657 }
5658
calvinpanb5a34062021-02-08 19:59:36 +08005659 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5660 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005661 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005662 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005663 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
5667 }
5668
5669 @Override
5670 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005671 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5672 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5673 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5675 "setImsProvisioningString");
joonhunshin4ac60942023-11-15 15:23:39 +00005676
5677 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5678 FEATURE_TELEPHONY_IMS, "setImsProvisioningString");
5679
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005680 final long identity = Binder.clearCallingIdentity();
5681 try {
5682 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005683 int slotId = getSlotIndex(subId);
5684 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5685 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5686 + subId + "' for key:" + key);
5687 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5688 }
calvinpanb5a34062021-02-08 19:59:36 +08005689 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5690 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005691 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005692 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005693 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005694 } finally {
5695 Binder.restoreCallingIdentity(identity);
5696 }
5697 }
5698
Brad Ebinger919631e2021-06-02 17:46:35 -07005699 /**
5700 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5701 * for the given slot ID or no ImsResolver instance has been created.
5702 * @param slotId The slot ID that the IMS service is created for.
5703 * @throws ImsException If there is no ImsService configured for this slot.
5704 */
5705 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5706 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5707 ImsFeature.FEATURE_MMTEL)) {
5708 throw new ImsException("This subscription does not support MMTEL over IMS",
5709 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5710 }
5711 }
5712
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005713 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005714 int slotId = SubscriptionManager.getSlotIndex(subId);
5715 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005716 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5717 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005718 }
5719 return slotId;
5720 }
5721
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005722 private int getSlotIndex(int subId) {
5723 int slotId = SubscriptionManager.getSlotIndex(subId);
5724 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5725 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5726 }
5727 return slotId;
5728 }
5729
Wink Saville36469e72014-06-11 15:17:00 -07005730 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005731 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005732 */
5733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005734 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5735 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005736 try {
5737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5738 } catch (SecurityException se) {
5739 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5740 throw new SecurityException("Package " + callingPackage + " does not belong to "
5741 + Binder.getCallingUid());
5742 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005743 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005744 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005745 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005746 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005747 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005748 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005749 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005750 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5751 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005752
joonhunshin4ac60942023-11-15 15:23:39 +00005753 enforceTelephonyFeatureWithException(callingPackage,
5754 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber");
5755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 final Phone phone = getPhone(subId);
5759 if (phone != null) {
5760 return phone.getServiceState().getDataNetworkType();
5761 } else {
5762 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5763 }
5764 } finally {
5765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005767 }
5768
5769 /**
5770 * Returns the data network type
5771 */
5772 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005773 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005774 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005775 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005776 }
5777
5778 /**
5779 * Returns the data network type for a subId
5780 */
5781 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005782 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5783 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005784 String functionName = "getDataNetworkTypeForSubscriber";
5785 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5786 mApp, functionName)) {
5787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5788 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5789 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5790 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005791 }
5792
joonhunshin4ac60942023-11-15 15:23:39 +00005793 enforceTelephonyFeatureWithException(callingPackage,
5794 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber");
5795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796 final long identity = Binder.clearCallingIdentity();
5797 try {
5798 final Phone phone = getPhone(subId);
5799 if (phone != null) {
5800 return phone.getServiceState().getDataNetworkType();
5801 } else {
5802 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5803 }
5804 } finally {
5805 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005807 }
5808
5809 /**
Wink Saville36469e72014-06-11 15:17:00 -07005810 * Returns the Voice network type for a subId
5811 */
5812 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005813 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5814 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005815 String functionName = "getVoiceNetworkTypeForSubscriber";
5816 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5817 mApp, functionName)) {
5818 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5819 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5820 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5821 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005822 }
5823
joonhunshin4ac60942023-11-15 15:23:39 +00005824 enforceTelephonyFeatureWithException(callingPackage,
5825 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber");
5826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 final long identity = Binder.clearCallingIdentity();
5828 try {
5829 final Phone phone = getPhone(subId);
5830 if (phone != null) {
5831 return phone.getServiceState().getVoiceNetworkType();
5832 } else {
5833 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5834 }
5835 } finally {
5836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005838 }
5839
5840 /**
5841 * @return true if a ICC card is present
5842 */
5843 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005844 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005845 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005846 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005847 }
5848
5849 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005850 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005851 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005852 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005853 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07005854 if (!mApp.getResources().getBoolean(
5855 com.android.internal.R.bool.config_force_phone_globals_creation)) {
5856 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5857 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex");
5858 }
joonhunshin4ac60942023-11-15 15:23:39 +00005859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 final long identity = Binder.clearCallingIdentity();
5861 try {
5862 final Phone phone = PhoneFactory.getPhone(slotIndex);
5863 if (phone != null) {
5864 return phone.getIccCard().hasIccCard();
5865 } else {
5866 return false;
5867 }
5868 } finally {
5869 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005871 }
5872
5873 /**
5874 * Return if the current radio is LTE on CDMA. This
5875 * is a tri-state return value as for a period of time
5876 * the mode may be unknown.
5877 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005878 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005879 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005880 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005881 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005883 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5884 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5885 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005886 }
5887
Sanket Padawe356d7632015-06-22 14:03:32 -07005888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005889 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5890 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005891 try {
5892 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5893 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005894 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5895 }
5896
joonhunshin4ac60942023-11-15 15:23:39 +00005897 enforceTelephonyFeatureWithException(callingPackage,
5898 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber");
5899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 final long identity = Binder.clearCallingIdentity();
5901 try {
5902 final Phone phone = getPhone(subId);
5903 if (phone == null) {
5904 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5905 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005906 return TelephonyProperties.lte_on_cdma_device()
5907 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 }
5909 } finally {
5910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005911 }
Wink Saville36469e72014-06-11 15:17:00 -07005912 }
5913
Wink Saville36469e72014-06-11 15:17:00 -07005914 /**
5915 * {@hide}
5916 * Returns Default subId, 0 in the case of single standby.
5917 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005918 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005919 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005920 }
5921
Shishir Agrawala9f32182016-04-12 12:00:16 -07005922 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005923 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005924 }
5925
Wink Savilleb564aae2014-10-23 10:18:09 -07005926 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005927 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005928 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005929
Pengquan Menge92a50d2018-09-21 15:54:48 -07005930 private boolean isActiveSubscription(int subId) {
Jack Yu3beaf9d2023-04-14 09:17:27 -07005931 return getSubscriptionManagerService().isActiveSubId(subId,
5932 mApp.getOpPackageName(), mApp.getFeatureId());
Pengquan Menge92a50d2018-09-21 15:54:48 -07005933 }
5934
Ihab Awadf2177b72013-11-25 13:33:23 -08005935 /**
5936 * @see android.telephony.TelephonyManager.WifiCallingChoices
5937 */
5938 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939 final long identity = Binder.clearCallingIdentity();
5940 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005941 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005942 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5943 getWhenToMakeWifiCallsDefaultPreference());
5944 } finally {
5945 Binder.restoreCallingIdentity(identity);
5946 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005947 }
5948
5949 /**
5950 * @see android.telephony.TelephonyManager.WifiCallingChoices
5951 */
5952 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 final long identity = Binder.clearCallingIdentity();
5954 try {
5955 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005956 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5958 } finally {
5959 Binder.restoreCallingIdentity(identity);
5960 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005961 }
5962
Sailesh Nepald1e68152013-12-12 19:08:02 -08005963 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005964 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005965 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005966 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005967
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005968 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5969 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5970 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005971 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005972 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005973 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005974 }
5975 return PhoneFactory.getPhone(phoneId);
5976 }
5977
Shishir Agrawal566b7612013-10-28 14:41:00 -07005978 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005979 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005980 @NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00005981
Rambo Wanga1782702021-11-10 20:15:19 -08005982 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5983 /*message=*/ "iccOpenLogicalChannel");
5984
5985 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5986 // Verify that the callingPackage in the request belongs to the calling UID
5987 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5988
joonhunshin4ac60942023-11-15 15:23:39 +00005989 enforceTelephonyFeatureWithException(getCurrentPackageName(),
5990 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel");
5991
Rambo Wanga1782702021-11-10 20:15:19 -08005992 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005993 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005994
Rambo Wanga1782702021-11-10 20:15:19 -08005995 private Phone getPhoneFromValidIccLogicalChannelRequest(
5996 @NonNull IccLogicalChannelRequest request, String message) {
5997 Phone phone;
5998 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6000 mApp, request.subId, message);
6001 phone = getPhoneFromSubId(request.subId);
6002 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6003 enforceModifyPermission();
6004 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6005 } else {
6006 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006007 }
Rambo Wanga1782702021-11-10 20:15:19 -08006008 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006009 }
6010
6011 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006012 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 final long identity = Binder.clearCallingIdentity();
6014 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006015 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006017 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6018 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006019 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6020 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 loge("The calling package is not allowed to access ISD-R.");
6022 throw new SecurityException(
6023 "The calling package is not allowed to access ISD-R.");
6024 }
Derek Tan740e1672017-06-27 14:56:27 -07006025 }
Derek Tan740e1672017-06-27 14:56:27 -07006026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006028 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6029 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 return response;
6031 } finally {
6032 Binder.restoreCallingIdentity(identity);
6033 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006034 }
6035
6036 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006037 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
joonhunshin4ac60942023-11-15 15:23:39 +00006038 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6039 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel");
6040
Rambo Wanga1782702021-11-10 20:15:19 -08006041 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6042 /*message=*/"iccCloseLogicalChannel");
6043
6044 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6045
6046 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006047 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006048
Rambo Wanga1782702021-11-10 20:15:19 -08006049 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6050 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006051 // before this feature is enabled, this API should only return false if
6052 // the operation fails instead of throwing runtime exception for
6053 // backward-compatibility.
6054 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6055 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 final long identity = Binder.clearCallingIdentity();
6057 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006058 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006059 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 }
Chen Xue9d737e2022-01-01 23:41:31 -08006061 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006062 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006063 Boolean success = false;
6064 if (result instanceof RuntimeException) {
6065 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006066 if (shouldThrowExceptionOnFailure) {
6067 throw (RuntimeException) result;
6068 } else {
6069 return false;
6070 }
Chen Xue9d737e2022-01-01 23:41:31 -08006071 } else if (result instanceof Boolean) {
6072 success = (Boolean) result;
6073 } else {
6074 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6075 }
Rambo Wanga1782702021-11-10 20:15:19 -08006076 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 return success;
6078 } finally {
6079 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006080 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006081 }
6082
6083 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006084 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006085 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6087 mApp, subId, "iccTransmitApduLogicalChannel");
joonhunshin4ac60942023-11-15 15:23:39 +00006088
6089 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6090 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel");
6091
Jordan Liu4c733742019-02-28 12:03:40 -08006092 if (DBG) {
6093 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6094 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6095 + p3 + " data=" + data);
6096 }
6097 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6098 command, p1, p2, p3, data);
6099 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006100
Jordan Liu4c733742019-02-28 12:03:40 -08006101 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006102 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006103 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006104 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006105
6106 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6107 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
6108 "iccTransmitApduLogicalChannelBySlot");
6109
Jordan Liu4c733742019-02-28 12:03:40 -08006110 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006111 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006112 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6113 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006114 }
6115 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006116 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6117 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006118 }
6119
6120 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6121 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122 final long identity = Binder.clearCallingIdentity();
6123 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006124 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125 return "";
6126 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006129 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6130 null /* workSource */);
6131 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 // Append the returned status code to the end of the response payload.
6134 String s = Integer.toHexString(
6135 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6136 if (response.payload != null) {
6137 s = IccUtils.bytesToHexString(response.payload) + s;
6138 }
6139 return s;
6140 } finally {
6141 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006142 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006143 }
Jake Hambye994d462014-02-03 13:10:13 -08006144
Evan Charltonc66da362014-05-16 14:06:40 -07006145 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006146 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6147 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6149 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006150 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006151
6152 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6153 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel");
6154
Jordan Liu4c733742019-02-28 12:03:40 -08006155 if (DBG) {
6156 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6157 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6158 }
6159 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6160 cla, command, p1, p2, p3, data);
6161 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006162
Jordan Liu4c733742019-02-28 12:03:40 -08006163 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006164 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006165 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006166 enforceModifyPermission();
6167 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +00006168
6169 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6170 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot");
6171
Jordan Liu4c733742019-02-28 12:03:40 -08006172 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006173 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006174 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6175 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006176 }
6177
6178 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006179 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6180 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006181 }
6182
6183 // open APDU basic channel assuming the caller has sufficient permissions
6184 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6185 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 final long identity = Binder.clearCallingIdentity();
6187 try {
6188 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6189 && TextUtils.equals(ISDR_AID, data)) {
6190 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006191 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6192 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 if (bestComponent == null
6194 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6195 loge("The calling package is not allowed to select ISD-R.");
6196 throw new SecurityException(
6197 "The calling package is not allowed to select ISD-R.");
6198 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006199 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006201 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006202 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6203 null /* workSource */);
6204 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006205
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006206 // Append the returned status code to the end of the response payload.
6207 String s = Integer.toHexString(
6208 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6209 if (response.payload != null) {
6210 s = IccUtils.bytesToHexString(response.payload) + s;
6211 }
6212 return s;
6213 } finally {
6214 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006215 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006216 }
6217
6218 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006219 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006220 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6222 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006223
joonhunshin4ac60942023-11-15 15:23:39 +00006224 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6225 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO");
6226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 if (DBG) {
6230 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6231 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6232 }
6233
6234 IccIoResult response =
6235 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6236 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6237 subId);
6238
6239 if (DBG) {
6240 log("Exchange SIM_IO [R]" + response);
6241 }
6242
6243 byte[] result = null;
6244 int length = 2;
6245 if (response.payload != null) {
6246 length = 2 + response.payload.length;
6247 result = new byte[length];
6248 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6249 } else {
6250 result = new byte[length];
6251 }
6252
6253 result[length - 1] = (byte) response.sw2;
6254 result[length - 2] = (byte) response.sw1;
6255 return result;
6256 } finally {
6257 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006258 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006259 }
6260
Nathan Haroldb3014052017-01-25 15:57:32 -08006261 /**
6262 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6263 * on a particular subscription
6264 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006265 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6266 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006268 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006269 return null;
6270 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006271
joonhunshin4ac60942023-11-15 15:23:39 +00006272 enforceTelephonyFeatureWithException(callingPackage,
6273 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns");
6274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 final long identity = Binder.clearCallingIdentity();
6276 try {
6277 if (appType != TelephonyManager.APPTYPE_USIM
6278 && appType != TelephonyManager.APPTYPE_SIM) {
6279 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6280 return null;
6281 }
6282 Object response = sendRequest(
6283 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6284 if (response instanceof String[]) {
6285 return (String[]) response;
6286 }
yincheng zhao2737e882019-09-06 17:06:54 -07006287 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006289 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 } finally {
6291 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006292 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006293 }
6294
yincheng zhao2737e882019-09-06 17:06:54 -07006295 /**
6296 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6297 * subscription.
6298 *
6299 * @param subId the id of the subscription.
6300 * @param appType the uicc app type, must be USIM or SIM.
6301 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6302 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006303 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006304 * @return number of fplmns that is successfully written to the SIM.
6305 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006306 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6307 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6309 mApp, subId, "setForbiddenPlmns");
6310
joonhunshin4ac60942023-11-15 15:23:39 +00006311 enforceTelephonyFeatureWithException(callingPackage,
6312 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns");
6313
yincheng zhao2737e882019-09-06 17:06:54 -07006314 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6315 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6316 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6317 }
6318 if (fplmns == null) {
6319 throw new IllegalArgumentException("Fplmn List provided is null");
6320 }
6321 for (String fplmn : fplmns) {
6322 if (!CellIdentity.isValidPlmn(fplmn)) {
6323 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6324 }
6325 }
6326 final long identity = Binder.clearCallingIdentity();
6327 try {
6328 Object response = sendRequest(
6329 CMD_SET_FORBIDDEN_PLMNS,
6330 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6331 subId);
6332 return (int) response;
6333 } finally {
6334 Binder.restoreCallingIdentity(identity);
6335 }
6336 }
6337
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006338 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006339 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6341 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006342
joonhunshin4ac60942023-11-15 15:23:39 +00006343 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6344 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus");
6345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 final long identity = Binder.clearCallingIdentity();
6347 try {
6348 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6349 if (response.payload == null) {
6350 return "";
6351 }
Evan Charltonc66da362014-05-16 14:06:40 -07006352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 // Append the returned status code to the end of the response payload.
6354 String s = Integer.toHexString(
6355 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6356 s = IccUtils.bytesToHexString(response.payload) + s;
6357 return s;
6358 } finally {
6359 Binder.restoreCallingIdentity(identity);
6360 }
Evan Charltonc66da362014-05-16 14:06:40 -07006361 }
6362
Jake Hambye994d462014-02-03 13:10:13 -08006363 /**
6364 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6365 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6366 *
6367 * @param itemID the ID of the item to read
6368 * @return the NV item as a String, or null on error.
6369 */
6370 @Override
6371 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006372 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6374 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375
6376 final long identity = Binder.clearCallingIdentity();
6377 try {
6378 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006379 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6381 return value;
6382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
Jake Hambye994d462014-02-03 13:10:13 -08006385 }
6386
6387 /**
6388 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6389 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6390 *
6391 * @param itemID the ID of the item to read
6392 * @param itemValue the value to write, as a String
6393 * @return true on success; false on any failure
6394 */
6395 @Override
6396 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006397 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6399 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400
6401 final long identity = Binder.clearCallingIdentity();
6402 try {
6403 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6404 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006405 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6407 return success;
6408 } finally {
6409 Binder.restoreCallingIdentity(identity);
6410 }
Jake Hambye994d462014-02-03 13:10:13 -08006411 }
6412
6413 /**
6414 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6415 * Used for device configuration by some CDMA operators.
6416 *
6417 * @param preferredRoamingList byte array containing the new PRL
6418 * @return true on success; false on any failure
6419 */
6420 @Override
6421 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6423 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424
6425 final long identity = Binder.clearCallingIdentity();
6426 try {
6427 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6428 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6429 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6430 return success;
6431 } finally {
6432 Binder.restoreCallingIdentity(identity);
6433 }
Jake Hambye994d462014-02-03 13:10:13 -08006434 }
6435
6436 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006437 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006438 * Used for device configuration by some CDMA operators.
6439 *
chen xu6dac5ab2018-10-26 17:39:23 -07006440 * @param slotIndex - device slot.
6441 *
Jake Hambye994d462014-02-03 13:10:13 -08006442 * @return true on success; false on any failure
6443 */
6444 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006445 public boolean resetModemConfig(int slotIndex) {
6446 Phone phone = PhoneFactory.getPhone(slotIndex);
6447 if (phone != null) {
6448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6449 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450
joonhunshin4ac60942023-11-15 15:23:39 +00006451 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6452 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig");
6453
chen xu6dac5ab2018-10-26 17:39:23 -07006454 final long identity = Binder.clearCallingIdentity();
6455 try {
6456 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6457 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6458 return success;
6459 } finally {
6460 Binder.restoreCallingIdentity(identity);
6461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462 }
chen xu6dac5ab2018-10-26 17:39:23 -07006463 return false;
6464 }
6465
6466 /**
6467 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6468 *
6469 * @param slotIndex - device slot.
6470 *
6471 * @return true on success; false on any failure
6472 */
6473 @Override
6474 public boolean rebootModem(int slotIndex) {
6475 Phone phone = PhoneFactory.getPhone(slotIndex);
6476 if (phone != null) {
6477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6478 mApp, phone.getSubId(), "rebootModem");
6479
joonhunshin4ac60942023-11-15 15:23:39 +00006480 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6481 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem");
6482
chen xu6dac5ab2018-10-26 17:39:23 -07006483 final long identity = Binder.clearCallingIdentity();
6484 try {
6485 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6486 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6487 return success;
6488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
6491 }
6492 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006493 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006494
Brad Ebinger51f743a2017-01-23 13:50:20 -08006495 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006496 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6497 * {@link #disableIms(int)}.
6498 * @param slotIndex device slot.
6499 */
6500 public void resetIms(int slotIndex) {
6501 enforceModifyPermission();
6502
joonhunshin4ac60942023-11-15 15:23:39 +00006503 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6504 PackageManager.FEATURE_TELEPHONY_IMS, "resetIms");
6505
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006506 final long identity = Binder.clearCallingIdentity();
6507 try {
6508 if (mImsResolver == null) {
6509 // may happen if the does not support IMS.
6510 return;
6511 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006512 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006513 } finally {
6514 Binder.restoreCallingIdentity(identity);
6515 }
6516 }
6517
6518 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006519 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6520 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006521 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006522 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006523 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006524
6525 final long identity = Binder.clearCallingIdentity();
6526 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006527 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006528 // may happen if the device does not support IMS.
6529 return;
6530 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006531 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006535 }
6536
6537 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006538 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6539 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006540 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006541 public void disableIms(int slotId) {
6542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006543
6544 final long identity = Binder.clearCallingIdentity();
6545 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006546 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006547 // may happen if the device does not support IMS.
6548 return;
6549 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006550 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 } finally {
6552 Binder.restoreCallingIdentity(identity);
6553 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006554 }
6555
6556 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006557 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6558 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006559 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006560 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006561 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006562 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563
6564 final long identity = Binder.clearCallingIdentity();
6565 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006566 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006567 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6568 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006569 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006570 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571 } finally {
6572 Binder.restoreCallingIdentity(identity);
6573 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006574 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006575 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006576 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6577 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006578 @Override
6579 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006580 enforceModifyPermission();
6581
6582 final long identity = Binder.clearCallingIdentity();
6583 try {
6584 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006585 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006586 } finally {
6587 Binder.restoreCallingIdentity(identity);
6588 }
6589 }
6590
6591 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006592 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006593 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006594 */
6595 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6596 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597
6598 final long identity = Binder.clearCallingIdentity();
6599 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006600 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006601 // may happen if the device does not support IMS.
6602 return null;
6603 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006604 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 } finally {
6606 Binder.restoreCallingIdentity(identity);
6607 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006608 }
6609
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006610 /**
6611 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006612 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006613 */
6614 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6615 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616
6617 final long identity = Binder.clearCallingIdentity();
6618 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006619 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006620 // may happen if the device does not support IMS.
6621 return null;
6622 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006623 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006624 } finally {
6625 Binder.restoreCallingIdentity(identity);
6626 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006627 }
6628
Brad Ebinger884c07b2018-02-15 16:17:40 -08006629 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006630 * Sets the ImsService Package Name that Telephony will bind to.
6631 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006632 * @param slotIndex the slot ID that the ImsService should bind for.
6633 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006634 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006635 * @param featureTypes An integer array of feature types associated with a packageName.
6636 * @param packageName The name of the package that the current configuration will be replaced
6637 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006638 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006639 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006640 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6641 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006644 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646 final long identity = Binder.clearCallingIdentity();
6647 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006648 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006649 // may happen if the device does not support IMS.
6650 return false;
6651 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006652 Map<Integer, String> featureConfig = new HashMap<>();
6653 for (int featureType : featureTypes) {
6654 featureConfig.put(featureType, packageName);
6655 }
6656 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6657 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 } finally {
6659 Binder.restoreCallingIdentity(identity);
6660 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006661 }
6662
6663 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006664 * Clears any carrier ImsService overrides for the slot index specified that were previously
6665 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6666 *
6667 * This should only be used for testing.
6668 *
6669 * @param slotIndex the slot ID that the ImsService should bind for.
6670 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6671 */
6672 @Override
6673 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006674 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6675 "clearCarrierImsServiceOverride");
6676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006677 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006678
6679 final long identity = Binder.clearCallingIdentity();
6680 try {
6681 if (mImsResolver == null) {
6682 // may happen if the device does not support IMS.
6683 return false;
6684 }
6685 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6686 } finally {
6687 Binder.restoreCallingIdentity(identity);
6688 }
6689 }
6690
6691 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006692 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006693 *
6694 * @param slotId The slot that the ImsService is associated with.
6695 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6696 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006697 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006698 * @return the package name of the ImsService configuration.
6699 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006700 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6701 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006702 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006703 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6704 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 final long identity = Binder.clearCallingIdentity();
6707 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006708 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006709 // may happen if the device does not support IMS.
6710 return "";
6711 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006712 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006713 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6714 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 } finally {
6716 Binder.restoreCallingIdentity(identity);
6717 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006718 }
6719
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006720 /**
6721 * Get the MmTelFeature state associated with the requested subscription id.
6722 * @param subId The subscription that the MmTelFeature is associated with.
6723 * @param callback A callback with an integer containing the
6724 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6725 */
6726 @Override
6727 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6728 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006729 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6730 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6731 "IMS not available on device.");
6732 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006733 final long token = Binder.clearCallingIdentity();
6734 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006735 int slotId = getSlotIndex(subId);
6736 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6737 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6738 + subId + "'");
6739 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6740 }
6741 verifyImsMmTelConfiguredOrThrow(slotId);
6742 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6743 try {
6744 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6745 } catch (RemoteException e) {
6746 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6747 + "Ignore");
6748 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006749 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006750 } catch (ImsException e) {
6751 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006752 } finally {
6753 Binder.restoreCallingIdentity(token);
6754 }
6755 }
6756
Daniel Brightbb5840b2021-01-12 15:48:18 -08006757 /**
6758 * Sets the ims registration state on all valid {@link Phone}s.
6759 */
6760 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762
6763 final long identity = Binder.clearCallingIdentity();
6764 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006765 // NOTE: Before S, this method only set the default phone.
6766 for (final Phone phone : PhoneFactory.getPhones()) {
6767 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6768 phone.setImsRegistrationState(registered);
6769 }
6770 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771 } finally {
6772 Binder.restoreCallingIdentity(identity);
6773 }
Wink Saville36469e72014-06-11 15:17:00 -07006774 }
6775
6776 /**
Stuart Scott54788802015-03-30 13:18:01 -07006777 * Set the network selection mode to automatic.
6778 *
6779 */
6780 @Override
6781 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6783 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784
joonhunshin4ac60942023-11-15 15:23:39 +00006785 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6786 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic");
6787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 final long identity = Binder.clearCallingIdentity();
6789 try {
shilufc958392020-01-20 11:36:01 -08006790 if (!isActiveSubscription(subId)) {
6791 return;
6792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006794 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6795 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 } finally {
6797 Binder.restoreCallingIdentity(identity);
6798 }
Stuart Scott54788802015-03-30 13:18:01 -07006799 }
6800
Jack Yud10cdd42020-09-28 20:28:01 -07006801 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006802 * Ask the radio to connect to the input network and change selection mode to manual.
6803 *
6804 * @param subId the id of the subscription.
6805 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6806 * the operator to attach to.
6807 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6808 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6809 * normal network selection next time.
6810 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006811 */
6812 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006813 public boolean setNetworkSelectionModeManual(
6814 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6816 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006817
joonhunshin4ac60942023-11-15 15:23:39 +00006818 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6819 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual");
6820
Jack Yu285100e2022-12-02 22:48:35 -08006821 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006822 if (!isActiveSubscription(subId)) {
6823 return false;
6824 }
6825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006826 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006827 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006829 if (DBG) {
6830 log("setNetworkSelectionModeManual: subId: " + subId
6831 + " operator: " + operatorInfo);
6832 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6834 } finally {
6835 Binder.restoreCallingIdentity(identity);
6836 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006837 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006838 /**
shilu84f6e8b2019-12-19 13:58:01 -08006839 * Get the manual network selection
6840 *
6841 * @param subId the id of the subscription.
6842 *
6843 * @return the previously saved user selected PLMN
6844 */
6845 @Override
6846 public String getManualNetworkSelectionPlmn(int subId) {
6847 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006848 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6849 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006850
joonhunshin4ac60942023-11-15 15:23:39 +00006851 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6852 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn");
6853
shilu84f6e8b2019-12-19 13:58:01 -08006854 final long identity = Binder.clearCallingIdentity();
6855 try {
6856 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006857 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006858 }
6859
6860 final Phone phone = getPhone(subId);
6861 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006862 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006863 }
6864 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6865 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006866 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006867 } finally {
6868 Binder.restoreCallingIdentity(identity);
6869 }
6870 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006871
6872 /**
6873 * Scans for available networks.
6874 */
6875 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006876 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6877 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6879 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006880 LocationAccessPolicy.LocationPermissionResult locationResult =
6881 LocationAccessPolicy.checkLocationPermission(mApp,
6882 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6883 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006884 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006885 .setCallingPid(Binder.getCallingPid())
6886 .setCallingUid(Binder.getCallingUid())
6887 .setMethod("getCellNetworkScanResults")
6888 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006889 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6890 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006891 .build());
6892 switch (locationResult) {
6893 case DENIED_HARD:
6894 throw new SecurityException("Not allowed to access scan results -- location");
6895 case DENIED_SOFT:
6896 return null;
6897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898
Pengquan Menga1bb6272018-09-06 09:59:22 -07006899 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006900 try {
6901 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006902 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 } finally {
6905 Binder.restoreCallingIdentity(identity);
6906 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006907 }
6908
6909 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006910 * Get the call forwarding info, given the call forwarding reason.
6911 */
6912 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006913 public void getCallForwarding(int subId, int callForwardingReason,
6914 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006915 enforceReadPrivilegedPermission("getCallForwarding");
joonhunshin4ac60942023-11-15 15:23:39 +00006916
6917 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6918 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding");
6919
Shuo Qian4a594052020-01-23 11:59:30 -08006920 long identity = Binder.clearCallingIdentity();
6921 try {
6922 if (DBG) {
6923 log("getCallForwarding: subId " + subId
6924 + " callForwardingReason" + callForwardingReason);
6925 }
Hall Liu27d24262020-09-18 19:04:59 -07006926
6927 Phone phone = getPhone(subId);
6928 if (phone == null) {
6929 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006930 callback.onError(
6931 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006932 } catch (RemoteException e) {
6933 // ignore
6934 }
6935 return;
6936 }
6937
6938 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6939 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6940 @Override
6941 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6942 try {
6943 callback.onCallForwardingInfoAvailable(info);
6944 } catch (RemoteException e) {
6945 // ignore
6946 }
6947 }
6948
6949 @Override
6950 public void onError(int error) {
6951 try {
6952 callback.onError(error);
6953 } catch (RemoteException e) {
6954 // ignore
6955 }
6956 }
6957 });
6958 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006959 } finally {
6960 Binder.restoreCallingIdentity(identity);
6961 }
6962 }
6963
6964 /**
6965 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6966 * reason, the number to forward, and the timeout before the forwarding is attempted.
6967 */
6968 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006969 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6970 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006971 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00006972
6973 enforceTelephonyFeatureWithException(getCurrentPackageName(),
6974 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding");
6975
Shuo Qian4a594052020-01-23 11:59:30 -08006976 long identity = Binder.clearCallingIdentity();
6977 try {
6978 if (DBG) {
6979 log("setCallForwarding: subId " + subId
6980 + " callForwardingInfo" + callForwardingInfo);
6981 }
Hall Liu27d24262020-09-18 19:04:59 -07006982
6983 Phone phone = getPhone(subId);
6984 if (phone == null) {
6985 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006986 callback.accept(
6987 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006988 } catch (RemoteException e) {
6989 // ignore
6990 }
6991 return;
6992 }
6993
6994 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6995 FunctionalUtils.ignoreRemoteException(callback::accept));
6996
6997 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006998 } finally {
6999 Binder.restoreCallingIdentity(identity);
7000 }
7001 }
7002
7003 /**
Hall Liu27d24262020-09-18 19:04:59 -07007004 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007005 */
7006 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007007 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007008 enforceReadPrivilegedPermission("getCallWaitingStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00007009
7010 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7011 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus");
7012
Shuo Qian4a594052020-01-23 11:59:30 -08007013 long identity = Binder.clearCallingIdentity();
7014 try {
Hall Liu27d24262020-09-18 19:04:59 -07007015 Phone phone = getPhone(subId);
7016 if (phone == null) {
7017 try {
7018 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7019 } catch (RemoteException e) {
7020 // ignore
7021 }
7022 return;
7023 }
SongFerngWang0e767992021-03-31 22:08:45 +08007024 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7025 PersistableBundle c = configManager.getConfigForSubId(subId);
7026 boolean requireUssd = c.getBoolean(
7027 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007028
Shuo Qian4a594052020-01-23 11:59:30 -08007029 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007030 if (requireUssd) {
7031 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7032 getSubscriptionCarrierId(subId));
7033 String newUssdCommand = "";
7034 try {
7035 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007036 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007037 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7038 } catch (NullPointerException e) {
7039 loge("Failed to generate USSD number" + e);
7040 }
7041 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7042 mMainThreadHandler, callback, carrierXmlParser,
7043 CarrierXmlParser.SsEntry.SSAction.QUERY);
7044 final String ussdCommand = newUssdCommand;
7045 Executors.newSingleThreadExecutor().execute(() -> {
7046 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7047 });
7048 } else {
7049 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7050 callback::accept);
7051 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7052 }
Shuo Qian4a594052020-01-23 11:59:30 -08007053 } finally {
7054 Binder.restoreCallingIdentity(identity);
7055 }
7056 }
7057
7058 /**
Hall Liu27d24262020-09-18 19:04:59 -07007059 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007060 */
7061 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007062 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007063 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007064
7065 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7066 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus");
7067
Shuo Qian4a594052020-01-23 11:59:30 -08007068 long identity = Binder.clearCallingIdentity();
7069 try {
Hall Liu27d24262020-09-18 19:04:59 -07007070 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7071
7072 Phone phone = getPhone(subId);
7073 if (phone == null) {
7074 try {
7075 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7076 } catch (RemoteException e) {
7077 // ignore
7078 }
7079 return;
7080 }
7081
SongFerngWang0e767992021-03-31 22:08:45 +08007082 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7083 PersistableBundle c = configManager.getConfigForSubId(subId);
7084 boolean requireUssd = c.getBoolean(
7085 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007086
SongFerngWang0e767992021-03-31 22:08:45 +08007087 if (DBG) log("getCallWaitingStatus: subId " + subId);
7088 if (requireUssd) {
7089 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7090 getSubscriptionCarrierId(subId));
7091 CarrierXmlParser.SsEntry.SSAction ssAction =
7092 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7093 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7094 String newUssdCommand = "";
7095 try {
7096 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007097 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007098 .makeCommand(ssAction, null);
7099 } catch (NullPointerException e) {
7100 loge("Failed to generate USSD number" + e);
7101 }
7102 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7103 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7104 final String ussdCommand = newUssdCommand;
7105 Executors.newSingleThreadExecutor().execute(() -> {
7106 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7107 });
7108 } else {
7109 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7110 FunctionalUtils.ignoreRemoteException(callback::accept));
7111
7112 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7113 }
Shuo Qian4a594052020-01-23 11:59:30 -08007114 } finally {
7115 Binder.restoreCallingIdentity(identity);
7116 }
7117 }
7118
7119 /**
yinxub1bed742017-04-17 11:45:04 -07007120 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007121 *
yinxub1bed742017-04-17 11:45:04 -07007122 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007123 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7124 * location related information which will be sent if the caller already possess
7125 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007126 * @param request contains the radio access networks with bands/channels to scan
7127 * @param messenger callback messenger for scan results or errors
7128 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007129 * @return the id of the requested scan which can be used to stop the scan.
7130 */
7131 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007132 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7133 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007134 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7136 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007137 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007138 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7139 if (!renounceFineLocationAccess) {
7140 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007141 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7142 .setCallingPackage(callingPackage)
7143 .setCallingFeatureId(callingFeatureId)
7144 .setCallingPid(Binder.getCallingPid())
7145 .setCallingUid(Binder.getCallingUid())
7146 .setMethod("requestNetworkScan")
7147 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7148 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7149 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7150 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007151 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007152 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007153 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7154 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007155 if (e != null) {
7156 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7157 throw e;
7158 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007159 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007160 return TelephonyScanManager.INVALID_SCAN_ID;
7161 }
7162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 }
joonhunshin4ac60942023-11-15 15:23:39 +00007164
7165 enforceTelephonyFeatureWithException(callingPackage,
7166 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan");
7167
Hall Liu912dfd32019-04-25 14:02:26 -07007168 int callingUid = Binder.getCallingUid();
7169 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07007173 renounceFineLocationAccess, request, messenger, binder,
7174 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007175 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007176 } finally {
7177 Binder.restoreCallingIdentity(identity);
7178 }
yinxu504e1392017-04-12 16:03:22 -07007179 }
7180
Hall Liub2ac8ef2019-02-28 15:56:23 -08007181 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007182 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007183 boolean hasCarrierPriv;
7184 final long identity = Binder.clearCallingIdentity();
7185 try {
7186 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7187 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7188 } finally {
7189 Binder.restoreCallingIdentity(identity);
7190 }
Hall Liu558027f2019-05-15 19:14:05 -07007191 boolean hasNetworkScanPermission =
7192 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007193 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007194
7195 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7196 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7197 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007198 }
7199
7200 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7201 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007202 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7203 return new SecurityException("Specific channels must not be"
7204 + " scanned without location access.");
7205 }
7206 }
7207 }
7208
Hall Liub2ac8ef2019-02-28 15:56:23 -08007209 return null;
7210 }
7211
yinxu504e1392017-04-12 16:03:22 -07007212 /**
7213 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007214 *
7215 * @param subId id of the subscription
7216 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007217 */
7218 @Override
7219 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7221 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007222
Hall Liu912dfd32019-04-25 14:02:26 -07007223 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 final long identity = Binder.clearCallingIdentity();
7225 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007226 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 } finally {
7228 Binder.restoreCallingIdentity(identity);
7229 }
yinxu504e1392017-04-12 16:03:22 -07007230 }
7231
7232 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007233 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007234 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007235 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007236 */
7237 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007238 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007239 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007240 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007241 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007242
joonhunshin4ac60942023-11-15 15:23:39 +00007243 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7244 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask");
7245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246 final long identity = Binder.clearCallingIdentity();
7247 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007248 if (DBG) log("getAllowedNetworkTypesBitmask");
7249 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7250 int networkTypesBitmask = (result != null ? result[0] : -1);
7251 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7252 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 } finally {
7254 Binder.restoreCallingIdentity(identity);
7255 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007256 }
7257
7258 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007259 * Get the allowed network types for certain reason.
7260 *
7261 * @param subId the id of the subscription.
7262 * @param reason the reason the allowed network type change is taking place
7263 * @return the allowed network types.
7264 */
7265 @Override
7266 public long getAllowedNetworkTypesForReason(int subId,
7267 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007268 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007269 mApp, subId, "getAllowedNetworkTypesForReason");
joonhunshin4ac60942023-11-15 15:23:39 +00007270
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007271 if (!mApp.getResources().getBoolean(
7272 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7273 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7274 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
7275 "getAllowedNetworkTypesForReason");
7276 }
joonhunshin4ac60942023-11-15 15:23:39 +00007277
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007278 final long identity = Binder.clearCallingIdentity();
7279 try {
Jack Yu7247ac82023-03-02 23:52:10 -08007280 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007281 } finally {
7282 Binder.restoreCallingIdentity(identity);
7283 }
7284 }
7285
7286 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007287 * Enable/Disable E-UTRA-NR Dual Connectivity
7288 * @param subId subscription id of the sim card
7289 * @param nrDualConnectivityState expected NR dual connectivity state
7290 * This can be passed following states
7291 * <ol>
7292 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7293 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7294 * <li>Disable NR dual connectivity and force secondary cell to be released
7295 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7296 * </ol>
7297 * @return operation result.
7298 */
7299 @Override
7300 public int setNrDualConnectivityState(int subId,
7301 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7303 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007304 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007305 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7306 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7307 }
7308
Sooraj Sasindran37444802020-08-11 10:40:43 -07007309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7310 final long identity = Binder.clearCallingIdentity();
7311 try {
7312 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7313 nrDualConnectivityState, subId,
7314 workSource);
7315 if (DBG) log("enableNRDualConnectivity result: " + result);
7316 return result;
7317 } finally {
7318 Binder.restoreCallingIdentity(identity);
7319 }
7320 }
7321
7322 /**
7323 * Is E-UTRA-NR Dual Connectivity enabled
7324 * @return true if dual connectivity is enabled else false
7325 */
7326 @Override
7327 public boolean isNrDualConnectivityEnabled(int subId) {
7328 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007329 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007330 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007331 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007332 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7333 return false;
7334 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007335 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7336 final long identity = Binder.clearCallingIdentity();
7337 try {
7338 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7339 null, subId, workSource);
7340 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7341 return isEnabled;
7342 } finally {
7343 Binder.restoreCallingIdentity(identity);
7344 }
7345 }
7346
7347 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007348 * Set the allowed network types of the device and
7349 * provide the reason triggering the allowed network change.
7350 *
7351 * @param subId the id of the subscription.
7352 * @param reason the reason the allowed network type change is taking place
7353 * @param allowedNetworkTypes the allowed network types.
7354 * @return true on success; false on any failure.
7355 */
7356 @Override
7357 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007358 @TelephonyManager.AllowedNetworkTypesReason int reason,
7359 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7361 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007362 // If the caller only has carrier privileges, then they should not be able to override
7363 // any network types which were set for security reasons.
7364 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7365 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007366 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007367 throw new SecurityException(
7368 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007369 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007370 }
joonhunshin4ac60942023-11-15 15:23:39 +00007371
7372 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7373 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason");
7374
SongFerngWang3ef3e072020-12-21 16:41:52 +08007375 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007376 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007377 return false;
7378 }
7379 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7380 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007381 return false;
7382 }
7383
Jack Yu5b494332023-01-23 18:18:04 +00007384 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7385 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007386
Jack Yue37dd262022-12-16 11:53:37 -08007387 Phone phone = getPhone(subId);
7388 if (phone == null) {
7389 return false;
7390 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007391
Jack Yue37dd262022-12-16 11:53:37 -08007392 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007393 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007394 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007395 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007396
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007397 final long identity = Binder.clearCallingIdentity();
7398 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007399 Boolean success = (Boolean) sendRequest(
7400 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7401 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7402
7403 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7404 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007405 } finally {
7406 Binder.restoreCallingIdentity(identity);
7407 }
7408 }
7409
7410 /**
Miaoa84611c2019-03-15 09:21:10 +08007411 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007412 *
Miaoa84611c2019-03-15 09:21:10 +08007413 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007414 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007415 * @hide
7416 */
7417 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007418 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007419 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00007420
7421 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7422 PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber");
7423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007425 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 try {
Miaoa84611c2019-03-15 09:21:10 +08007427 if (phone != null) {
7428 return phone.hasMatchedTetherApnSetting();
7429 } else {
7430 return false;
7431 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 } finally {
7433 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007434 }
Junda Liu475951f2014-11-07 16:45:03 -08007435 }
7436
7437 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007438 * Get the user enabled state of Mobile Data.
7439 *
7440 * TODO: remove and use isUserDataEnabled.
7441 * This can't be removed now because some vendor codes
7442 * calls through ITelephony directly while they should
7443 * use TelephonyManager.
7444 *
7445 * @return true on enabled
7446 */
7447 @Override
7448 public boolean getDataEnabled(int subId) {
7449 return isUserDataEnabled(subId);
7450 }
7451
7452 /**
7453 * Get whether mobile data is enabled per user setting.
7454 *
7455 * There are other factors deciding whether mobile data is actually enabled, but they are
7456 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007457 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007458 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7459 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007460 *
7461 * @return {@code true} if data is enabled else {@code false}
7462 */
7463 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007464 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007465 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007466 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007467 try {
7468 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7469 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007470 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007471 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7472 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007473 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007475 mApp, subId, functionName);
7476
Robert Greenwalt646120a2014-05-23 11:54:03 -07007477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478
7479 final long identity = Binder.clearCallingIdentity();
7480 try {
Jack Yu285100e2022-12-02 22:48:35 -08007481 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7483 Phone phone = PhoneFactory.getPhone(phoneId);
7484 if (phone != null) {
7485 boolean retVal = phone.isUserDataEnabled();
7486 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7487 return retVal;
7488 } else {
7489 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7490 return false;
7491 }
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007494 }
7495 }
7496
7497 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007498 * Checks if the device is capable of mobile data by considering whether whether the
7499 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7500 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007501 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007502 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007503 */
7504 @Override
7505 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007506 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007507 try {
7508 try {
7509 mApp.enforceCallingOrSelfPermission(
7510 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007511 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007512 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007513 try {
7514 mApp.enforceCallingOrSelfPermission(
7515 android.Manifest.permission.READ_PHONE_STATE,
7516 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007517 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007518 mApp.enforceCallingOrSelfPermission(
7519 permission.READ_BASIC_PHONE_STATE, functionName);
7520 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007521 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007522 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007523 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007524 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525
joonhunshin4ac60942023-11-15 15:23:39 +00007526 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7527 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled");
7528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 final long identity = Binder.clearCallingIdentity();
7530 try {
Jack Yu285100e2022-12-02 22:48:35 -08007531 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007533 if (phone != null && phone.getDataSettingsManager() != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007534 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007535 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 return retVal;
7537 } else {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007538 if (DBG) {
7539 loge("isDataEnabled: no phone or no DataSettingsManager subId="
7540 + subId + " retVal=false");
7541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 return false;
7543 }
7544 } finally {
7545 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007546 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007547 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007548
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007549 /**
7550 * Check if data is enabled for a specific reason
7551 * @param subId Subscription index
7552 * @param reason the reason the data enable change is taking place
7553 * @return {@code true} if the overall data is enabled; {@code false} if not.
7554 */
7555 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007556 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007557 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007558 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007559 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007560 try {
7561 mApp.enforceCallingOrSelfPermission(
7562 android.Manifest.permission.ACCESS_NETWORK_STATE,
7563 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007564 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007565 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7566 functionName);
7567 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007568 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007569 try {
7570 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007571 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007572 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007574 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007575 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007576 }
7577
joonhunshin4ac60942023-11-15 15:23:39 +00007578 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7579 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007580
7581 final long identity = Binder.clearCallingIdentity();
7582 try {
Jack Yu285100e2022-12-02 22:48:35 -08007583 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007584 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007585 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007586 + " reason=" + reason);
7587 }
7588 Phone phone = PhoneFactory.getPhone(phoneId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007589 if (phone != null && phone.getDataSettingsManager() != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007590 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007591 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007592 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007593 return retVal;
7594 } else {
7595 if (DBG) {
Hunsuk Choibf761bf2024-06-18 08:34:32 +00007596 loge("isDataEnabledForReason: no phone or no DataSettingsManager subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007597 + subId + " retVal=false");
7598 }
7599 return false;
7600 }
7601 } finally {
7602 Binder.restoreCallingIdentity(identity);
7603 }
7604 }
7605
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007606 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007607 public int getCarrierPrivilegeStatus(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00007608 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7609 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus");
7610
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007611 // No permission needed; this only lets the caller inspect their own status.
7612 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007613 }
Junda Liu29340342014-07-10 15:23:27 -07007614
7615 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007616 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007617 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
joonhunshin4ac60942023-11-15 15:23:39 +00007618
7619 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7620 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatusForUid");
7621
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007622 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7623 }
7624
7625 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7626 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007627 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007628 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007629 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7630 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007631 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7632 if (cpt == null) {
7633 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007634 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7635 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007636 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007637 }
7638
7639 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007640 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007641 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
joonhunshin4ac60942023-11-15 15:23:39 +00007642
7643 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7644 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage");
7645
chen xuf7e9fe82019-05-09 19:31:02 -07007646 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007647 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007648 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007649 Phone phone = getPhone(subId);
7650 if (phone == null) {
7651 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7652 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7653 }
7654 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7655 if (cpt == null) {
7656 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007657 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7658 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007659 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007660 }
7661
7662 @Override
7663 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007664 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007665
7666 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7667 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7668 "checkCarrierPrivilegesForPackageAnyPhone");
7669
Rambo Wange7209ce2022-02-23 13:41:02 -08007670 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7671 }
7672
7673 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007674 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007675 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007676 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007677 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007678 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7679 Phone phone = PhoneFactory.getPhone(phoneId);
7680 if (phone == null) {
7681 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007682 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007683 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7684 if (cpt == null) {
7685 continue;
7686 }
7687 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007688 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7689 break;
7690 }
7691 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007692 return result;
Junda Liu29340342014-07-10 15:23:27 -07007693 }
Derek Tan89e89d42014-07-08 17:00:10 -07007694
7695 @Override
Junda Liue64de782015-04-16 17:19:16 -07007696 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007697 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
joonhunshin4ac60942023-11-15 15:23:39 +00007698
7699 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7700 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7701 "getCarrierPackageNamesForIntentAndPhone");
7702
Rambo Wang8a247eb2022-02-08 21:11:18 +00007703 Phone phone = PhoneFactory.getPhone(phoneId);
7704 if (phone == null) {
7705 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007706 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007707 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7708 if (cpt == null) {
7709 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007710 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007711 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007712 }
7713
Amith Yamasani6e118872016-02-19 12:53:51 -08007714 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007715 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007716 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007717 Phone phone = PhoneFactory.getPhone(phoneId);
7718 if (phone == null) {
7719 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007720 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007721 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7722 if (cpt == null) {
7723 return Collections.emptyList();
7724 }
7725 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007726 }
7727
chen xuf7e9fe82019-05-09 19:31:02 -07007728 @Override
7729 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007730 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
joonhunshin4ac60942023-11-15 15:23:39 +00007731
7732 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7733 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7734 "getPackagesWithCarrierPrivilegesForAllPhones");
7735
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007736 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007737 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007738 try {
7739 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7740 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7741 }
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007744 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007745 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007746 }
7747
Rambo Wang6812ffb2022-03-15 16:54:17 -07007748 @Override
7749 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7750 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7751
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07007752 if (!mApp.getResources().getBoolean(
7753 com.android.internal.R.bool.config_force_phone_globals_creation)) {
7754 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7755 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7756 "getCarrierServicePackageNameForLogicalSlot");
7757 }
joonhunshin4ac60942023-11-15 15:23:39 +00007758
Rambo Wang6812ffb2022-03-15 16:54:17 -07007759 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7760 if (phone == null) {
7761 return null;
7762 }
7763 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7764 if (cpt == null) {
7765 return null;
7766 }
7767 return cpt.getCarrierServicePackageName();
7768 }
7769
Wink Savilleb564aae2014-10-23 10:18:09 -07007770 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007771 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007772 UiccPort port = phone == null ? null : phone.getUiccPort();
7773 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007774 return null;
7775 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007776 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007777 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007778 return null;
7779 }
7780 return iccId;
7781 }
7782
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007783 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007784 public void setCallComposerStatus(int subId, int status) {
7785 enforceModifyPermission();
7786
joonhunshin4ac60942023-11-15 15:23:39 +00007787 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7788 PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus");
7789
Shuo Qiane4e11672020-12-15 22:15:33 -08007790 final long identity = Binder.clearCallingIdentity();
7791 try {
7792 Phone phone = getPhone(subId);
7793 if (phone != null) {
7794 Phone defaultPhone = phone.getImsPhone();
7795 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7796 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7797 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007798 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7799 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007800 }
7801 }
Shuo Qian284ae752020-12-22 19:10:14 -08007802 } catch (ImsException e) {
7803 throw new ServiceSpecificException(e.getCode());
7804 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007805 Binder.restoreCallingIdentity(identity);
7806 }
7807 }
7808
7809 @Override
7810 public int getCallComposerStatus(int subId) {
7811 enforceReadPrivilegedPermission("getCallComposerStatus");
7812
joonhunshin4ac60942023-11-15 15:23:39 +00007813 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7814 PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus");
7815
Shuo Qiane4e11672020-12-15 22:15:33 -08007816 final long identity = Binder.clearCallingIdentity();
7817 try {
7818 Phone phone = getPhone(subId);
7819 if (phone != null) {
7820 Phone defaultPhone = phone.getImsPhone();
7821 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7822 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7823 return imsPhone.getCallComposerStatus();
7824 }
7825 }
7826 } finally {
7827 Binder.restoreCallingIdentity(identity);
7828 }
7829 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7830 }
7831
7832 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007833 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7834 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007835 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007836 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007837
joonhunshin4ac60942023-11-15 15:23:39 +00007838 enforceTelephonyFeatureWithException(getCurrentPackageName(),
7839 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
7840 "setLine1NumberForDisplayForSubscriber");
7841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842 final long identity = Binder.clearCallingIdentity();
7843 try {
7844 final String iccId = getIccId(subId);
7845 final Phone phone = getPhone(subId);
7846 if (phone == null) {
7847 return false;
7848 }
7849 final String subscriberId = phone.getSubscriberId();
7850
7851 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007852 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 + subscriberId + " to " + number);
7854 }
7855
7856 if (TextUtils.isEmpty(iccId)) {
7857 return false;
7858 }
7859
7860 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7861
7862 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7863 if (alphaTag == null) {
7864 editor.remove(alphaTagPrefKey);
7865 } else {
7866 editor.putString(alphaTagPrefKey, alphaTag);
7867 }
7868
7869 // Record both the line number and IMSI for this ICCID, since we need to
7870 // track all merged IMSIs based on line number
7871 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7872 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7873 if (number == null) {
7874 editor.remove(numberPrefKey);
7875 editor.remove(subscriberPrefKey);
7876 } else {
7877 editor.putString(numberPrefKey, number);
7878 editor.putString(subscriberPrefKey, subscriberId);
7879 }
7880
7881 editor.commit();
7882 return true;
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007885 }
Derek Tan7226c842014-07-02 17:42:23 -07007886 }
7887
7888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007889 public String getLine1NumberForDisplay(int subId, String callingPackage,
7890 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007891 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007893 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007894 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007895 return null;
7896 }
Derek Tan97ebb422014-09-05 16:55:38 -07007897
joonhunshin4ac60942023-11-15 15:23:39 +00007898 enforceTelephonyFeatureWithException(callingPackage,
7899 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay");
7900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901 final long identity = Binder.clearCallingIdentity();
7902 try {
7903 String iccId = getIccId(subId);
7904 if (iccId != null) {
7905 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7906 if (DBG_MERGE) {
7907 log("getLine1NumberForDisplay returning "
7908 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7909 }
7910 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7913 return null;
7914 } finally {
7915 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007916 }
Derek Tan7226c842014-07-02 17:42:23 -07007917 }
7918
7919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007920 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7921 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007923 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007924 return null;
7925 }
Derek Tan97ebb422014-09-05 16:55:38 -07007926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007927 final long identity = Binder.clearCallingIdentity();
7928 try {
7929 String iccId = getIccId(subId);
7930 if (iccId != null) {
7931 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7932 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7933 }
7934 return null;
7935 } finally {
7936 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007937 }
Derek Tan7226c842014-07-02 17:42:23 -07007938 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007939
7940 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007941 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7942 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007943 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7944 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007946 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007947 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007948 return null;
7949 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007950
Jordan Liub49b04b2019-05-06 14:45:15 -07007951 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7952 // the process, where TelephonyManager was instantiated.
7953 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007954 final long identity = Binder.clearCallingIdentity();
7955 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007956 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 final TelephonyManager tele = TelephonyManager.from(context);
7958 final SubscriptionManager sub = SubscriptionManager.from(context);
7959
7960 // Figure out what subscribers are currently active
7961 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962
Jordan Liub49b04b2019-05-06 14:45:15 -07007963 // Only consider subs which match the current subId
7964 // This logic can be simplified. See b/131189269 for progress.
7965 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007966 activeSubscriberIds.add(tele.getSubscriberId(subId));
7967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007968
7969 // First pass, find a number override for an active subscriber
7970 String mergeNumber = null;
7971 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7972 for (String key : prefs.keySet()) {
7973 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7974 final String subscriberId = (String) prefs.get(key);
7975 if (activeSubscriberIds.contains(subscriberId)) {
7976 final String iccId = key.substring(
7977 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7978 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7979 mergeNumber = (String) prefs.get(numberKey);
7980 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007981 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007982 + " for active subscriber " + subscriberId);
7983 }
7984 if (!TextUtils.isEmpty(mergeNumber)) {
7985 break;
7986 }
7987 }
7988 }
7989 }
7990
7991 // Shortcut when no active merged subscribers
7992 if (TextUtils.isEmpty(mergeNumber)) {
7993 return null;
7994 }
7995
7996 // Second pass, find all subscribers under that line override
7997 final ArraySet<String> result = new ArraySet<>();
7998 for (String key : prefs.keySet()) {
7999 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8000 final String number = (String) prefs.get(key);
8001 if (mergeNumber.equals(number)) {
8002 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8003 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8004 final String subscriberId = (String) prefs.get(subscriberKey);
8005 if (!TextUtils.isEmpty(subscriberId)) {
8006 result.add(subscriberId);
8007 }
8008 }
8009 }
8010 }
8011
8012 final String[] resultArray = result.toArray(new String[result.size()]);
8013 Arrays.sort(resultArray);
8014 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008015 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008016 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8017 }
8018 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008019 } finally {
8020 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008021 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008022 }
8023
8024 @Override
zoey chen38003472019-12-13 17:16:31 +08008025 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8026 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008027
joonhunshin4ac60942023-11-15 15:23:39 +00008028 enforceTelephonyFeatureWithException(callingPackage,
8029 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup");
8030
Malcolm Chen6ca97372019-07-01 16:28:21 -07008031 final long identity = Binder.clearCallingIdentity();
8032 try {
8033 final TelephonyManager telephonyManager = mApp.getSystemService(
8034 TelephonyManager.class);
8035 String subscriberId = telephonyManager.getSubscriberId(subId);
8036 if (subscriberId == null) {
8037 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008038 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008039 + subId);
8040 }
8041 return null;
8042 }
8043
Jack Yu3beaf9d2023-04-14 09:17:27 -07008044 final SubscriptionInfo info = getSubscriptionManagerService()
8045 .getSubscriptionInfo(subId);
8046 ParcelUuid groupUuid = info.getGroupUuid();
Malcolm Chen6ca97372019-07-01 16:28:21 -07008047 // If it doesn't belong to any group, return just subscriberId of itself.
8048 if (groupUuid == null) {
8049 return new String[]{subscriberId};
8050 }
8051
8052 // Get all subscriberIds from the group.
8053 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu3beaf9d2023-04-14 09:17:27 -07008054 List<SubscriptionInfo> groupInfos = getSubscriptionManagerService()
8055 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8056 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07008057 for (SubscriptionInfo subInfo : groupInfos) {
8058 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8059 if (subscriberId != null) {
8060 mergedSubscriberIds.add(subscriberId);
8061 }
8062 }
8063
8064 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8065 } finally {
8066 Binder.restoreCallingIdentity(identity);
8067
8068 }
8069 }
8070
8071 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008072 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008073 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008074 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075
joonhunshin4ac60942023-11-15 15:23:39 +00008076 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8077 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride");
8078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 final Phone phone = getPhone(subId);
8082 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8083 } finally {
8084 Binder.restoreCallingIdentity(identity);
8085 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008086 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008087
8088 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008089 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008090 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8091 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008092 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8093 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008094
8095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 final Phone phone = getPhone(subId);
8098 if (phone == null) {
8099 return false;
8100 }
8101 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8102 cdmaNonRoamingList);
8103 } finally {
8104 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008105 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008106 }
8107
8108 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008109 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008110 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008111 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008112 if (phone == null) {
8113 return raf;
8114 }
8115
Shuo Qiandee53402020-05-29 14:08:15 -07008116 try {
8117 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008118 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008119 mApp, phone.getSubId(), "getRadioAccessFamily");
8120 } catch (SecurityException e) {
8121 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8122 throw e;
8123 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00008124
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -07008125 if (!mApp.getResources().getBoolean(
8126 com.android.internal.R.bool.config_force_phone_globals_creation)) {
8127 enforceTelephonyFeatureWithException(callingPackage,
8128 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily");
8129 }
joonhunshin4ac60942023-11-15 15:23:39 +00008130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008131 final long identity = Binder.clearCallingIdentity();
8132 try {
chen xub97461a2018-10-26 14:17:57 -07008133 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008134 } finally {
8135 Binder.restoreCallingIdentity(identity);
8136 }
chen xub97461a2018-10-26 14:17:57 -07008137 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008138 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008139
8140 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008141 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008142 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008143 try {
8144 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8145 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008146 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008147 }
8148 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008149 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008150 }
joonhunshin4ac60942023-11-15 15:23:39 +00008151
8152 enforceTelephonyFeatureWithException(callingPackage,
8153 PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture");
8154
Hall Liu82694d52020-12-11 18:22:04 -08008155 RoleManager rm = mApp.getSystemService(RoleManager.class);
8156 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8157 if (!dialerRoleHolders.contains(callingPackage)) {
8158 throw new SecurityException("App must be the dialer role holder to"
8159 + " upload a call composer pic");
8160 }
8161
8162 Executors.newSingleThreadExecutor().execute(() -> {
8163 ByteArrayOutputStream output = new ByteArrayOutputStream(
8164 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8165 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8166 boolean readUntilEnd = false;
8167 int totalBytesRead = 0;
8168 byte[] buffer = new byte[16 * 1024];
8169 while (true) {
8170 int numRead;
8171 try {
8172 numRead = input.read(buffer);
8173 } catch (IOException e) {
8174 try {
8175 fd.checkError();
8176 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8177 null);
8178 } catch (IOException e1) {
8179 // This means that the other side closed explicitly with an error. If this
8180 // happens, log and ignore.
8181 loge("Remote end of call composer picture pipe closed: " + e1);
8182 }
8183 break;
8184 }
8185 if (numRead == -1) {
8186 readUntilEnd = true;
8187 break;
8188 }
8189 totalBytesRead += numRead;
8190 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8191 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8192 try {
8193 input.close();
8194 } catch (IOException e) {
8195 // ignore
8196 }
8197 break;
8198 }
8199 output.write(buffer, 0, numRead);
8200 }
8201 // Generally, the remote end will close the file descriptors. The only case where we
8202 // close is above, where the picture size is too big.
8203
8204 try {
8205 fd.checkError();
8206 } catch (IOException e) {
8207 loge("Remote end for call composer closed with an error: " + e);
8208 return;
8209 }
8210
Hall Liuaa4211e2021-01-20 15:43:39 -08008211 if (!readUntilEnd) {
8212 loge("Did not finish reading entire image; aborting");
8213 return;
8214 }
Hall Liu82694d52020-12-11 18:22:04 -08008215
Hall Liuaa4211e2021-01-20 15:43:39 -08008216 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8217 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8218 new CallComposerPictureTransfer.Factory() {},
8219 imageData,
8220 (result) -> {
8221 if (result.first != null) {
8222 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8223 Bundle outputResult = new Bundle();
8224 outputResult.putParcelable(
8225 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8226 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8227 outputResult);
8228 } else {
8229 callback.send(result.second, null);
8230 }
8231 }
8232 );
Hall Liu82694d52020-12-11 18:22:04 -08008233 });
8234 }
8235
8236 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008237 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008238 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008239 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008240
joonhunshin4ac60942023-11-15 15:23:39 +00008241 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8242 PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling");
8243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 final long identity = Binder.clearCallingIdentity();
8245 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008246 ImsManager.getInstance(defaultPhone.getContext(),
8247 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008251 }
8252
8253 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008254 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008255 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008256 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8257 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008258 return false;
8259 }
Svet Ganovb320e182015-04-16 12:30:10 -07008260
joonhunshin4ac60942023-11-15 15:23:39 +00008261 enforceTelephonyFeatureWithException(callingPackage,
8262 PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled");
8263
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008264 final long identity = Binder.clearCallingIdentity();
8265 try {
8266 // Check the user preference and the system-level IMS setting. Even if the user has
8267 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8268 // In the long run, we may instead need to check if there exists a connection service
8269 // which can support video calling.
8270 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008271 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008272 return imsManager.isVtEnabledByPlatform()
8273 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8274 && imsManager.isVtEnabledByUser();
8275 } finally {
8276 Binder.restoreCallingIdentity(identity);
8277 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008278 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008279
Andrew Leea1239f22015-03-02 17:44:07 -08008280 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008281 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8282 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008284 mApp, subId, callingPackage, callingFeatureId,
8285 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008286 return false;
8287 }
8288
joonhunshin4ac60942023-11-15 15:23:39 +00008289 enforceTelephonyFeatureWithException(callingPackage,
8290 PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength");
8291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292 final long identity = Binder.clearCallingIdentity();
8293 try {
8294 CarrierConfigManager configManager =
8295 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008296 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8298 } finally {
8299 Binder.restoreCallingIdentity(identity);
8300 }
Andrew Leea1239f22015-03-02 17:44:07 -08008301 }
8302
8303 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008304 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008306 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307 return false;
8308 }
8309
joonhunshin4ac60942023-11-15 15:23:39 +00008310 enforceTelephonyFeatureWithException(callingPackage,
8311 PackageManager.FEATURE_TELEPHONY, "isWorldPhone");
8312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313 final long identity = Binder.clearCallingIdentity();
8314 try {
8315 CarrierConfigManager configManager =
8316 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008317 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008318 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8319 } finally {
8320 Binder.restoreCallingIdentity(identity);
8321 }
Andrew Leea1239f22015-03-02 17:44:07 -08008322 }
8323
Andrew Lee9431b832015-03-09 18:46:45 -07008324 @Override
8325 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008326 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008327 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008328 }
8329
8330 @Override
8331 public boolean isHearingAidCompatibilitySupported() {
joonhunshin4ac60942023-11-15 15:23:39 +00008332 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8333 PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported");
8334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335 final long identity = Binder.clearCallingIdentity();
8336 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008337 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 } finally {
8339 Binder.restoreCallingIdentity(identity);
8340 }
Andrew Lee9431b832015-03-09 18:46:45 -07008341 }
8342
Hall Liuf6668912018-10-31 17:05:23 -07008343 /**
8344 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8345 * support for the feature and device firmware support.
8346 *
8347 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8348 */
8349 @Override
8350 public boolean isRttSupported(int subscriptionId) {
joonhunshin4ac60942023-11-15 15:23:39 +00008351 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8352 PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported");
8353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008354 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008355 final Phone phone = getPhone(subscriptionId);
8356 if (phone == null) {
8357 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8358 return false;
8359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008360 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008361 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008362 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
joonhunshin4ac60942023-11-15 15:23:39 +00008363 boolean isDeviceSupported = (phone.getContext().getResources() != null)
8364 ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt)
8365 : false;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366 return isCarrierSupported && isDeviceSupported;
8367 } finally {
8368 Binder.restoreCallingIdentity(identity);
8369 }
Hall Liu98187582018-01-22 19:15:32 -08008370 }
8371
Hall Liuf6668912018-10-31 17:05:23 -07008372 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008373 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8374 * RTT setting, will return true if the device and carrier both support RTT.
8375 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008376 */
8377 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378 final long identity = Binder.clearCallingIdentity();
8379 try {
joonhunshin4ac60942023-11-15 15:23:39 +00008380 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
8381 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
8382 return false;
8383 }
8384 }
8385
Hall Liu5bab75c2019-12-11 23:58:20 +00008386 boolean isRttSupported = isRttSupported(subscriptionId);
8387 boolean isUserRttSettingOn = Settings.Secure.getInt(
8388 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8389 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8390 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8391 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392 } finally {
8393 Binder.restoreCallingIdentity(identity);
8394 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008395 }
8396
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008397 @Deprecated
8398 @Override
8399 public String getDeviceId(String callingPackage) {
8400 return getDeviceIdWithFeature(callingPackage, null);
8401 }
8402
Sanket Padawe7310cc72015-01-14 09:53:20 -08008403 /**
8404 * Returns the unique device ID of phone, for example, the IMEI for
8405 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8406 *
8407 * <p>Requires Permission:
8408 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8409 */
8410 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008411 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008412 try {
8413 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8414 } catch (SecurityException se) {
8415 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8416 throw new SecurityException("Package " + callingPackage + " does not belong to "
8417 + Binder.getCallingUid());
8418 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008419 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008420 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008421 return null;
8422 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008423 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008424 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008425 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008426 return null;
8427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008428
8429 final long identity = Binder.clearCallingIdentity();
8430 try {
8431 return phone.getDeviceId();
8432 } finally {
8433 Binder.restoreCallingIdentity(identity);
8434 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008435 }
8436
Ping Sunc67b7c22016-03-02 19:16:45 +08008437 /**
8438 * {@hide}
8439 * Returns the IMS Registration Status on a particular subid
8440 *
8441 * @param subId
8442 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008443 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008444 Phone phone = getPhone(subId);
8445 if (phone != null) {
8446 return phone.isImsRegistered();
8447 } else {
8448 return false;
8449 }
8450 }
8451
Santos Cordon7a1885b2015-02-03 11:15:19 -08008452 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008453 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008454 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008455 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008456 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008457 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8458 }
8459 final long identity = Binder.clearCallingIdentity();
8460 try {
8461 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8462 } finally {
8463 Binder.restoreCallingIdentity(identity);
8464 }
8465 }
8466
8467 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008468 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008469 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008470 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008471 mApp,
8472 subscriptionId,
8473 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8474 + subscriptionId);
joonhunshin4ac60942023-11-15 15:23:39 +00008475
8476 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8477 PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId");
8478
Tyler Gunnf70ed162019-04-03 15:28:53 -07008479 final long identity = Binder.clearCallingIdentity();
8480 try {
8481 Phone phone = getPhone(subscriptionId);
8482 if (phone == null) {
8483 return null;
8484 }
8485 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8486 } finally {
8487 Binder.restoreCallingIdentity(identity);
8488 }
8489 }
8490
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008491 /**
8492 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008493 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008494 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008495 final long identity = Binder.clearCallingIdentity();
8496 try {
8497 Phone phone = getPhone(subId);
8498 if (phone != null) {
8499 return phone.isWifiCallingEnabled();
8500 } else {
8501 return false;
8502 }
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008505 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008506 }
8507
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008508 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008509 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008510 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008511 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008512 final long identity = Binder.clearCallingIdentity();
8513 try {
8514 Phone phone = getPhone(subId);
8515 if (phone != null) {
8516 return phone.isVideoEnabled();
8517 } else {
8518 return false;
8519 }
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008522 }
8523 }
8524
8525 /**
8526 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8527 * defined in {@link ImsRegistrationImplBase}.
8528 */
8529 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008530 final long identity = Binder.clearCallingIdentity();
8531 try {
8532 Phone phone = getPhone(subId);
8533 if (phone != null) {
8534 return phone.getImsRegistrationTech();
8535 } else {
8536 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8537 }
8538 } finally {
8539 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008540 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008541 }
8542
Stuart Scott8eef64f2015-04-08 15:13:54 -07008543 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008544 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008545 enforceSettingsPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008546
8547 enforceTelephonyFeatureWithException(callingPackage,
8548 PackageManager.FEATURE_TELEPHONY, "factoryReset");
8549
Stuart Scott981d8582015-04-21 14:09:50 -07008550 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8551 return;
8552 }
Kai Shif70f46f2021-03-03 13:59:46 -08008553 Phone defaultPhone = getDefaultPhone();
8554 if (defaultPhone != null) {
8555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8556 mApp, getDefaultPhone().getSubId(), "factoryReset");
8557 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008558 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008559
Svet Ganovcc087f82015-05-12 20:35:54 -07008560 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008561 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8562 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008563 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008564 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008565 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008566 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008567 cleanUpAllowedNetworkTypes(phone, subId);
Rambo Wang71f6aa62024-02-23 20:16:22 +00008568 setDataRoamingEnabled(subId, phone == null ? false
8569 : phone.getDataSettingsManager().isDefaultDataRoamingEnabled());
Jordan Liu857e73a2021-03-05 16:24:04 -08008570 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008571 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008572 // There has been issues when Sms raw table somehow stores orphan
8573 // fragments. They lead to garbled message when new fragments come
8574 // in and combined with those stale ones. In case this happens again,
8575 // user can reset all network settings which will clean up this table.
8576 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008577 // Clean up IMS settings as well here.
8578 int slotId = getSlotIndex(subId);
8579 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8580 ImsManager.getInstance(mApp, slotId).factoryReset();
8581 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008582
Kai Shif70f46f2021-03-03 13:59:46 -08008583 if (defaultPhone == null) {
8584 return;
8585 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008586 // Erase modem config if erase modem on network setting is enabled.
8587 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8588 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8589 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008590 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008591 }
Kai Shif70f46f2021-03-03 13:59:46 -08008592
8593 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008594 } finally {
8595 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008596 }
8597 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008598
SongFerngWangfd89b102021-05-27 22:44:54 +08008599 @VisibleForTesting
8600 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8601 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8602 return;
8603 }
8604 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8605 RILConstants.PREFERRED_NETWORK_MODE);
8606 SubscriptionManager.setSubscriptionProperty(subId,
8607 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8608 "user=" + defaultNetworkType);
8609 phone.loadAllowedNetworksFromSubscriptionDatabase();
8610 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8611 defaultNetworkType, null);
8612 }
8613
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008614 private void cleanUpSmsRawTable(Context context) {
8615 ContentResolver resolver = context.getContentResolver();
8616 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8617 resolver.delete(uri, null, null);
8618 }
8619
Narayan Kamath1c496c22015-04-16 14:40:19 +01008620 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008621 public String getSimLocaleForSubscriber(int subId) {
8622 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
joonhunshin4ac60942023-11-15 15:23:39 +00008623
8624 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8625 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber");
8626
chen xu5d3637b2019-01-21 23:31:38 -08008627 final Phone phone = getPhone(subId);
8628 if (phone == null) {
8629 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008630 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008632 final long identity = Binder.clearCallingIdentity();
8633 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008634 SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
8635 phone.getContext().getOpPackageName(),
8636 phone.getContext().getAttributionTag());
8637 if (info == null) {
8638 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8639 return null;
chen xu6291c472019-02-04 12:55:53 -08008640 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008641 // Try and fetch the locale from the carrier properties or from the SIM language
8642 // preferences (EF-PL and EF-LI)...
8643 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008644 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008645 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8646 if (localeFromDefaultSim != null) {
8647 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8648 if (DBG) log("Using locale from subId: " + subId + " locale: "
8649 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008650 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008651 } else {
8652 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008653 }
8654 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008656 // The SIM language preferences only store a language (e.g. fr = French), not an
8657 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8658 // the SIM and carrier preferences does not include a country we add the country
8659 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008660 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008661 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008662 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008663 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008664 }
8665
8666 if (DBG) log("No locale found - returning null");
8667 return null;
8668 } finally {
8669 Binder.restoreCallingIdentity(identity);
8670 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008671 }
8672
tom hsu0b59d292022-09-29 23:49:21 +08008673 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008674 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008675 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008676 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008677 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008678 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8679 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008680 Locale.forLanguageTag(localeTag).getCountry())) {
8681 return localeTag;
8682 }
8683 }
8684 return inputLocale.toLanguageTag();
8685 }
8686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008687 /**
8688 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8689 */
8690 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008691 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Ling Ma9fa67412023-11-13 14:13:19 -08008692 mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/);
Narayan Kamath1c496c22015-04-16 14:40:19 +01008693 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008694
Gary Jian3aa9a762022-01-24 16:41:19 +08008695 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8696 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008697
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008698 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008699 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8700 * representing the state of the modem.
8701 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008702 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8703 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008704 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008705 */
8706 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008707 public void requestModemActivityInfo(ResultReceiver result) {
8708 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00008709
8710 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8711 PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo");
8712
vagdeviaf9a5b92018-08-15 16:01:53 -07008713 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008714
8715 final long identity = Binder.clearCallingIdentity();
8716 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008717 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008718 } finally {
8719 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008720 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008721 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008722
Gary Jian76280a42022-12-07 16:18:33 +08008723 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008724 // less than total activity duration.
8725 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8726 if (info == null) {
8727 return false;
8728 }
8729 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008730 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008731 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8732
Hall Liu49656c02020-10-09 19:00:11 -07008733 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8734
Siddharth Rayb8114062018-06-17 15:02:38 -07008735 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008736 && (info.getSleepTimeMillis() <= activityDurationMs)
8737 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008738 }
8739
Gary Jian3aa9a762022-01-24 16:41:19 +08008740 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8741 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8742 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8743 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8744
8745 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8746 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8747 }
8748
8749 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8750 mLastModemActivityInfo.setReceiveTimeMillis(
8751 rat,
8752 freq,
8753 info.getReceiveTimeMillis(rat, freq)
8754 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8755 }
8756
8757 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8758 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8759 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8760 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8761
8762 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8763 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8764 }
8765 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8766 mLastModemActivityInfo.setReceiveTimeMillis(
8767 rat,
8768 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8769 }
8770
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008771 /**
8772 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8773 * @param info recent ModemActivityInfo
8774 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008775 private void mergeModemActivityInfo(ModemActivityInfo info) {
8776 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008777 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008778 boolean matched;
8779 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8780 matched = false;
8781 int rat = info.getSpecificInfoRat(i);
8782 int freq = info.getSpecificInfoFrequencyRange(i);
8783 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8784 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8785 //if it already exists
8786 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8787 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8788 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8789 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8790 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8791 updateLastModemActivityInfo(info, rat, freq);
8792 matched = true;
8793 }
8794 } else {
8795 updateLastModemActivityInfo(info, rat);
8796 matched = true;
8797 }
8798 }
8799 }
8800
8801 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008802 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008803 new ActivityStatsTechSpecificInfo(
8804 rat,
8805 freq,
8806 info.getTransmitTimeMillis(rat, freq),
8807 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008808 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008809 }
8810 }
8811 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8812 mLastModemActivitySpecificInfo =
8813 new ActivityStatsTechSpecificInfo[merged.size()];
8814 merged.toArray(mLastModemActivitySpecificInfo);
8815
8816 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8817 mLastModemActivityInfo.setSleepTimeMillis(
8818 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008819 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008820 mLastModemActivityInfo.setIdleTimeMillis(
8821 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008822 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008823
8824 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008825 new ModemActivityInfo(
8826 mLastModemActivityInfo.getTimestampMillis(),
8827 mLastModemActivityInfo.getSleepTimeMillis(),
8828 mLastModemActivityInfo.getIdleTimeMillis(),
8829 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008830 }
8831
8832 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8833 ActivityStatsTechSpecificInfo[] info) {
8834 int infoSize = info.length;
8835 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8836 for (int i = 0; i < infoSize; i++) {
8837 ret[i] = new ActivityStatsTechSpecificInfo(
8838 info[i].getRat(), info[i].getFrequencyRange(),
8839 info[i].getTransmitTimeMillis(),
8840 (int) info[i].getReceiveTimeMillis());
8841 }
8842 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008843 }
8844
Jack Yu85bd38a2015-11-09 11:34:32 -08008845 /**
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008846 * Returns the service state information on specified SIM slot.
Jack Yu85bd38a2015-11-09 11:34:32 -08008847 */
8848 @Override
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008849 public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess,
8850 boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) {
8851 Phone phone = PhoneFactory.getPhone(slotIndex);
8852 if (phone == null) {
8853 loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex);
8854 return null;
8855 }
8856
8857 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08008858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008859 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008860 return null;
8861 }
8862
joonhunshin4ac60942023-11-15 15:23:39 +00008863 enforceTelephonyFeatureWithException(callingPackage,
8864 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber");
8865
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008866 boolean hasFinePermission = false;
8867 boolean hasCoarsePermission = false;
8868 if (!renounceFineLocationAccess) {
8869 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8870 LocationAccessPolicy.checkLocationPermission(mApp,
8871 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8872 .setCallingPackage(callingPackage)
8873 .setCallingFeatureId(callingFeatureId)
8874 .setCallingPid(Binder.getCallingPid())
8875 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008876 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008877 .setLogAsInfo(true)
8878 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8879 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8880 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8881 .build());
8882 hasFinePermission =
8883 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8884 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008885
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008886 if (!renounceCoarseLocationAccess) {
8887 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8888 LocationAccessPolicy.checkLocationPermission(mApp,
8889 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8890 .setCallingPackage(callingPackage)
8891 .setCallingFeatureId(callingFeatureId)
8892 .setCallingPid(Binder.getCallingPid())
8893 .setCallingUid(Binder.getCallingUid())
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008894 .setMethod("getServiceStateForSlot")
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008895 .setLogAsInfo(true)
8896 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8897 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8898 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8899 .build());
8900 hasCoarsePermission =
8901 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8902 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008903
Jordan Liu0f2bc442020-11-18 16:47:37 -08008904 final long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008905 try {
Jack Yu3beaf9d2023-04-14 09:17:27 -07008906 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
8907 .getSubscriptionInfoInternal(subId);
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008908 if (subInfo != null && !subInfo.isActive()) {
8909 log("getServiceStateForSlot returning null for inactive subId=" + subId);
Jack Yu3beaf9d2023-04-14 09:17:27 -07008910 return null;
Jordan Liuc437b192020-08-17 10:59:12 -07008911 }
8912
Hall Liuf19c44f2018-11-27 14:38:17 -08008913 ServiceState ss = phone.getServiceState();
Aishwarya Mallampati33a201a2024-05-09 20:39:09 +00008914 boolean isCallingPackageDataService = phone.getDataServicePackages()
8915 .contains(callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08008916
8917 // Scrub out the location info in ServiceState depending on what level of access
8918 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008919 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008920 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8921 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008922 } finally {
8923 Binder.restoreCallingIdentity(identity);
8924 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008925 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008926
8927 /**
8928 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8929 *
8930 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8931 * voicemail ringtone.
8932 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8933 * PhoneAccount.
8934 */
8935 @Override
8936 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00008937 enforceTelephonyFeatureWithException(getCurrentPackageName(),
8938 PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri");
8939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008940 final long identity = Binder.clearCallingIdentity();
8941 try {
8942 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8943 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008944 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008947 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8948 } finally {
8949 Binder.restoreCallingIdentity(identity);
8950 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008951 }
8952
8953 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008954 * Sets the per-account voicemail ringtone.
8955 *
8956 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8957 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8958 *
8959 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8960 * voicemail ringtone.
8961 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8962 * PhoneAccount.
8963 */
8964 @Override
8965 public void setVoicemailRingtoneUri(String callingPackage,
8966 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008967 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008968 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008969 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8970 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8972 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8973 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008974 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975
joonhunshin4ac60942023-11-15 15:23:39 +00008976 enforceTelephonyFeatureWithException(callingPackage,
8977 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri");
8978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 final long identity = Binder.clearCallingIdentity();
8980 try {
8981 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8982 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008983 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008984 }
8985 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8986 } finally {
8987 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008988 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008989 }
8990
8991 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008992 * Returns whether vibration is set for voicemail notification in Phone settings.
8993 *
8994 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8995 * voicemail vibration setting.
8996 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8997 */
8998 @Override
8999 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
joonhunshin4ac60942023-11-15 15:23:39 +00009000 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9001 PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled");
9002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009003 final long identity = Binder.clearCallingIdentity();
9004 try {
9005 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9006 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009007 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009008 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009010 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9011 } finally {
9012 Binder.restoreCallingIdentity(identity);
9013 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009014 }
9015
Youhan Wange64578a2016-05-02 15:32:42 -07009016 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009017 * Sets the per-account voicemail vibration.
9018 *
9019 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9020 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9021 *
9022 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9023 * voicemail vibration setting.
9024 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9025 * specific PhoneAccount.
9026 */
9027 @Override
9028 public void setVoicemailVibrationEnabled(String callingPackage,
9029 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009030 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009032 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9033 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9035 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9036 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009037 }
9038
joonhunshin4ac60942023-11-15 15:23:39 +00009039 enforceTelephonyFeatureWithException(callingPackage,
9040 PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled");
9041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009042 final long identity = Binder.clearCallingIdentity();
9043 try {
9044 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9045 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009046 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009047 }
9048 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9049 } finally {
9050 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009051 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009052 }
9053
9054 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009055 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9056 *
9057 * @throws SecurityException if the caller does not have the required permission
9058 */
arunvoddud7401012022-12-15 16:08:12 +00009059 @VisibleForTesting
9060 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009061 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009062 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009063 }
9064
9065 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009066 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9067 * permission.
9068 *
9069 * @throws SecurityException if the caller does not have the required permission
9070 */
9071 private void enforceSendSmsPermission() {
9072 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9073 }
9074
9075 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009076 * Make sure either called from same process as self (phone) or IPC caller has interact across
9077 * users permission.
9078 *
9079 * @throws SecurityException if the caller does not have the required permission
9080 */
9081 private void enforceInteractAcrossUsersPermission(String message) {
9082 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9083 }
9084
9085 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009086 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009087 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009088 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009089 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009090 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009091 final long identity = Binder.clearCallingIdentity();
9092 try {
9093 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009094 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009095 if (componentName == null) {
9096 throw new SecurityException(
9097 "Caller not current active visual voicemail package[null]");
9098 }
9099 String vvmPackage = componentName.getPackageName();
9100 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009101 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009102 }
9103 } finally {
9104 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009105 }
9106 }
9107
9108 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009109 * Return the application ID for the app type.
9110 *
9111 * @param subId the subscription ID that this request applies to.
9112 * @param appType the uicc app type.
9113 * @return Application ID for specificied app type, or null if no uicc.
9114 */
9115 @Override
9116 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009117 enforceReadPrivilegedPermission("getAidForAppType");
joonhunshin4ac60942023-11-15 15:23:39 +00009118
9119 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9120 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType");
9121
Youhan Wange64578a2016-05-02 15:32:42 -07009122 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009123
9124 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009125 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009126 if (phone == null) {
9127 return null;
9128 }
9129 String aid = null;
9130 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009131 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009132 .getApplicationByType(appType).getAid();
9133 } catch (Exception e) {
9134 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9135 }
9136 return aid;
9137 } finally {
9138 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009139 }
Youhan Wange64578a2016-05-02 15:32:42 -07009140 }
9141
Youhan Wang4001d252016-05-11 10:29:41 -07009142 /**
9143 * Return the Electronic Serial Number.
9144 *
9145 * @param subId the subscription ID that this request applies to.
9146 * @return ESN or null if error.
9147 */
9148 @Override
9149 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009150 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009151 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009152
9153 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009154 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009155 if (phone == null) {
9156 return null;
9157 }
9158 String esn = null;
9159 try {
9160 esn = phone.getEsn();
9161 } catch (Exception e) {
9162 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9163 }
9164 return esn;
9165 } finally {
9166 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009167 }
Youhan Wang4001d252016-05-11 10:29:41 -07009168 }
9169
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009170 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009171 * Return the Preferred Roaming List Version.
9172 *
9173 * @param subId the subscription ID that this request applies to.
9174 * @return PRLVersion or null if error.
9175 */
9176 @Override
9177 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009178 enforceReadPrivilegedPermission("getCdmaPrlVersion");
joonhunshin4ac60942023-11-15 15:23:39 +00009179
9180 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9181 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion");
9182
Youhan Wang66ad5d72016-07-18 17:56:58 -07009183 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009184
9185 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009186 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009187 if (phone == null) {
9188 return null;
9189 }
9190 String cdmaPrlVersion = null;
9191 try {
9192 cdmaPrlVersion = phone.getCdmaPrlVersion();
9193 } catch (Exception e) {
9194 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9195 }
9196 return cdmaPrlVersion;
9197 } finally {
9198 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009199 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009200 }
9201
9202 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009203 * Get snapshot of Telephony histograms
9204 * @return List of Telephony histograms
9205 * @hide
9206 */
9207 @Override
9208 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9210 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009211
9212 final long identity = Binder.clearCallingIdentity();
9213 try {
9214 return RIL.getTelephonyRILTimingHistograms();
9215 } finally {
9216 Binder.restoreCallingIdentity(identity);
9217 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009218 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009219
9220 /**
9221 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009222 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9223 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009224 * Require system privileges. In the future we may add this to carrier APIs.
9225 *
Michele Berionne482f8202018-11-27 18:57:59 -08009226 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009227 */
9228 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009229 @TelephonyManager.SetCarrierRestrictionResult
9230 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009231 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009232
9233 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9234 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers");
9235
vagdeviaf9a5b92018-08-15 16:01:53 -07009236 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009237
Michele Berionne482f8202018-11-27 18:57:59 -08009238 if (carrierRestrictionRules == null) {
9239 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009240 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009242 final long identity = Binder.clearCallingIdentity();
9243 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009244 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009245 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009246 } finally {
9247 Binder.restoreCallingIdentity(identity);
9248 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009249 }
9250
9251 /**
9252 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009253 * Get the allowed carrier list and the excluded carrier list, including the priority between
9254 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009255 * Require system privileges. In the future we may add this to carrier APIs.
9256 *
Michele Berionne482f8202018-11-27 18:57:59 -08009257 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009258 */
9259 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009260 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009261 enforceReadPrivilegedPermission("getAllowedCarriers");
joonhunshin4ac60942023-11-15 15:23:39 +00009262
9263 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9264 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers");
9265
vagdeviaf9a5b92018-08-15 16:01:53 -07009266 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009267
9268 final long identity = Binder.clearCallingIdentity();
9269 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009270 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9271 if (response instanceof CarrierRestrictionRules) {
9272 return (CarrierRestrictionRules) response;
9273 }
9274 // Response is an Exception of some kind,
9275 // which is signalled to the user as a NULL retval
9276 return null;
9277 } catch (Exception e) {
9278 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9279 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009280 } finally {
9281 Binder.restoreCallingIdentity(identity);
9282 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009283 }
9284
fionaxu59545b42016-05-25 15:53:37 -07009285 /**
arunvoddud7401012022-12-15 16:08:12 +00009286 * Fetches the carrier restriction status of the device and sends the status to the caller
9287 * through the callback.
9288 *
9289 * @param callback The callback that will be used to send the result.
9290 * @throws SecurityException if the caller does not have the required permission/privileges or
9291 * the caller is not allowlisted.
9292 */
9293 @Override
9294 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9295 enforceReadPermission("getCarrierRestrictionStatus");
joonhunshin4ac60942023-11-15 15:23:39 +00009296
9297 enforceTelephonyFeatureWithException(packageName,
9298 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierRestrictionStatus");
9299
Steve Statia28b7cb32024-03-11 23:58:50 +00009300 Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName);
9301 if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) {
arunvoddud7401012022-12-15 16:08:12 +00009302 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9303 throw new SecurityException("Not an authorized caller");
9304 }
9305 final long identity = Binder.clearCallingIdentity();
9306 try {
9307 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
Steve Statia28b7cb32024-03-11 23:58:50 +00009308 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds);
arunvoddud7401012022-12-15 16:08:12 +00009309 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9310 } finally {
9311 Binder.restoreCallingIdentity(identity);
9312 }
9313 }
9314
arunvoddu567f2b42023-04-25 17:22:00 +00009315 @Override
9316 public List<String> getShaIdFromAllowList(String pkgName, int carrierId) {
9317 enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange");
9318 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9319 return allowListInfo.getShaIdList(pkgName, carrierId);
9320 }
9321
arunvoddud7401012022-12-15 16:08:12 +00009322 @VisibleForTesting
Steve Statia28b7cb32024-03-11 23:58:50 +00009323 public Set<Integer> validateCallerAndGetCarrierIds(String packageName) {
arunvoddud7401012022-12-15 16:08:12 +00009324 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
Steve Statia28b7cb32024-03-11 23:58:50 +00009325 return allowListInfo.validateCallerAndGetCarrierIds(packageName);
arunvoddud7401012022-12-15 16:08:12 +00009326 }
9327
9328 /**
fionaxu59545b42016-05-25 15:53:37 -07009329 * Action set from carrier signalling broadcast receivers to enable/disable radio
9330 * @param subId the subscription ID that this action applies to.
9331 * @param enabled control enable or disable radio.
9332 * {@hide}
9333 */
9334 @Override
9335 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9336 enforceModifyPermission();
9337 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009338
9339 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009340 if (phone == null) {
9341 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9342 return;
9343 }
9344 try {
9345 phone.carrierActionSetRadioEnabled(enabled);
9346 } catch (Exception e) {
9347 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009348 } finally {
9349 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009350 }
9351 }
9352
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009353 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009354 * Enable or disable Voice over NR (VoNR)
9355 * @param subId the subscription ID that this action applies to.
9356 * @param enabled enable or disable VoNR.
9357 * @return operation result.
9358 */
9359 @Override
9360 public int setVoNrEnabled(int subId, boolean enabled) {
9361 enforceModifyPermission();
9362 final Phone phone = getPhone(subId);
9363
9364 final long identity = Binder.clearCallingIdentity();
9365 if (phone == null) {
9366 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9367 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9368 }
9369
9370 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9371 try {
9372 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9373 workSource);
9374 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009375
9376 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9377 if (DBG) {
9378 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9379 }
9380 SubscriptionManager.setSubscriptionProperty(
9381 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9382 (enabled ? "1" : "0"));
9383 }
9384
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009385 return result;
9386 } finally {
9387 Binder.restoreCallingIdentity(identity);
9388 }
9389 }
9390
9391 /**
9392 * Is voice over NR enabled
9393 * @return true if VoNR is enabled else false
9394 */
9395 @Override
9396 public boolean isVoNrEnabled(int subId) {
9397 enforceReadPrivilegedPermission("isVoNrEnabled");
9398 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9399 final long identity = Binder.clearCallingIdentity();
9400 try {
9401 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9402 null, subId, workSource);
9403 if (DBG) log("isVoNrEnabled: " + isEnabled);
9404 return isEnabled;
9405 } finally {
9406 Binder.restoreCallingIdentity(identity);
9407 }
9408 }
9409
9410 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009411 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9412 * network status based on which carrier apps could apply actions accordingly,
9413 * enable/disable default url handler for example.
9414 *
9415 * @param subId the subscription ID that this action applies to.
9416 * @param report control start/stop reporting the default network status.
9417 * {@hide}
9418 */
9419 @Override
9420 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9421 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009422
9423 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9424 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
9425 "carrierActionReportDefaultNetworkStatus");
9426
fionaxu8da9cb12017-05-23 15:02:46 -07009427 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009428
9429 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009430 if (phone == null) {
9431 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9432 return;
9433 }
9434 try {
9435 phone.carrierActionReportDefaultNetworkStatus(report);
9436 } catch (Exception e) {
9437 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009438 } finally {
9439 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009440 }
9441 }
9442
9443 /**
fionaxud9622282017-07-17 17:51:30 -07009444 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9445 * @param subId the subscription ID that this action applies to.
9446 * {@hide}
9447 */
9448 @Override
9449 public void carrierActionResetAll(int subId) {
9450 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009451
9452 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9453 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll");
9454
fionaxud9622282017-07-17 17:51:30 -07009455 final Phone phone = getPhone(subId);
9456 if (phone == null) {
9457 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9458 return;
9459 }
9460 try {
9461 phone.carrierActionResetAll();
9462 } catch (Exception e) {
9463 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9464 }
9465 }
9466
9467 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009468 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9469 * bug report is being generated.
9470 */
9471 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009472 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009473 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9474 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009475 writer.println("Permission Denial: can't dump Phone from pid="
9476 + Binder.getCallingPid()
9477 + ", uid=" + Binder.getCallingUid()
9478 + "without permission "
9479 + android.Manifest.permission.DUMP);
9480 return;
9481 }
Allen Xu4574a1a2024-05-13 23:10:02 +00009482 try {
9483 DumpsysHandler.dump(mApp, fd, writer, args);
9484 } catch (Exception e) {
9485 writer.println("Failed to dump phone information: " + e);
9486 }
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009487 }
Jack Yueb89b242016-06-22 13:27:47 -07009488
Brad Ebingerdac2f002018-04-03 15:17:52 -07009489 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009490 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9491 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9492 @NonNull String[] args) {
9493 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9494 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009495 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009496 }
9497
Jack Yueb89b242016-06-22 13:27:47 -07009498 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009499 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009500 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009501 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009502 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009503 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009504 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009505 */
9506 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009507 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009508 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009509 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9510 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9511 try {
9512 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009513 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009514 } catch (SecurityException se) {
9515 enforceModifyPermission();
9516 }
9517 } else {
9518 enforceModifyPermission();
9519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009520
joonhunshin4ac60942023-11-15 15:23:39 +00009521 enforceTelephonyFeatureWithException(callingPackage,
9522 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
9523
Nate Myren116695d2024-02-09 09:36:01 -08009524 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009525 final long identity = Binder.clearCallingIdentity();
9526 try {
Nate Myren116695d2024-02-09 09:36:01 -08009527 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
9528 && null != callingPackage && opEnableMobileDataByUser()) {
Nate Myren453c3472024-03-13 11:28:11 -07009529 mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
Nate Myren116695d2024-02-09 09:36:01 -08009530 callingUid, callingPackage, null, null);
9531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009532 Phone phone = getPhone(subId);
9533 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009534 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9535 phone.carrierActionSetMeteredApnsEnabled(enabled);
Hunsuk Choibf761bf2024-06-18 08:34:32 +00009536 } else if (phone.getDataSettingsManager() != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07009537 phone.getDataSettingsManager().setDataEnabled(
9538 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009540 }
9541 } finally {
9542 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009543 }
9544 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009545
9546 /**
9547 * Get Client request stats
9548 * @return List of Client Request Stats
9549 * @hide
9550 */
9551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009552 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9553 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009554 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009555 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009556 return null;
9557 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009558 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009559
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009560 final long identity = Binder.clearCallingIdentity();
9561 try {
9562 if (phone != null) {
9563 return phone.getClientRequestStats();
9564 }
9565
9566 return null;
9567 } finally {
9568 Binder.restoreCallingIdentity(identity);
9569 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009570 }
9571
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009572 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009573 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009574 if (uid == Process.ROOT_UID && packageName == null) {
9575 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9576 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9577 // exception. ROOT_UID seems not to have a valid package name returned by
9578 // PackageManager, so just fake it here to avoid issues when running telephony shell
9579 // commands that plumb through the RIL as root, like so:
9580 // $ adb root
9581 // $ adb shell cmd phone ...
9582 packageName = "root";
9583 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009584 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009585 }
Jack Yueb4124c2017-02-16 15:32:43 -08009586
9587 /**
Grace Chen70990072017-03-24 17:21:30 -07009588 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009589 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009590 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009591 * @param state State of SIM (power down, power up, pass through)
9592 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9593 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9594 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009595 *
9596 **/
9597 @Override
Grace Chen70990072017-03-24 17:21:30 -07009598 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009599 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009600
9601 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9602 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot");
9603
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009604 Phone phone = PhoneFactory.getPhone(slotIndex);
9605
vagdeviaf9a5b92018-08-15 16:01:53 -07009606 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009608 final long identity = Binder.clearCallingIdentity();
9609 try {
9610 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009611 phone.setSimPowerState(state, null, workSource);
9612 }
9613 } finally {
9614 Binder.restoreCallingIdentity(identity);
9615 }
9616 }
9617
9618 /**
9619 * Set SIM card power state.
9620 *
9621 * @param slotIndex SIM slot id.
9622 * @param state State of SIM (power down, power up, pass through)
9623 * @param callback callback to trigger after success or failure
9624 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9625 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9626 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9627 *
9628 **/
9629 @Override
9630 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9631 IIntegerConsumer callback) {
9632 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +00009633
9634 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9635 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
9636 "setSimPowerStateForSlotWithCallback");
9637
Jordan Liu109698e2020-11-24 14:50:34 -08009638 Phone phone = PhoneFactory.getPhone(slotIndex);
9639
9640 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9641
9642 final long identity = Binder.clearCallingIdentity();
9643 try {
9644 if (phone != null) {
9645 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9646 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009647 }
9648 } finally {
9649 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009650 }
9651 }
Shuo Qiandd210312017-04-12 22:11:33 +00009652
Tyler Gunn65d45c22017-06-05 11:22:26 -07009653 private boolean isUssdApiAllowed(int subId) {
9654 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009655 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009656 if (configManager == null) {
9657 return false;
9658 }
9659 PersistableBundle pb = configManager.getConfigForSubId(subId);
9660 if (pb == null) {
9661 return false;
9662 }
9663 return pb.getBoolean(
9664 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9665 }
9666
Shuo Qiandd210312017-04-12 22:11:33 +00009667 /**
Ling Mac28f0212023-03-24 16:07:15 -07009668 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009669 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009670 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009671 */
goneil9c5f4872017-12-05 14:07:56 -08009672 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009673 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009674 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
joonhunshin4ac60942023-11-15 15:23:39 +00009675
9676 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9677 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode");
9678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009679 final long identity = Binder.clearCallingIdentity();
9680 try {
Ling Mac28f0212023-03-24 16:07:15 -07009681 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009682 } finally {
9683 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009684 }
9685 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009686
9687 /**
9688 * Get the current signal strength information for the given subscription.
9689 * Because this information is not updated when the device is in a low power state
9690 * it should not be relied-upon to be current.
9691 * @param subId Subscription index
9692 * @return the most recent cached signal strength info from the modem
9693 */
9694 @Override
9695 public SignalStrength getSignalStrength(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +00009696 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9697 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength");
9698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009699 final long identity = Binder.clearCallingIdentity();
9700 try {
9701 Phone p = getPhone(subId);
9702 if (p == null) {
9703 return null;
9704 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009706 return p.getSignalStrength();
9707 } finally {
9708 Binder.restoreCallingIdentity(identity);
9709 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009710 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009711
Pengquan Meng77b7f132018-08-22 14:49:57 -07009712 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009713 * Get the current modem radio state for the given slot.
9714 * @param slotIndex slot index.
9715 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009716 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009717 * @return the current radio power state from the modem
9718 */
9719 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009720 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009721 Phone phone = PhoneFactory.getPhone(slotIndex);
9722 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9724 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009725 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9726 }
9727
joonhunshin4ac60942023-11-15 15:23:39 +00009728 enforceTelephonyFeatureWithException(callingPackage,
9729 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState");
9730
Chen Xuf792fd62018-10-17 17:54:36 +00009731 final long identity = Binder.clearCallingIdentity();
9732 try {
9733 return phone.getRadioPowerState();
9734 } finally {
9735 Binder.restoreCallingIdentity(identity);
9736 }
9737 }
9738 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9739 }
9740
9741 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009742 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9743 *
9744 * <p>Requires one of the following permissions:
9745 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009746 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009747 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9748 * privileges.
9749 *
9750 * @param subId subscription id
9751 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9752 * {@code false}.
9753 */
9754 @Override
9755 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009756 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009757 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009758 try {
9759 mApp.enforceCallingOrSelfPermission(
9760 android.Manifest.permission.ACCESS_NETWORK_STATE,
9761 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009762 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009763 mApp.enforceCallingOrSelfPermission(
9764 permission.READ_BASIC_PHONE_STATE, functionName);
9765 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009766 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009767 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009768 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009769 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009770
joonhunshin4ac60942023-11-15 15:23:39 +00009771 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9772 PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled");
9773
Pengquan Menga1bb6272018-09-06 09:59:22 -07009774 boolean isEnabled = false;
9775 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009776 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009777 Phone phone = getPhone(subId);
9778 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009779 } finally {
9780 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009781 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009782 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009783 }
9784
9785
9786 /**
9787 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9788 *
9789 * <p> Requires permission:
9790 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9791 * privileges.
9792 *
9793 * @param subId subscription id
9794 * @param isEnabled {@code true} means enable, {@code false} means disable.
9795 */
9796 @Override
9797 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9799 mApp, subId, "setDataRoamingEnabled");
9800
joonhunshin4ac60942023-11-15 15:23:39 +00009801 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9802 PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled");
9803
Pengquan Menga1bb6272018-09-06 09:59:22 -07009804 final long identity = Binder.clearCallingIdentity();
9805 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009806 Phone phone = getPhone(subId);
9807 if (phone != null) {
9808 phone.setDataRoamingEnabled(isEnabled);
9809 }
9810 } finally {
9811 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009812 }
9813 }
9814
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009815 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009816 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009817 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009818 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009819 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009820
joonhunshin4ac60942023-11-15 15:23:39 +00009821 enforceTelephonyFeatureWithException(getCurrentPackageName(),
9822 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed");
9823
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009824 boolean isAllowed = true;
9825 final long identity = Binder.clearCallingIdentity();
9826 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009827 Phone phone = getPhone(subId);
9828 if (phone != null) {
9829 isAllowed = phone.isCspPlmnEnabled();
9830 }
9831 } finally {
9832 Binder.restoreCallingIdentity(identity);
9833 }
9834 return isAllowed;
9835 }
9836
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009837 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9838 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009839 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009840 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009841 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009842 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9843 if (phone == null) {
9844 return false;
9845 }
9846 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9847 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9848 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009849 }
9850
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009851 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009852 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009853 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009854 mApp.getSystemService(AppOpsManager.class)
9855 .checkPackage(Binder.getCallingUid(), callingPackage);
9856
Jordan Liu1e142fc2019-04-22 15:10:43 -07009857 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009858 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009859 try {
9860 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009861 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009862 } catch (SecurityException e) {
9863 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9864 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009865 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009866 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009867 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009868 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009869 }
joonhunshin4ac60942023-11-15 15:23:39 +00009870
9871 enforceTelephonyFeatureWithException(callingPackage,
9872 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo");
9873
sandeepjsb6c87872021-09-27 15:34:44 +00009874 // checking compatibility, if calling app's target SDK is T and beyond.
9875 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9876 Binder.getCallingUid())) {
9877 isIccIdAccessRestricted = true;
9878 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009879 final long identity = Binder.clearCallingIdentity();
9880 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009881 UiccController uiccController = UiccController.getInstance();
9882 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009883 if (hasReadPermission) {
9884 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009885 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009886
9887 // Remove private info if the caller doesn't have access
9888 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9889 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009890 //setting the value after compatibility check
9891 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009892 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9893 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009894 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009895 if (card == null) {
9896 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009897 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009898 continue;
9899 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009900 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9901 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009902 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009903 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009904 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009905 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9906 for (UiccPortInfo portInfo : portInfos) {
9907 UiccPort port = uiccController.getUiccPortForSlot(
9908 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9909 if (port == null) {
9910 // assume no access if port is null
9911 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9912 continue;
9913 }
9914 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9915 uiccPortInfos.add(portInfo);
9916 } else {
9917 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9918 }
9919 }
9920 filteredInfos.add(new UiccCardInfo(
9921 cardInfo.isEuicc(),
9922 cardInfo.getCardId(),
9923 null,
9924 cardInfo.getPhysicalSlotIndex(),
9925 cardInfo.isRemovable(),
9926 cardInfo.isMultipleEnabledProfilesSupported(),
9927 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009928 }
9929 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009930 } finally {
9931 Binder.restoreCallingIdentity(identity);
9932 }
9933 }
9934
sandeepjsb6c87872021-09-27 15:34:44 +00009935 /**
9936 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9937 * generally private and require carrier privileges to view.
9938 *
9939 * @hide
9940 */
9941 @NonNull
9942 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9943 List<UiccPortInfo> portinfo = new ArrayList<>();
9944 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9945 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9946 }
9947 return new UiccCardInfo(
9948 cardInfo.isEuicc(),
9949 cardInfo.getCardId(),
9950 null,
9951 cardInfo.getPhysicalSlotIndex(),
9952 cardInfo.isRemovable(),
9953 cardInfo.isMultipleEnabledProfilesSupported(),
9954 portinfo
9955 );
9956 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009957
sandeepjsb6c87872021-09-27 15:34:44 +00009958 /**
9959 * @hide
9960 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9961 * These values are generally private and require carrier privileges to view.
9962 */
9963 @NonNull
9964 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9965 return new UiccPortInfo(
9966 UiccPortInfo.ICCID_REDACTED,
9967 portInfo.getPortIndex(),
9968 portInfo.getLogicalSlotIndex(),
9969 portInfo.isActive()
9970 );
9971 }
9972 @Override
9973 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009974 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009975 mApp.getSystemService(AppOpsManager.class)
9976 .checkPackage(Binder.getCallingUid(), callingPackage);
9977
sandeepjsb6c87872021-09-27 15:34:44 +00009978 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009979
Aman Guptaf3c90b32022-03-17 04:54:16 +00009980 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9981 // we are reading iccId which is PII data.
9982 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009983
joonhunshin4ac60942023-11-15 15:23:39 +00009984 enforceTelephonyFeatureWithException(callingPackage,
9985 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo");
9986
sandeepjsb6c87872021-09-27 15:34:44 +00009987 // checking compatibility, if calling app's target SDK is T and beyond.
9988 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9989 Binder.getCallingUid())) {
9990 isLogicalSlotAccessRestricted = true;
9991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009992 final long identity = Binder.clearCallingIdentity();
9993 try {
9994 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009995 if (slots == null || slots.length == 0) {
9996 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009997 return null;
9998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009999 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10000 for (int i = 0; i < slots.length; i++) {
10001 UiccSlot slot = slots[i];
10002 if (slot == null) {
10003 continue;
10004 }
10005
Jordan Liu7be7e652019-05-06 18:55:02 +000010006 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010007 UiccCard card = slot.getUiccCard();
10008 if (card != null) {
10009 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010010 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010011 cardId = slot.getEid();
10012 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010013 // If cardId is null, use iccId of default port as cardId.
10014 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010016 }
10017
Jordan Liu857451f2019-05-09 16:35:35 -070010018 if (cardId != null) {
10019 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10020 // if cardId is an EID, it's all digits so this is fine
10021 cardId = IccUtils.stripTrailingFs(cardId);
10022 }
10023
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010024 int cardState = 0;
10025 switch (slot.getCardState()) {
10026 case CARDSTATE_ABSENT:
10027 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10028 break;
10029 case CARDSTATE_PRESENT:
10030 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10031 break;
10032 case CARDSTATE_ERROR:
10033 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10034 break;
10035 case CARDSTATE_RESTRICTED:
10036 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10037 break;
10038 default:
10039 break;
10040
10041 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010042 List<UiccPortInfo> portInfos = new ArrayList<>();
10043 int[] portIndexes = slot.getPortList();
10044 for (int portIdx : portIndexes) {
10045 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010046 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010047 portInfos.add(new UiccPortInfo(iccId, portIdx,
10048 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010050 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010051 slot.isEuicc(),
10052 cardId,
10053 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010054 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010055 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010056 //setting the value after compatibility check
10057 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010058 }
10059 return infos;
10060 } finally {
10061 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010062 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010063 }
10064
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010065 /* Returns null if doesn't have read permission or carrier privilege access. */
10066 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10067 boolean hasReadPermission) {
10068 String iccId = slot.getIccId(portIndex);
10069 if (hasReadPermission) { // if has read permission
10070 return iccId;
10071 } else {
10072 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10073 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10074 // if no read permission, checking carrier privilege access
10075 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10076 return iccId;
10077 }
10078 }
10079 }
10080 // No read permission or carrier privilege access.
10081 return UiccPortInfo.ICCID_REDACTED;
10082 }
10083
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010084 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010085 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010086 public boolean switchSlots(int[] physicalSlots) {
10087 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010088
joonhunshin4ac60942023-11-15 15:23:39 +000010089 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10090 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots");
10091
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010092 final long identity = Binder.clearCallingIdentity();
10093 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010094 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10095 for (int i = 0; i < physicalSlots.length; i++) {
10096 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10097 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10098 physicalSlots[i], i));
10099 }
10100 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010101 } finally {
10102 Binder.restoreCallingIdentity(identity);
10103 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010104 }
Jack Yu4c988042018-02-27 15:30:01 -080010105
10106 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010107 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10108 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10109 enforceModifyPermission();
10110
joonhunshin4ac60942023-11-15 15:23:39 +000010111 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10112 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping");
10113
sandeepjsb6c87872021-09-27 15:34:44 +000010114 final long identity = Binder.clearCallingIdentity();
10115 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010116 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010117 } finally {
10118 Binder.restoreCallingIdentity(identity);
10119 }
10120 }
10121
10122 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010123 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
joonhunshin4ac60942023-11-15 15:23:39 +000010124 enforceTelephonyFeatureWithException(callingPackage,
10125 PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc");
10126
Jordan Liu7de49fa2018-12-06 14:48:49 -080010127 final long identity = Binder.clearCallingIdentity();
10128 try {
10129 return UiccController.getInstance().getCardIdForDefaultEuicc();
10130 } finally {
10131 Binder.restoreCallingIdentity(identity);
10132 }
10133 }
10134
Pengquan Meng85728fb2018-03-12 16:31:21 -070010135 /**
goneil47ffb6e2018-04-06 15:40:58 -070010136 * A test API to reload the UICC profile.
10137 *
10138 * <p>Requires that the calling app has permission
10139 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10140 * @hide
10141 */
10142 @Override
10143 public void refreshUiccProfile(int subId) {
10144 enforceModifyPermission();
10145
10146 final long identity = Binder.clearCallingIdentity();
10147 try {
10148 Phone phone = getPhone(subId);
10149 if (phone == null) {
10150 return;
10151 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010152 UiccPort uiccPort = phone.getUiccPort();
10153 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010154 return;
10155 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010156 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010157 if (uiccProfile == null) {
10158 return;
10159 }
10160 uiccProfile.refresh();
10161 } finally {
10162 Binder.restoreCallingIdentity(identity);
10163 }
10164 }
10165
10166 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010167 * Returns false if the mobile data is disabled by default, otherwise return true.
10168 */
10169 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010170 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010171 }
10172
10173 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010174 * Returns the default network type for the given {@code subId}, if the default network type is
10175 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10176 */
10177 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010178 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010179 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010180 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10181 return list.get(phoneId);
10182 }
10183 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010184 }
fionaxua13278b2018-03-21 00:08:13 -070010185
10186 @Override
10187 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010188 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010189 enforceModifyPermission();
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("setCarrierTestOverride fails with invalid subId: " + subId);
10196 return;
10197 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010198 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10199 if (cpt != null) {
10200 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10201 }
10202 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010203 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10204 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010205 if (carrierPrivilegeRules == null) {
10206 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10207 } else {
10208 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010210 } finally {
10211 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010212 }
fionaxua13278b2018-03-21 00:08:13 -070010213 }
10214
10215 @Override
Benedict Wong66477622023-02-03 23:30:57 +000010216 public void setCarrierServicePackageOverride(
10217 int subId, String carrierServicePackage, String callingPackage) {
10218 TelephonyPermissions.enforceShellOnly(
10219 Binder.getCallingUid(), "setCarrierServicePackageOverride");
10220
Benedict Wong66477622023-02-03 23:30:57 +000010221 final long identity = Binder.clearCallingIdentity();
10222 try {
10223 final Phone phone = getPhone(subId);
10224 if (phone == null || phone.getSubId() != subId) {
10225 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
10226 throw new IllegalArgumentException("No phone for subid");
10227 }
10228 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10229 if (cpt == null) {
10230 loge("setCarrierServicePackageOverride failed with no CPT for phone");
10231 throw new IllegalStateException("No CPT for phone");
10232 }
10233 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
10234 } finally {
10235 Binder.restoreCallingIdentity(identity);
10236 }
10237 }
10238
10239 @Override
fionaxua13278b2018-03-21 00:08:13 -070010240 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010241 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010242
10243 final long identity = Binder.clearCallingIdentity();
10244 try {
10245 final Phone phone = getPhone(subId);
10246 if (phone == null) {
10247 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10248 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10249 }
10250 return phone.getCarrierIdListVersion();
10251 } finally {
10252 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010253 }
fionaxua13278b2018-03-21 00:08:13 -070010254 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010255
10256 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010257 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10258 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010260 mApp, subId, callingPackage, callingFeatureId,
10261 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010262 return -1;
10263 }
10264
10265 final long identity = Binder.clearCallingIdentity();
10266 try {
10267 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10268 } finally {
10269 Binder.restoreCallingIdentity(identity);
10270 }
10271 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010272
10273 @Override
10274 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010275 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010276 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010277 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010278
joonhunshin4ac60942023-11-15 15:23:39 +000010279 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10280 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode");
10281
Pengquan Menga1bb6272018-09-06 09:59:22 -070010282 final long identity = Binder.clearCallingIdentity();
10283 try {
10284 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10285 } finally {
10286 Binder.restoreCallingIdentity(identity);
10287 }
10288 }
10289
10290 @Override
10291 public boolean setCdmaRoamingMode(int subId, int mode) {
10292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10293 mApp, subId, "setCdmaRoamingMode");
10294
joonhunshin4ac60942023-11-15 15:23:39 +000010295 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10296 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode");
10297
Pengquan Menga1bb6272018-09-06 09:59:22 -070010298 final long identity = Binder.clearCallingIdentity();
10299 try {
10300 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10301 } finally {
10302 Binder.restoreCallingIdentity(identity);
10303 }
10304 }
10305
10306 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010307 public int getCdmaSubscriptionMode(int subId) {
10308 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010309 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010310 mApp, subId, "getCdmaSubscriptionMode");
10311
joonhunshin4ac60942023-11-15 15:23:39 +000010312 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10313 PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode");
10314
Sarah Chinbaab1432020-10-28 13:46:24 -070010315 final long identity = Binder.clearCallingIdentity();
10316 try {
10317 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10318 } finally {
10319 Binder.restoreCallingIdentity(identity);
10320 }
10321 }
10322
10323 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010324 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10326 mApp, subId, "setCdmaSubscriptionMode");
10327
joonhunshin4ac60942023-11-15 15:23:39 +000010328 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10329 PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode");
10330
Pengquan Menga1bb6272018-09-06 09:59:22 -070010331 final long identity = Binder.clearCallingIdentity();
10332 try {
10333 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10334 } finally {
10335 Binder.restoreCallingIdentity(identity);
10336 }
10337 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010338
sqianc5eccab2018-10-19 18:46:41 -070010339 @Override
sqian8c685422019-02-22 15:55:18 -080010340 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010341 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010343 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10344 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010345 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10346 }
joonhunshin4ac60942023-11-15 15:23:39 +000010347
10348 enforceTelephonyFeatureWithException(callingPackage,
10349 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList");
10350
sqian11b7a0e2018-12-05 18:48:28 -080010351 final long identity = Binder.clearCallingIdentity();
10352 try {
sqian854d44b2018-12-12 16:48:18 -080010353 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10354 for (Phone phone: PhoneFactory.getPhones()) {
10355 if (phone.getEmergencyNumberTracker() != null
10356 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10357 emergencyNumberListInternal.put(
10358 phone.getSubId(),
10359 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10360 }
sqian11b7a0e2018-12-05 18:48:28 -080010361 }
sqian854d44b2018-12-12 16:48:18 -080010362 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010363 } finally {
10364 Binder.restoreCallingIdentity(identity);
10365 }
sqianc5eccab2018-10-19 18:46:41 -070010366 }
10367
10368 @Override
sqian8c685422019-02-22 15:55:18 -080010369 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010370 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010371 if (!exactMatch) {
10372 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010373 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010374 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010375 }
joonhunshin4ac60942023-11-15 15:23:39 +000010376
10377 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10378 PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber");
10379
sqian11b7a0e2018-12-05 18:48:28 -080010380 final long identity = Binder.clearCallingIdentity();
10381 try {
sqian854d44b2018-12-12 16:48:18 -080010382 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010383 //Note: we ignore passed in param exactMatch. We can remove it once
10384 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010385 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010386 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010387 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010388 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010389 }
sqian11b7a0e2018-12-05 18:48:28 -080010390 }
10391 return false;
10392 } finally {
10393 Binder.restoreCallingIdentity(identity);
10394 }
10395 }
10396
sqianf4ca7ed2019-01-15 18:32:07 -080010397 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010398 * Start emergency callback mode for GsmCdmaPhone for testing.
10399 */
10400 @Override
10401 public void startEmergencyCallbackMode() {
10402 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10403 "startEmergencyCallbackMode");
10404 enforceModifyPermission();
10405 final long identity = Binder.clearCallingIdentity();
10406 try {
10407 for (Phone phone : PhoneFactory.getPhones()) {
10408 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10409 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10410 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10411 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10412 gsmCdmaPhone.obtainMessage(
10413 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10414 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10415 }
10416 }
10417 } finally {
10418 Binder.restoreCallingIdentity(identity);
10419 }
10420 }
10421
10422 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010423 * Update emergency number list for test mode.
10424 */
10425 @Override
10426 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10427 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10428 "updateEmergencyNumberListTestMode");
10429
10430 final long identity = Binder.clearCallingIdentity();
10431 try {
10432 for (Phone phone: PhoneFactory.getPhones()) {
10433 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10434 if (tracker != null) {
10435 tracker.executeEmergencyNumberTestModeCommand(action, num);
10436 }
10437 }
10438 } finally {
10439 Binder.restoreCallingIdentity(identity);
10440 }
10441 }
10442
10443 /**
10444 * Get the full emergency number list for test mode.
10445 */
10446 @Override
10447 public List<String> getEmergencyNumberListTestMode() {
10448 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10449 "getEmergencyNumberListTestMode");
10450
10451 final long identity = Binder.clearCallingIdentity();
10452 try {
10453 Set<String> emergencyNumbers = new HashSet<>();
10454 for (Phone phone: PhoneFactory.getPhones()) {
10455 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10456 if (tracker != null) {
10457 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10458 emergencyNumbers.add(num.getNumber());
10459 }
10460 }
10461 }
10462 return new ArrayList<>(emergencyNumbers);
10463 } finally {
10464 Binder.restoreCallingIdentity(identity);
10465 }
10466 }
10467
chen xud6b45bd2018-10-30 22:27:10 -070010468 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010469 public int getEmergencyNumberDbVersion(int subId) {
10470 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10471
joonhunshin4ac60942023-11-15 15:23:39 +000010472 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10473 PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion");
10474
Shuo Qian3b6ee772019-11-13 17:43:31 -080010475 final long identity = Binder.clearCallingIdentity();
10476 try {
10477 final Phone phone = getPhone(subId);
10478 if (phone == null) {
10479 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10480 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10481 }
10482 return phone.getEmergencyNumberDbVersion();
10483 } finally {
10484 Binder.restoreCallingIdentity(identity);
10485 }
10486 }
10487
10488 @Override
10489 public void notifyOtaEmergencyNumberDbInstalled() {
10490 enforceModifyPermission();
10491
joonhunshin4ac60942023-11-15 15:23:39 +000010492 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10493 PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled");
10494
Shuo Qian3b6ee772019-11-13 17:43:31 -080010495 final long identity = Binder.clearCallingIdentity();
10496 try {
10497 for (Phone phone: PhoneFactory.getPhones()) {
10498 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10499 if (tracker != null) {
10500 tracker.updateOtaEmergencyNumberDatabase();
10501 }
10502 }
10503 } finally {
10504 Binder.restoreCallingIdentity(identity);
10505 }
10506 }
10507
10508 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010509 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010510 enforceActiveEmergencySessionPermission();
10511
joonhunshin4ac60942023-11-15 15:23:39 +000010512 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10513 PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath");
10514
Shuo Qian3b6ee772019-11-13 17:43:31 -080010515 final long identity = Binder.clearCallingIdentity();
10516 try {
10517 for (Phone phone: PhoneFactory.getPhones()) {
10518 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10519 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010520 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10521 }
10522 }
10523 } finally {
10524 Binder.restoreCallingIdentity(identity);
10525 }
10526 }
10527
10528 @Override
10529 public void resetOtaEmergencyNumberDbFilePath() {
10530 enforceActiveEmergencySessionPermission();
10531
joonhunshin4ac60942023-11-15 15:23:39 +000010532 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10533 PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath");
10534
Shuo Qianc373f112020-03-05 17:55:34 -080010535 final long identity = Binder.clearCallingIdentity();
10536 try {
10537 for (Phone phone: PhoneFactory.getPhones()) {
10538 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10539 if (tracker != null) {
10540 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010541 }
10542 }
10543 } finally {
10544 Binder.restoreCallingIdentity(identity);
10545 }
10546 }
10547
10548 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010549 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10550 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10551 Phone phone = getPhone(subId);
10552 if (phone == null) {
10553 return null;
10554 }
10555 final long identity = Binder.clearCallingIdentity();
10556 try {
10557 UiccProfile profile = UiccController.getInstance()
10558 .getUiccProfileForPhone(phone.getPhoneId());
10559 if (profile != null) {
10560 return profile.getCertsFromCarrierPrivilegeAccessRules();
10561 }
10562 } finally {
10563 Binder.restoreCallingIdentity(identity);
10564 }
10565 return null;
10566 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010567
10568 /**
10569 * Enable or disable a modem stack.
10570 */
10571 @Override
10572 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10573 enforceModifyPermission();
10574
joonhunshin4ac60942023-11-15 15:23:39 +000010575 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10576 PackageManager.FEATURE_TELEPHONY, "enableModemForSlot");
10577
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010578 final long identity = Binder.clearCallingIdentity();
10579 try {
10580 Phone phone = PhoneFactory.getPhone(slotIndex);
10581 if (phone == null) {
10582 return false;
10583 } else {
10584 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10585 }
10586 } finally {
10587 Binder.restoreCallingIdentity(identity);
10588 }
10589 }
Michelecea4cf22018-12-21 15:00:11 -080010590
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010591 /**
10592 * Whether a modem stack is enabled or not.
10593 */
10594 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010595 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10596 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010597 Phone phone = PhoneFactory.getPhone(slotIndex);
10598 if (phone == null) return false;
10599
10600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010601 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10602 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010603 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10604 }
10605
joonhunshin4ac60942023-11-15 15:23:39 +000010606 enforceTelephonyFeatureWithException(callingPackage,
10607 PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot");
10608
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010609 final long identity = Binder.clearCallingIdentity();
10610 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010611 try {
10612 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10613 } catch (NoSuchElementException ex) {
10614 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10615 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010616 } finally {
10617 Binder.restoreCallingIdentity(identity);
10618 }
10619 }
10620
Michelecea4cf22018-12-21 15:00:11 -080010621 @Override
Michele0ea7d782019-03-19 14:58:42 -070010622 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010623 enforceModifyPermission();
10624
joonhunshin4ac60942023-11-15 15:23:39 +000010625 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10626 PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction");
10627
Michelecea4cf22018-12-21 15:00:11 -080010628 final long identity = Binder.clearCallingIdentity();
10629 try {
10630 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010631 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010632 .commit();
10633 } finally {
10634 Binder.restoreCallingIdentity(identity);
10635 }
10636 }
10637
10638 @Override
Michele0ea7d782019-03-19 14:58:42 -070010639 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010640 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010641 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010642 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10643 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010644 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010645 }
Michelecea4cf22018-12-21 15:00:11 -080010646
joonhunshin4ac60942023-11-15 15:23:39 +000010647 enforceTelephonyFeatureWithException(callingPackage,
10648 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported");
10649
Michelecea4cf22018-12-21 15:00:11 -080010650 final long identity = Binder.clearCallingIdentity();
10651 try {
Michele0ea7d782019-03-19 14:58:42 -070010652 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010653 } finally {
10654 Binder.restoreCallingIdentity(identity);
10655 }
10656 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010657
Michele0ea7d782019-03-19 14:58:42 -070010658 @TelephonyManager.IsMultiSimSupportedResult
10659 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010660 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10661 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10662 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010663 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10664 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010665 }
10666 // Check if the hardware supports multisim functionality. If usage of multisim is not
10667 // supported by the modem, indicate that it is restricted.
10668 PhoneCapability staticCapability =
10669 mPhoneConfigurationManager.getStaticPhoneCapability();
10670 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010671 loge("isMultiSimSupportedInternal: no static configuration available");
10672 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010673 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010674 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010675 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10676 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010677 }
10678 // Check if support of multiple SIMs is restricted by carrier
10679 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010680 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010681 }
10682
Michele0ea7d782019-03-19 14:58:42 -070010683 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010684 }
10685
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010686 /**
10687 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010688 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10689 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10690 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010691 * @param numOfSims number of active sims we want to switch to
10692 */
10693 @Override
10694 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010695 if (numOfSims == 1) {
10696 enforceModifyPermission();
10697 } else {
10698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10699 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10700 }
joonhunshin4ac60942023-11-15 15:23:39 +000010701
10702 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10703 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig");
10704
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010705 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010706
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010707 try {
Michele30b57b22019-03-01 12:01:14 -080010708 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010709 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010710 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10711 return;
10712 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010713 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10714 } finally {
10715 Binder.restoreCallingIdentity(identity);
10716 }
10717 }
10718
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010719 @Override
10720 public boolean isApplicationOnUicc(int subId, int appType) {
10721 enforceReadPrivilegedPermission("isApplicationOnUicc");
joonhunshin4ac60942023-11-15 15:23:39 +000010722
10723 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10724 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc");
10725
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010726 Phone phone = getPhone(subId);
10727 if (phone == null) {
10728 return false;
10729 }
10730 final long identity = Binder.clearCallingIdentity();
10731 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010732 UiccPort uiccPort = phone.getUiccPort();
10733 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010734 return false;
10735 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010736 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010737 if (uiccProfile == null) {
10738 return false;
10739 }
10740 if (TelephonyManager.APPTYPE_SIM <= appType
10741 && appType <= TelephonyManager.APPTYPE_ISIM) {
10742 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10743 }
10744 return false;
10745 } finally {
10746 Binder.restoreCallingIdentity(identity);
10747 }
10748 }
10749
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010750 /**
chen xub4baa772019-04-03 10:23:41 -070010751 * Get whether making changes to modem configurations will trigger reboot.
10752 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010753 */
10754 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010755 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10756 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010758 mApp, subId, callingPackage, callingFeatureId,
10759 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010760 return false;
10761 }
joonhunshin4ac60942023-11-15 15:23:39 +000010762
10763 enforceTelephonyFeatureWithException(callingPackage,
10764 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION,
10765 "doesSwitchMultiSimConfigTriggerReboot");
10766
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10770 } finally {
10771 Binder.restoreCallingIdentity(identity);
10772 }
10773 }
10774
Nathan Harold29f5f052019-02-15 13:41:57 -080010775 private void updateModemStateMetrics() {
10776 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10777 // TODO: check the state for each modem if the api is ready.
10778 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10779 }
10780
Pengquan Meng3889a572019-01-23 11:16:29 -080010781 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010782 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010783 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010784 // Verify that the callingPackage belongs to the calling UID
10785 mApp.getSystemService(AppOpsManager.class)
10786 .checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000010787
10788 enforceTelephonyFeatureWithException(callingPackage,
10789 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping");
10790
Pengquan Meng3889a572019-01-23 11:16:29 -080010791 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010792 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010793 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010794 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10795 if (slotInfos != null) {
10796 for (int i = 0; i < slotInfos.length; i++) {
10797 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10798 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10799 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10800 portInfo.getLogicalSlotIndex()));
10801 }
10802 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010803 }
10804 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010805 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010806 } finally {
10807 Binder.restoreCallingIdentity(identity);
10808 }
10809 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010810
10811 /**
10812 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010813 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010814 */
jimsunf9ec1622022-09-13 21:18:43 +080010815 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010816 @Override
10817 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010818 return getHalVersion(HAL_SERVICE_RADIO);
10819 }
10820
10821 /**
10822 * Get the HAL Version of a specific service
10823 */
10824 @Override
10825 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010826 Phone phone = getDefaultPhone();
10827 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010828 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010829 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10830 return hv.major * 100 + hv.minor;
10831 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010832
10833 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010834 * Get the current calling package name.
sangyun097dcf72024-01-04 10:35:49 +090010835 *
10836 * @return the current calling package name, or null if there is no known package.
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010837 */
10838 @Override
sangyun097dcf72024-01-04 10:35:49 +090010839 public @Nullable String getCurrentPackageName() {
10840 PackageManager pm = mApp.getPackageManager();
10841 String[] packageNames = pm == null ? null : pm.getPackagesForUid(Binder.getCallingUid());
10842 return packageNames == null ? null : packageNames[0];
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010843 }
10844
10845 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010846 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10847 * corresponding network requests on a subId.
10848 *
10849 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010850 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010851 * 2) APN is un-metered for this subscription, or
10852 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010853 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010854 *
10855 * @return whether data is allowed for a apn type.
10856 *
10857 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010858 */
10859 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010860 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010861 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10862 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010863
joonhunshin4ac60942023-11-15 15:23:39 +000010864 enforceTelephonyFeatureWithException(callingPackage,
10865 PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn");
10866
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010867 // Now that all security checks passes, perform the operation as ourselves.
10868 final long identity = Binder.clearCallingIdentity();
10869 try {
10870 Phone phone = getPhone(subId);
10871 if (phone == null) return false;
10872
Jack Yu27422a52022-03-21 10:38:05 -070010873 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010874 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010875 isMetered = phone.getDataNetworkController().getDataConfigManager()
10876 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10877 phone.getServiceState().getDataRoaming());
Hunsuk Choibf761bf2024-06-18 08:34:32 +000010878 isDataEnabled = (phone.getDataSettingsManager() != null)
10879 ? phone.getDataSettingsManager().isDataEnabled(apnType) : false;
Jack Yu99e87332021-12-17 23:14:15 -080010880 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010881 } finally {
10882 Binder.restoreCallingIdentity(identity);
10883 }
10884 }
10885
10886 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010887 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010888 enforceReadPrivilegedPermission("isApnMetered");
10889
joonhunshin4ac60942023-11-15 15:23:39 +000010890 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10891 PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered");
10892
Malcolm Chene5ad5792019-04-18 13:51:02 -070010893 // Now that all security checks passes, perform the operation as ourselves.
10894 final long identity = Binder.clearCallingIdentity();
10895 try {
10896 Phone phone = getPhone(subId);
10897 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010898 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10899 DataUtils.apnTypeToNetworkCapability(apnType),
10900 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010901 } finally {
10902 Binder.restoreCallingIdentity(identity);
10903 }
10904 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010905
10906 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010907 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10908 int subscriptionId, IBooleanConsumer resultCallback) {
10909 enforceModifyPermission();
joonhunshin4ac60942023-11-15 15:23:39 +000010910
10911 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10912 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels");
10913
Hall Liu73f5d362020-01-20 13:42:00 -080010914 long token = Binder.clearCallingIdentity();
10915 try {
10916 Phone phone = getPhone(subscriptionId);
10917 if (phone == null) {
10918 try {
10919 if (resultCallback != null) {
10920 resultCallback.accept(false);
10921 }
10922 } catch (RemoteException e) {
10923 // ignore
10924 }
10925 return;
10926 }
10927 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10928 Pair.create(specifiers, (x) -> {
10929 try {
10930 if (resultCallback != null) {
10931 resultCallback.accept(x);
10932 }
10933 } catch (RemoteException e) {
10934 // ignore
10935 }
10936 });
10937 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10938 } finally {
10939 Binder.restoreCallingIdentity(token);
10940 }
10941 }
10942
10943 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010944 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10945 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010946 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010947 mApp, subId, "getSystemSelectionChannels");
joonhunshin4ac60942023-11-15 15:23:39 +000010948
10949 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10950 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels");
10951
Sarah Chin679c08a2020-11-18 13:39:35 -080010952 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10953 final long identity = Binder.clearCallingIdentity();
10954 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010955 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10956 if (result instanceof IllegalStateException) {
10957 throw (IllegalStateException) result;
10958 }
10959 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010960 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10961 return specifiers;
10962 } finally {
10963 Binder.restoreCallingIdentity(identity);
10964 }
10965 }
10966
10967 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010968 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010969 enforceReadPrivilegedPermission("isMvnoMatched");
joonhunshin4ac60942023-11-15 15:23:39 +000010970
10971 enforceTelephonyFeatureWithException(getCurrentPackageName(),
10972 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched");
10973
Jack Yu8b766fc2022-03-21 09:42:33 -070010974 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010975 }
10976
10977 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010978 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10979 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010980 if (callingPackage == null) {
10981 callingPackage = getCurrentPackageName();
10982 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010983 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10984 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010985 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10986 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010987 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10988 }
10989 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10990 Intent intent = new Intent();
10991 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10992 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10993 // Bring up choose default SMS subscription dialog right now
10994 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10995 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10996 mApp.startActivity(intent);
10997 }
chen xud5ca2d52019-05-28 15:20:57 -070010998
10999 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000011000 public void showSwitchToManagedProfileDialog() {
11001 enforceModifyPermission();
Anthony Alridge70ba5572023-05-02 12:14:14 +000011002 try {
11003 // Note: This intent is constructed to ensure that the IntentForwarderActivity is
11004 // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils
11005 // for work telephony.
11006 Intent intent = new Intent(Intent.ACTION_SENDTO);
11007 intent.setData(Uri.parse("smsto:"));
11008 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11009 mApp.startActivity(intent);
11010 } catch (ActivityNotFoundException e) {
11011 Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead");
11012 Intent intent = new Intent();
11013 intent.setClass(mApp, ErrorDialogActivity.class);
11014 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
11015 mApp.startActivity(intent);
11016 }
Ayush Sharma787854b2022-12-12 14:55:02 +000011017 }
11018
11019 @Override
chen xud5ca2d52019-05-28 15:20:57 -070011020 public String getMmsUAProfUrl(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011021 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11022 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl");
11023
chen xud5ca2d52019-05-28 15:20:57 -070011024 //TODO investigate if this API should require proper permission check in R b/133791609
11025 final long identity = Binder.clearCallingIdentity();
11026 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011027 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
11028 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
11029 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
11030 return carrierUAProfUrl;
11031 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011032 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11033 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070011034 } finally {
11035 Binder.restoreCallingIdentity(identity);
11036 }
11037 }
11038
11039 @Override
11040 public String getMmsUserAgent(int subId) {
joonhunshin4ac60942023-11-15 15:23:39 +000011041 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11042 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent");
11043
chen xud5ca2d52019-05-28 15:20:57 -070011044 //TODO investigate if this API should require proper permission check in R b/133791609
11045 final long identity = Binder.clearCallingIdentity();
11046 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011047 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11048 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11049 if (!TextUtils.isEmpty(carrierUserAgent)) {
11050 return carrierUserAgent;
11051 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011052 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11053 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011054 } finally {
11055 Binder.restoreCallingIdentity(identity);
11056 }
11057 }
Jack Yub07d4972019-05-28 16:12:25 -070011058
11059 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011060 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11061 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011062
joonhunshin4ac60942023-11-15 15:23:39 +000011063 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11064 PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled");
11065
Jack Yub07d4972019-05-28 16:12:25 -070011066 final long identity = Binder.clearCallingIdentity();
11067 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011068 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011069 if (phone == null || phone.getDataSettingsManager() == null) return false;
Jack Yub07d4972019-05-28 16:12:25 -070011070
Ling Maf188d502022-09-16 15:22:36 -070011071 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011072 } finally {
11073 Binder.restoreCallingIdentity(identity);
11074 }
11075 }
11076
11077 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011078 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011079 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011080 enforceModifyPermission();
11081
joonhunshin4ac60942023-11-15 15:23:39 +000011082 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11083 PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled");
11084
changbettyd5c246e2019-12-24 15:40:37 +080011085 final long identity = Binder.clearCallingIdentity();
11086 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011087 Phone phone = getPhone(subscriptionId);
Hunsuk Choibf761bf2024-06-18 08:34:32 +000011088 if (phone == null || phone.getDataSettingsManager() == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011089
Ling Maf188d502022-09-16 15:22:36 -070011090 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011091 } finally {
11092 Binder.restoreCallingIdentity(identity);
11093 }
11094 }
11095
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011096 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011097 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011098 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11099 * otherwise.
11100 */
11101 @Override
11102 public void setCepEnabled(boolean isCepEnabled) {
11103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11104
11105 final long identity = Binder.clearCallingIdentity();
11106 try {
11107 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11108 for (Phone phone : PhoneFactory.getPhones()) {
11109 Phone defaultPhone = phone.getImsPhone();
11110 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11111 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11112 ImsPhoneCallTracker imsPhoneCallTracker =
11113 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11114 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11115 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11116 + imsPhone.getMsisdn());
11117 }
11118 }
11119 } finally {
11120 Binder.restoreCallingIdentity(identity);
11121 }
11122 }
allenwtsu46dcc572020-01-08 18:24:03 +080011123
11124 /**
11125 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11126 *
11127 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11128 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11129 * before being read.
11130 */
11131 @Override
11132 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11133 isCompressed) {
11134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11135 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011136 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11137 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11138 }
joonhunshin4ac60942023-11-15 15:23:39 +000011139
11140 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11141 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11142 Binder.getCallingUserHandle())) {
11143 if (!isImsAvailableOnDevice()) {
11144 // ProvisioningManager can not handle ServiceSpecificException.
11145 // Throw the IllegalStateException and annotate ProvisioningManager.
11146 throw new IllegalStateException("IMS not available on device.");
11147 }
11148 } else {
11149 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11150 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11151 "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011152 }
11153
11154 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011155 try {
Hui Wang761a6682020-10-31 05:12:53 +000011156 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11157 } finally {
11158 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011159 }
11160 }
zoey chene02881a2019-12-30 16:11:23 +080011161
11162 @Override
11163 public boolean isIccLockEnabled(int subId) {
11164 enforceReadPrivilegedPermission("isIccLockEnabled");
11165
joonhunshin4ac60942023-11-15 15:23:39 +000011166 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11167 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled");
11168
zoey chene02881a2019-12-30 16:11:23 +080011169 // Now that all security checks passes, perform the operation as ourselves.
11170 final long identity = Binder.clearCallingIdentity();
11171 try {
11172 Phone phone = getPhone(subId);
11173 if (phone != null && phone.getIccCard() != null) {
11174 return phone.getIccCard().getIccLockEnabled();
11175 } else {
11176 return false;
11177 }
11178 } finally {
11179 Binder.restoreCallingIdentity(identity);
11180 }
11181 }
11182
11183 /**
11184 * Set the ICC pin lock enabled or disabled.
11185 *
11186 * @return an integer representing the status of IccLock enabled or disabled in the following
11187 * three cases:
11188 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11189 * successfully.
11190 * - Positive number and zero for remaining password attempts.
11191 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11192 *
11193 */
11194 @Override
11195 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11196 enforceModifyPermission();
11197
joonhunshin4ac60942023-11-15 15:23:39 +000011198 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11199 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled");
11200
zoey chene02881a2019-12-30 16:11:23 +080011201 Phone phone = getPhone(subId);
11202 if (phone == null) {
11203 return 0;
11204 }
11205 // Now that all security checks passes, perform the operation as ourselves.
11206 final long identity = Binder.clearCallingIdentity();
11207 try {
11208 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11209 new Pair<Boolean, String>(enabled, password), phone, null);
11210 return attemptsRemaining;
11211
11212 } catch (Exception e) {
11213 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11214 } finally {
11215 Binder.restoreCallingIdentity(identity);
11216 }
11217 return 0;
11218 }
11219
11220 /**
11221 * Change the ICC password used in ICC pin lock.
11222 *
11223 * @return an integer representing the status of IccLock changed in the following three cases:
11224 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11225 * - Positive number and zero for remaining password attempts.
11226 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11227 *
11228 */
11229 @Override
11230 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11231 enforceModifyPermission();
11232
joonhunshin4ac60942023-11-15 15:23:39 +000011233 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11234 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword");
11235
zoey chene02881a2019-12-30 16:11:23 +080011236 Phone phone = getPhone(subId);
11237 if (phone == null) {
11238 return 0;
11239 }
11240 // Now that all security checks passes, perform the operation as ourselves.
11241 final long identity = Binder.clearCallingIdentity();
11242 try {
11243 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11244 new Pair<String, String>(oldPassword, newPassword), phone, null);
11245 return attemptsRemaining;
11246
11247 } catch (Exception e) {
11248 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11249 } finally {
11250 Binder.restoreCallingIdentity(identity);
11251 }
11252 return 0;
11253 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011254
11255 /**
11256 * Request for receiving user activity notification
11257 */
11258 @Override
11259 public void requestUserActivityNotification() {
11260 if (!mNotifyUserActivity.get()
11261 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11262 mNotifyUserActivity.set(true);
11263 }
11264 }
11265
11266 /**
11267 * Called when userActivity is signalled in the power manager.
11268 * This is safe to call from any thread, with any window manager locks held or not.
11269 */
11270 @Override
11271 public void userActivity() {
11272 // ***************************************
11273 // * Inherited from PhoneWindowManager *
11274 // ***************************************
11275 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11276 // WITH ITS LOCKS HELD.
11277 //
11278 // This code must be VERY careful about the locks
11279 // it acquires.
11280 // In fact, the current code acquires way too many,
11281 // and probably has lurking deadlocks.
11282
11283 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11284 throw new SecurityException("Only the OS may call notifyUserActivity()");
11285 }
11286
11287 if (mNotifyUserActivity.getAndSet(false)) {
11288 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11289 USER_ACTIVITY_NOTIFICATION_DELAY);
11290 }
11291 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011292
11293 @Override
11294 public boolean canConnectTo5GInDsdsMode() {
11295 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11296 }
Jack Yud10cdd42020-09-28 20:28:01 -070011297
11298 @Override
11299 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11300 String callingFeatureId) {
11301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11302 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11303 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11304 }
11305
joonhunshin4ac60942023-11-15 15:23:39 +000011306 enforceTelephonyFeatureWithException(callingPackage,
11307 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns");
11308
Jack Yud10cdd42020-09-28 20:28:01 -070011309 Phone phone = getPhone(subId);
11310 if (phone == null) {
11311 throw new RuntimeException("phone is not available");
11312 }
11313 // Now that all security checks passes, perform the operation as ourselves.
11314 final long identity = Binder.clearCallingIdentity();
11315 try {
11316 return phone.getEquivalentHomePlmns();
11317 } finally {
11318 Binder.restoreCallingIdentity(identity);
11319 }
11320 }
Daniel Bright59e67312020-11-13 11:49:37 -080011321
11322 @Override
11323 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011324 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070011325 if (!mApp.getResources().getBoolean(
11326 com.android.internal.R.bool.config_force_phone_globals_creation)) {
11327 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11328 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
11329 "isRadioInterfaceCapabilitySupported");
11330 }
joonhunshin4ac60942023-11-15 15:23:39 +000011331
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011332 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011333 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011334 if (radioInterfaceCapabilities == null) {
11335 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011336 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011337 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011338 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011339
Hui Wang641e81c2020-10-12 12:14:23 -070011340 @Override
11341 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11342 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011343 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11344 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11345 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11346 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11347 Manifest.permission.MODIFY_PHONE_STATE);
joonhunshin4ac60942023-11-15 15:23:39 +000011348
11349 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11350 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest");
11351
Hui Wang641e81c2020-10-12 12:14:23 -070011352 if (DBG) {
11353 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11354 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11355 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11356 }
11357
11358 if (!SubscriptionManager.isValidSubscriptionId(subId)
11359 || appType < TelephonyManager.APPTYPE_UNKNOWN
11360 || appType > TelephonyManager.APPTYPE_ISIM
11361 || nafUrl == null || securityProtocol == null || callback == null) {
11362 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11363 if (callback != null) {
11364 try {
11365 callback.onAuthenticationFailure(
11366 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11367 } catch (RemoteException exception) {
11368 log("Fail to notify onAuthenticationFailure due to " + exception);
11369 }
11370 return;
11371 }
11372 }
11373
11374 final long token = Binder.clearCallingIdentity();
11375 try {
11376 getGbaManager(subId).bootstrapAuthenticationRequest(
11377 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011378 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011379 } finally {
11380 Binder.restoreCallingIdentity(token);
11381 }
11382 }
11383
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011384 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011385 * Attempts to set the radio power state for all phones for thermal reason.
11386 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011387 * requested radio power state will actually be set. See {@link
11388 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11389 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011390 * @param enable {@code true} if trying to turn radio on.
11391 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11392 * false}.
11393 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011394 private boolean setRadioPowerForThermal(boolean enable) {
11395 boolean isPhoneAvailable = false;
11396 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11397 Phone phone = PhoneFactory.getPhone(i);
11398 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011399 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011400 isPhoneAvailable = true;
11401 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011402 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011403
11404 // return true if successfully informed the phone object about the thermal radio power
11405 // request.
11406 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011407 }
11408
11409 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011410 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011411 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11412 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11413 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11414 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11415 throw new IllegalArgumentException("modem does not support data throttling");
11416 }
11417
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011418 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11419 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011420 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011421 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11422 }
11423
Sarah Chinecc78c42022-03-31 21:16:48 -070011424 setDataEnabledForReason(
11425 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011426
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011427 if (isDataThrottlingSupported) {
11428 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011429 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011430 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11431 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11432 } else if (thermalMitigationResult
11433 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011434 log("Modem likely does not support data throttling on secondary carrier. Data " +
11435 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11436 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011437 }
11438 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011439 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011440
11441 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011442 }
11443
Jack Nudelman644b91a2021-03-12 14:09:48 -080011444 private static List<String> getThermalMitigationAllowlist(Context context) {
11445 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11446 for (String pckg : context.getResources()
11447 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11448 sThermalMitigationAllowlistedPackages.add(pckg);
11449 }
11450 }
11451
11452 return sThermalMitigationAllowlistedPackages;
11453 }
11454
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011455 private boolean isAnyPhoneInEmergencyState() {
11456 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11457 if (tm.isInEmergencyCall()) {
11458 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11459 return true;
11460 }
11461 for (Phone phone : PhoneFactory.getPhones()) {
11462 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11463 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011464 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11465 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011466 return true;
11467 }
11468 }
11469
11470 return false;
11471 }
11472
Jack Nudelman644b91a2021-03-12 14:09:48 -080011473 /**
11474 * Used by shell commands to add an authorized package name for thermal mitigation.
11475 * @param packageName name of package to be allowlisted
11476 * @param context
11477 */
11478 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11479 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11480 sThermalMitigationAllowlistedPackages.add(packageName);
11481 }
11482
11483 /**
11484 * Used by shell commands to remove an authorized package name for thermal mitigation.
11485 * @param packageName name of package to remove from allowlist
11486 * @param context
11487 */
11488 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11489 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11490 sThermalMitigationAllowlistedPackages.remove(packageName);
11491 }
11492
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011493 /**
11494 * Thermal mitigation request to control functionalities at modem.
11495 *
11496 * @param subId the id of the subscription.
11497 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011498 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011499 *
11500 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11501 */
11502 @Override
11503 @ThermalMitigationResult
11504 public int sendThermalMitigationRequest(
11505 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011506 ThermalMitigationRequest thermalMitigationRequest,
11507 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011508 enforceModifyPermission();
11509
Jack Nudelman644b91a2021-03-12 14:09:48 -080011510 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
joonhunshin4ac60942023-11-15 15:23:39 +000011511
11512 enforceTelephonyFeatureWithException(callingPackage,
11513 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest");
11514
Jack Nudelman644b91a2021-03-12 14:09:48 -080011515 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11516 .contains(callingPackage)) {
11517 throw new SecurityException("Calling package must be configured in the device config. "
11518 + "calling package: " + callingPackage);
11519 }
11520
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011521 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11522 final long identity = Binder.clearCallingIdentity();
11523
11524 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11525 try {
11526 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11527 switch (thermalMitigationAction) {
11528 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11529 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011530 handleDataThrottlingRequest(subId,
11531 thermalMitigationRequest.getDataThrottlingRequest(),
11532 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011533 break;
11534 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11535 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11536 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11537 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11538 }
11539
11540 // Ensure that radio is on. If not able to power on due to phone being
11541 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011542 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011543 thermalMitigationResult =
11544 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11545 break;
11546 }
11547
11548 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011549 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011550 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11551 break;
11552 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11553 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11554 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11555 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11556 }
11557
11558 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11559 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011560 Phone phone = getPhone(subId);
11561 if (phone == null) {
11562 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011563 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011564 break;
11565 }
11566
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011567 TelephonyConnectionService service =
11568 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011569 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011570 Log.e(LOG_TAG, "An emergency call is pending");
11571 thermalMitigationResult =
11572 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11573 break;
11574 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011575 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011576 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011577 break;
11578 }
11579 } else {
11580 thermalMitigationResult =
11581 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11582 break;
11583 }
11584
11585 // Turn radio off. If not able to power off due to phone being unavailable,
11586 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011587 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011588 thermalMitigationResult =
11589 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11590 break;
11591 }
11592 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011593 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011594 break;
11595 default:
11596 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11597 + "not exist. Requested action: " + thermalMitigationAction);
11598 }
11599 } catch (IllegalArgumentException e) {
11600 throw e;
11601 } catch (Exception e) {
11602 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11603 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11604 } finally {
11605 Binder.restoreCallingIdentity(identity);
11606 }
11607
11608 if (DBG) {
11609 log("thermalMitigationRequest returning with thermalMitigationResult: "
11610 + thermalMitigationResult);
11611 }
11612
11613 return thermalMitigationResult;
11614 }
Hui Wang641e81c2020-10-12 12:14:23 -070011615
11616 /**
11617 * Set the GbaService Package Name that Telephony will bind to.
11618 *
11619 * @param subId The sim that the GbaService is associated with.
11620 * @param packageName The name of the package to be replaced with.
11621 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11622 */
11623 @Override
11624 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11625 enforceModifyPermission();
11626
11627 final long identity = Binder.clearCallingIdentity();
11628 try {
11629 return getGbaManager(subId).overrideServicePackage(packageName);
11630 } finally {
11631 Binder.restoreCallingIdentity(identity);
11632 }
11633 }
11634
11635 /**
11636 * Return the package name of the currently bound GbaService.
11637 *
11638 * @param subId The sim that the GbaService is associated with.
11639 * @return the package name of the GbaService configuration, null if GBA is not supported.
11640 */
11641 @Override
11642 public String getBoundGbaService(int subId) {
11643 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11644
11645 final long identity = Binder.clearCallingIdentity();
11646 try {
11647 return getGbaManager(subId).getServicePackage();
11648 } finally {
11649 Binder.restoreCallingIdentity(identity);
11650 }
11651 }
11652
11653 /**
11654 * Set the release time for telephony to unbind GbaService.
11655 *
11656 * @param subId The sim that the GbaService is associated with.
11657 * @param interval The release time to unbind GbaService by millisecond.
11658 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11659 */
11660 @Override
11661 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11662 enforceModifyPermission();
11663
11664 final long identity = Binder.clearCallingIdentity();
11665 try {
11666 return getGbaManager(subId).overrideReleaseTime(interval);
11667 } finally {
11668 Binder.restoreCallingIdentity(identity);
11669 }
11670 }
11671
11672 /**
11673 * Return the release time for telephony to unbind GbaService.
11674 *
11675 * @param subId The sim that the GbaService is associated with.
11676 * @return The release time to unbind GbaService by millisecond.
11677 */
11678 @Override
11679 public int getGbaReleaseTime(int subId) {
11680 enforceReadPrivilegedPermission("getGbaReleaseTime");
11681
11682 final long identity = Binder.clearCallingIdentity();
11683 try {
11684 return getGbaManager(subId).getReleaseTime();
11685 } finally {
11686 Binder.restoreCallingIdentity(identity);
11687 }
11688 }
11689
11690 private GbaManager getGbaManager(int subId) {
11691 GbaManager instance = GbaManager.getInstance(subId);
11692 if (instance == null) {
11693 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11694 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11695 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11696 }
11697 return instance;
11698 }
Hui Wang761a6682020-10-31 05:12:53 +000011699
11700 /**
11701 * indicate whether the device and the carrier can support
11702 * RCS VoLTE single registration.
11703 */
11704 @Override
11705 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011706 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11707 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11708 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11709 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011710
11711 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11712 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11713 }
11714
11715 final long identity = Binder.clearCallingIdentity();
11716 try {
11717 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11718 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011719 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11720 if (isCapable != null) {
11721 return isCapable;
11722 }
Hui Wang761a6682020-10-31 05:12:53 +000011723 }
Hui Wang67af90e2021-06-04 16:57:15 -070011724 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11725 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011726 } finally {
11727 Binder.restoreCallingIdentity(identity);
11728 }
11729 }
11730
11731 /**
11732 * Register RCS provisioning callback.
11733 */
11734 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011735 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011736 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011737 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011738 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011739 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11740 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011741
11742 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11743 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11744 }
joonhunshin4ac60942023-11-15 15:23:39 +000011745 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11746 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11747 Binder.getCallingUserHandle())) {
11748 if (!isImsAvailableOnDevice()) {
11749 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11750 "IMS not available on device.");
11751 }
11752 } else {
11753 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11754 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011755 }
11756
11757 final long identity = Binder.clearCallingIdentity();
11758 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011759 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011760 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011761 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11762 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011763 }
Hui Wang761a6682020-10-31 05:12:53 +000011764 } finally {
11765 Binder.restoreCallingIdentity(identity);
11766 }
11767 }
11768
11769 /**
11770 * Unregister RCS provisioning callback.
11771 */
11772 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011773 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011774 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011775 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011776 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011777 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11778 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011779
11780 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11781 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11782 }
joonhunshin4ac60942023-11-15 15:23:39 +000011783
11784 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11785 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11786 Binder.getCallingUserHandle())) {
11787 if (!isImsAvailableOnDevice()) {
11788 // operation failed silently
11789 Rlog.w(LOG_TAG, "IMS not available on device.");
11790 return;
11791 }
11792 } else {
11793 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11794 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION,
11795 "unregisterRcsProvisioningCallback");
Hui Wang761a6682020-10-31 05:12:53 +000011796 }
11797
11798 final long identity = Binder.clearCallingIdentity();
11799 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011800 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011801 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011802 } finally {
11803 Binder.restoreCallingIdentity(identity);
11804 }
11805 }
11806
11807 /**
11808 * trigger RCS reconfiguration.
11809 */
11810 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011811 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11812 "triggerRcsReconfiguration",
11813 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011814
11815 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11816 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11817 }
joonhunshin4ac60942023-11-15 15:23:39 +000011818 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11819 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11820 Binder.getCallingUserHandle())) {
11821 if (!isImsAvailableOnDevice()) {
11822 // ProvisioningManager can not handle ServiceSpecificException.
11823 // Throw the IllegalStateException and annotate ProvisioningManager.
11824 throw new IllegalStateException("IMS not available on device.");
11825 }
11826 } else {
11827 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11828 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011829 }
11830
11831 final long identity = Binder.clearCallingIdentity();
11832 try {
11833 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11834 } finally {
11835 Binder.restoreCallingIdentity(identity);
11836 }
11837 }
11838
11839 /**
11840 * Provide the client configuration parameters of the RCS application.
11841 */
11842 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011843 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11844 "setRcsClientConfiguration",
11845 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011846
11847 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11848 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11849 }
joonhunshin4ac60942023-11-15 15:23:39 +000011850 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
11851 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(),
11852 Binder.getCallingUserHandle())) {
11853 if (!isImsAvailableOnDevice()) {
11854 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11855 "IMS not available on device.");
11856 }
11857 } else {
11858 enforceTelephonyFeatureWithException(getCurrentPackageName(),
11859 FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration");
Hui Wang761a6682020-10-31 05:12:53 +000011860 }
11861
11862 final long identity = Binder.clearCallingIdentity();
11863
11864 try {
11865 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11866 if (configBinder == null) {
11867 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011868 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11869 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011870 } else {
11871 configBinder.setRcsClientConfiguration(rcc);
11872 }
joonhunshin3e154242021-09-17 06:33:39 +000011873
11874 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11875 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011876 } catch (RemoteException e) {
11877 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011878 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11879 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011880 } finally {
11881 Binder.restoreCallingIdentity(identity);
11882 }
11883 }
11884
11885 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011886 * Enables or disables the test mode for RCS VoLTE single registration.
11887 */
11888 @Override
11889 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11890 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11891 "setRcsSingleRegistrationTestModeEnabled");
11892
11893 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11894 }
11895
11896 /**
11897 * Gets the test mode for RCS VoLTE single registration.
11898 */
11899 @Override
11900 public boolean getRcsSingleRegistrationTestModeEnabled() {
11901 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11902 "getRcsSingleRegistrationTestModeEnabled");
11903
11904 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11905 }
11906
11907 /**
Hui Wang761a6682020-10-31 05:12:53 +000011908 * Overrides the config of RCS VoLTE single registration enabled for the device.
11909 */
11910 @Override
11911 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11912 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11913 "setDeviceSingleRegistrationEnabledOverride");
11914 enforceModifyPermission();
11915
11916 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11917 : Boolean.parseBoolean(enabledStr);
11918 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011919 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011920 }
11921
11922 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011923 * Sends a device to device communication message. Only usable via shell.
11924 * @param message message to send.
11925 * @param value message value.
11926 */
11927 @Override
11928 public void sendDeviceToDeviceMessage(int message, int value) {
11929 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011930 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011931 enforceModifyPermission();
11932
11933 final long identity = Binder.clearCallingIdentity();
11934 try {
11935 TelephonyConnectionService service =
11936 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11937 if (service == null) {
11938 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11939 return;
11940 }
11941 service.sendTestDeviceToDeviceMessage(message, value);
11942 } finally {
11943 Binder.restoreCallingIdentity(identity);
11944 }
11945 }
11946
Tyler Gunnbabbda02021-02-10 11:05:02 -080011947 /**
11948 * Sets the specified device to device transport active.
11949 * @param transport The transport to set active.
11950 */
11951 @Override
11952 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11953 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11954 "setActiveDeviceToDeviceTransport");
11955 enforceModifyPermission();
11956
11957 final long identity = Binder.clearCallingIdentity();
11958 try {
11959 TelephonyConnectionService service =
11960 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11961 if (service == null) {
11962 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11963 return;
11964 }
11965 service.setActiveDeviceToDeviceTransport(transport);
11966 } finally {
11967 Binder.restoreCallingIdentity(identity);
11968 }
11969 }
Tyler Gunn92479152021-01-20 16:30:10 -080011970
Tyler Gunnd4339262021-05-03 14:46:49 -070011971 @Override
11972 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11973 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11974 "setDeviceToDeviceForceEnabled");
11975
11976 final long identity = Binder.clearCallingIdentity();
11977 try {
11978 Arrays.stream(PhoneFactory.getPhones()).forEach(
11979 p -> {
11980 Phone thePhone = p.getImsPhone();
11981 if (thePhone != null && thePhone instanceof ImsPhone) {
11982 ImsPhone imsPhone = (ImsPhone) thePhone;
11983 CallTracker tracker = imsPhone.getCallTracker();
11984 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11985 ImsPhoneCallTracker imsPhoneCallTracker =
11986 (ImsPhoneCallTracker) tracker;
11987 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11988 }
11989 }
11990 }
11991 );
11992 } finally {
11993 Binder.restoreCallingIdentity(identity);
11994 }
11995 }
11996
Tyler Gunn92479152021-01-20 16:30:10 -080011997 /**
Hui Wang761a6682020-10-31 05:12:53 +000011998 * Gets the config of RCS VoLTE single registration enabled for the device.
11999 */
12000 @Override
12001 public boolean getDeviceSingleRegistrationEnabled() {
12002 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
12003 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
12004 }
12005
12006 /**
12007 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
12008 */
12009 @Override
12010 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
12011 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12012 "setCarrierSingleRegistrationEnabledOverride");
12013 enforceModifyPermission();
12014
12015 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12016 : Boolean.parseBoolean(enabledStr);
12017 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
12018 subId, enabled);
12019 }
12020
12021 /**
12022 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
12023 */
12024 @Override
12025 public boolean getCarrierSingleRegistrationEnabled(int subId) {
12026 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
12027 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
12028 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080012029
12030 /**
Hui Wangb647abe2021-02-26 09:33:38 -080012031 * Overrides the ims feature validation result
12032 */
12033 @Override
12034 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
12035 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12036 "setImsFeatureValidationOverride");
12037
12038 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
12039 : Boolean.parseBoolean(enabledStr);
12040 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
12041 subId, enabled);
12042 }
12043
12044 /**
12045 * Gets the ims feature validation override value
12046 */
12047 @Override
12048 public boolean getImsFeatureValidationOverride(int subId) {
12049 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12050 "getImsFeatureValidationOverride");
12051 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
12052 }
12053
12054 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080012055 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
12056 * their mobile plan.
12057 */
12058 @Override
12059 public String getMobileProvisioningUrl() {
12060 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
12061 final long identity = Binder.clearCallingIdentity();
12062 try {
12063 return getDefaultPhone().getMobileProvisioningUrl();
12064 } finally {
12065 Binder.restoreCallingIdentity(identity);
12066 }
12067 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012068
James.cf Linbcdf8b32021-01-14 16:44:13 +080012069 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080012070 * Get the EAB contact from the EAB database.
12071 */
12072 @Override
12073 public String getContactFromEab(String contact) {
12074 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
12075 enforceModifyPermission();
12076 final long identity = Binder.clearCallingIdentity();
12077 try {
12078 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
12079 } finally {
12080 Binder.restoreCallingIdentity(identity);
12081 }
12082 }
12083
12084 /**
Calvin Pana1434322021-07-01 19:27:01 +080012085 * Get the EAB capability from the EAB database.
12086 */
12087 @Override
12088 public String getCapabilityFromEab(String contact) {
12089 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
12090 enforceModifyPermission();
12091 final long identity = Binder.clearCallingIdentity();
12092 try {
12093 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
12094 } finally {
12095 Binder.restoreCallingIdentity(identity);
12096 }
12097 }
12098
12099 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080012100 * Remove the EAB contacts from the EAB database.
12101 */
12102 @Override
12103 public int removeContactFromEab(int subId, String contacts) {
12104 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
12105 enforceModifyPermission();
12106 final long identity = Binder.clearCallingIdentity();
12107 try {
12108 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
12109 } finally {
12110 Binder.restoreCallingIdentity(identity);
12111 }
12112 }
12113
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012114 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012115 public boolean getDeviceUceEnabled() {
12116 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12117 final long identity = Binder.clearCallingIdentity();
12118 try {
12119 return mApp.getDeviceUceEnabled();
12120 } finally {
12121 Binder.restoreCallingIdentity(identity);
12122 }
12123 }
12124
12125 @Override
12126 public void setDeviceUceEnabled(boolean isEnabled) {
12127 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12128 final long identity = Binder.clearCallingIdentity();
12129 try {
12130 mApp.setDeviceUceEnabled(isEnabled);
12131 } finally {
12132 Binder.restoreCallingIdentity(identity);
12133 }
12134 }
12135
Brad Ebinger14d467f2021-02-12 06:18:28 +000012136 /**
12137 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12138 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12139 */
12140 // Used for SHELL command only right now.
12141 @Override
12142 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12143 List<String> featureTags) {
12144 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12145 "addUceRegistrationOverrideShell");
12146 final long identity = Binder.clearCallingIdentity();
12147 try {
12148 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12149 new ArraySet<>(featureTags));
12150 } catch (ImsException e) {
12151 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12152 } finally {
12153 Binder.restoreCallingIdentity(identity);
12154 }
12155 }
12156
12157 /**
12158 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12159 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12160 */
12161 // Used for SHELL command only right now.
12162 @Override
12163 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12164 List<String> featureTags) {
12165 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12166 "removeUceRegistrationOverrideShell");
12167 final long identity = Binder.clearCallingIdentity();
12168 try {
12169 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12170 new ArraySet<>(featureTags));
12171 } catch (ImsException e) {
12172 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12173 } finally {
12174 Binder.restoreCallingIdentity(identity);
12175 }
12176 }
12177
12178 /**
12179 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12180 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12181 */
12182 // Used for SHELL command only right now.
12183 @Override
12184 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12185 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12186 "clearUceRegistrationOverrideShell");
12187 final long identity = Binder.clearCallingIdentity();
12188 try {
12189 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12190 } catch (ImsException e) {
12191 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12192 } finally {
12193 Binder.restoreCallingIdentity(identity);
12194 }
12195 }
12196
12197 /**
12198 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12199 */
12200 // Used for SHELL command only right now.
12201 @Override
12202 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12203 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12204 "getLatestRcsContactUceCapabilityShell");
12205 final long identity = Binder.clearCallingIdentity();
12206 try {
12207 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12208 } catch (ImsException e) {
12209 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12210 } finally {
12211 Binder.restoreCallingIdentity(identity);
12212 }
12213 }
12214
12215 /**
12216 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12217 * device does not have an active PUBLISH.
12218 */
12219 // Used for SHELL command only right now.
12220 @Override
12221 public String getLastUcePidfXmlShell(int subId) {
12222 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12223 final long identity = Binder.clearCallingIdentity();
12224 try {
12225 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12226 } catch (ImsException e) {
12227 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12228 } finally {
12229 Binder.restoreCallingIdentity(identity);
12230 }
12231 }
12232
James.cf Line8713a42021-04-29 16:04:26 +080012233 /**
12234 * Remove UCE requests cannot be sent to the network status.
12235 */
12236 // Used for SHELL command only right now.
12237 @Override
12238 public boolean removeUceRequestDisallowedStatus(int subId) {
12239 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12240 final long identity = Binder.clearCallingIdentity();
12241 try {
12242 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12243 } catch (ImsException e) {
12244 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12245 } finally {
12246 Binder.restoreCallingIdentity(identity);
12247 }
12248 }
12249
James.cf Lin18bb9002021-05-25 01:37:38 +080012250 /**
12251 * Remove UCE requests cannot be sent to the network status.
12252 */
12253 // Used for SHELL command only.
12254 @Override
12255 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12256 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12257 final long identity = Binder.clearCallingIdentity();
12258 try {
12259 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12260 } catch (ImsException e) {
12261 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12262 } finally {
12263 Binder.restoreCallingIdentity(identity);
12264 }
12265 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012266
James.cf Lin4b784aa2021-01-31 03:25:15 +080012267 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012268 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12269 String callingPackage) {
12270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12271 mApp, subId, "setSignalStrengthUpdateRequest");
12272
joonhunshin4ac60942023-11-15 15:23:39 +000012273 enforceTelephonyFeatureWithException(callingPackage,
12274 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest");
12275
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012276 final int callingUid = Binder.getCallingUid();
12277 // Verify that tha callingPackage belongs to the calling UID
12278 mApp.getSystemService(AppOpsManager.class)
12279 .checkPackage(callingUid, callingPackage);
12280
Rambo Wang3607f502021-02-01 21:51:40 -080012281 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012282
12283 final long identity = Binder.clearCallingIdentity();
12284 try {
12285 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12286 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12287
12288 if (result instanceof IllegalStateException) {
12289 throw (IllegalStateException) result;
12290 }
12291 } finally {
12292 Binder.restoreCallingIdentity(identity);
12293 }
12294 }
12295
12296 @Override
12297 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12298 String callingPackage) {
12299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12300 mApp, subId, "clearSignalStrengthUpdateRequest");
12301
joonhunshin4ac60942023-11-15 15:23:39 +000012302 enforceTelephonyFeatureWithException(callingPackage,
12303 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest");
12304
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012305 final int callingUid = Binder.getCallingUid();
12306 // Verify that tha callingPackage belongs to the calling UID
12307 mApp.getSystemService(AppOpsManager.class)
12308 .checkPackage(callingUid, callingPackage);
12309
12310 final long identity = Binder.clearCallingIdentity();
12311 try {
12312 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12313 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12314
12315 if (result instanceof IllegalStateException) {
12316 throw (IllegalStateException) result;
12317 }
12318 } finally {
12319 Binder.restoreCallingIdentity(identity);
12320 }
12321 }
12322
Rambo Wang3607f502021-02-01 21:51:40 -080012323 private static void validateSignalStrengthUpdateRequest(Context context,
12324 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wangb7a95a42024-03-07 04:57:29 +000012325 if (TelephonyPermissions.isSystemOrPhone(callingUid)) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012326 // phone/system process do not have further restriction on request
12327 return;
12328 }
12329
12330 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012331 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012332 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012333 context.enforceCallingOrSelfPermission(
12334 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12335 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012336 }
12337
12338 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012339 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012340 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012341 || info.isEnabled()) {
12342 throw new IllegalArgumentException(
12343 "Only system can set hide fields in SignalThresholdInfo");
12344 }
12345
12346 // Thresholds length for each RAN need in range. This has been validated in
12347 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12348 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12349 final int[] thresholds = info.getThresholds();
12350 Objects.requireNonNull(thresholds);
12351 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12352 || thresholds.length
12353 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12354 throw new IllegalArgumentException(
12355 "thresholds length is out of range: " + thresholds.length);
12356 }
12357 }
12358 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012359
12360 /**
12361 * Gets the current phone capability.
12362 *
12363 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12364 * @return the PhoneCapability which describes the data connection capability of modem.
12365 * It's used to evaluate possible phone config change, for example from single
12366 * SIM device to multi-SIM device.
12367 */
12368 @Override
12369 public PhoneCapability getPhoneCapability() {
12370 enforceReadPrivilegedPermission("getPhoneCapability");
joonhunshin4ac60942023-11-15 15:23:39 +000012371
12372 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12373 PackageManager.FEATURE_TELEPHONY, "getPhoneCapability");
12374
SongFerngWang8236caa2021-01-17 21:51:44 +080012375 final long identity = Binder.clearCallingIdentity();
12376 try {
12377 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12378 } finally {
12379 Binder.restoreCallingIdentity(identity);
12380 }
12381 }
Michele Berionne5e411512020-11-13 02:36:59 +000012382
12383 /**
12384 * Prepare TelephonyManager for an unattended reboot. The reboot is
12385 * required to be done shortly after the API is invoked.
12386 */
12387 @Override
12388 @TelephonyManager.PrepareUnattendedRebootResult
12389 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012390 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012391 enforceRebootPermission();
12392
joonhunshin4ac60942023-11-15 15:23:39 +000012393 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12394 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot");
12395
Michele Berionne5e411512020-11-13 02:36:59 +000012396 final long identity = Binder.clearCallingIdentity();
12397 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012398 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012399 } finally {
12400 Binder.restoreCallingIdentity(identity);
12401 }
12402 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012403
12404 /**
12405 * Request to get the current slicing configuration including URSP rules and
12406 * NSSAIs (configured, allowed and rejected).
12407 *
12408 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12409 */
12410 @Override
12411 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012412 TelephonyPermissions
12413 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12414 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012415
joonhunshin4ac60942023-11-15 15:23:39 +000012416 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12417 PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS,
12418 "getSlicingConfig");
12419
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012420 final long identity = Binder.clearCallingIdentity();
12421 try {
12422 Phone phone = getDefaultPhone();
12423 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12424 } finally {
12425 Binder.restoreCallingIdentity(identity);
12426 }
12427 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012428
12429 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012430 * Check whether the given premium capability is available for purchase from the carrier.
12431 *
12432 * @param capability The premium capability to check.
12433 * @param subId The subId to check the premium capability for.
12434 *
12435 * @return Whether the given premium capability is available to purchase.
12436 */
12437 @Override
12438 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12439 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12440 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12441 log("Premium capability "
12442 + TelephonyManager.convertPremiumCapabilityToString(capability)
12443 + " is not available for purchase due to missing permissions.");
12444 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12445 + "permission READ_BASIC_PHONE_STATE.");
12446 }
12447
joonhunshin4ac60942023-11-15 15:23:39 +000012448 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12449 PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase");
12450
Sarah Chin2ec39f62022-08-31 17:03:26 -070012451 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012452 if (phone == null) {
12453 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12454 return false;
12455 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012456 final long identity = Binder.clearCallingIdentity();
12457 try {
Sarah Chincc5446f2023-10-23 17:57:19 -070012458 return SlicePurchaseController.getInstance(phone, mFeatureFlags)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012459 .isPremiumCapabilityAvailableForPurchase(capability);
12460 } finally {
12461 Binder.restoreCallingIdentity(identity);
12462 }
12463 }
12464
12465 /**
12466 * Purchase the given premium capability from the carrier.
12467 *
12468 * @param capability The premium capability to purchase.
12469 * @param callback The result of the purchase request.
12470 * @param subId The subId to purchase the premium capability for.
12471 */
12472 @Override
12473 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12474 log("purchasePremiumCapability: capability="
12475 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12476 + getCurrentPackageName());
12477
12478 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12479 mApp, "purchasePremiumCapability")) {
12480 log("purchasePremiumCapability "
12481 + TelephonyManager.convertPremiumCapabilityToString(capability)
12482 + " failed due to missing permissions.");
12483 throw new SecurityException("purchasePremiumCapability requires permission "
12484 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012485 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12486 mApp, "purchasePremiumCapability")) {
12487 log("purchasePremiumCapability "
12488 + TelephonyManager.convertPremiumCapabilityToString(capability)
12489 + " failed due to missing permissions.");
12490 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012491 }
12492
joonhunshin4ac60942023-11-15 15:23:39 +000012493 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12494 PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability");
12495
Sarah Chin2ec39f62022-08-31 17:03:26 -070012496 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012497 if (phone == null) {
12498 try {
12499 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12500 callback.accept(result);
12501 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12502 } catch (RemoteException e) {
12503 String logStr = "Purchase premium capability "
12504 + TelephonyManager.convertPremiumCapabilityToString(capability)
12505 + " failed due to RemoteException handling null phone: " + e;
12506 if (DBG) log(logStr);
12507 AnomalyReporter.reportAnomaly(
12508 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12509 }
12510 return;
12511 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012512
12513 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012514 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012515 callingProcess = mApp.getPackageManager().getApplicationInfo(
12516 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012517 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012518 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012519 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012520
12521 boolean isVisible = false;
12522 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12523 if (am != null) {
12524 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12525 if (processes != null) {
12526 for (ActivityManager.RunningAppProcessInfo process : processes) {
12527 log("purchasePremiumCapability: process " + process.processName
Sarah Chinff8b1802023-04-11 14:22:14 -070012528 + " has importance " + process.importance);
Sarah Chin532d6bb2022-12-28 22:50:43 -080012529 if (process.processName.equals(callingProcess) && process.importance
12530 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12531 isVisible = true;
12532 break;
12533 }
12534 }
12535 }
12536 }
12537
12538 if (!isVisible) {
12539 try {
12540 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12541 callback.accept(result);
12542 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12543 } catch (RemoteException e) {
12544 String logStr = "Purchase premium capability "
12545 + TelephonyManager.convertPremiumCapabilityToString(capability)
12546 + " failed due to RemoteException handling background application: " + e;
12547 if (DBG) log(logStr);
12548 AnomalyReporter.reportAnomaly(
12549 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12550 }
12551 return;
12552 }
12553
Sarah Chin71b3a852022-09-28 15:54:19 -070012554 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012555 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012556 }
12557
12558 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012559 * Register an IMS connection state callback
12560 */
12561 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012562 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12563 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012564 if (feature == ImsFeature.FEATURE_MMTEL) {
12565 // ImsMmTelManager
12566 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12567 TelephonyPermissions
12568 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12569 mApp, subId, "registerImsStateCallback");
12570 } else if (feature == ImsFeature.FEATURE_RCS) {
12571 // ImsRcsManager or SipDelegateManager
12572 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12573 Binder.getCallingUid(), "registerImsStateCallback",
12574 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12575 Manifest.permission.READ_PRECISE_PHONE_STATE,
12576 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12577 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12578 }
12579
12580 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12581 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12582 "IMS not available on device.");
12583 }
12584
12585 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12586 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12587 }
12588
12589 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12590 if (controller == null) {
12591 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12592 "IMS not available on device.");
12593 }
12594
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012595 if (callingPackage == null) {
12596 callingPackage = getCurrentPackageName();
12597 }
12598
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012599 final long token = Binder.clearCallingIdentity();
12600 try {
12601 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012602 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012603 } catch (ImsException e) {
12604 throw new ServiceSpecificException(e.getCode());
12605 } finally {
12606 Binder.restoreCallingIdentity(token);
12607 }
12608 }
12609
12610 /**
12611 * Unregister an IMS connection state callback
12612 */
12613 @Override
12614 public void unregisterImsStateCallback(IImsStateCallback cb) {
12615 final long token = Binder.clearCallingIdentity();
12616 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12617 if (controller == null) {
12618 return;
12619 }
12620 try {
12621 controller.unregisterImsStateCallback(cb);
12622 } finally {
12623 Binder.restoreCallingIdentity(token);
12624 }
12625 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012626
12627 /**
12628 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12629 *
12630 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012631 * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012632 * SecurityException.
Pranav Madapurmath3ec71172023-12-05 23:46:25 +000012633 *
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012634 * If there is current registered network this value will be same as the registered cell
12635 * identity. If the device goes out of service the previous cell identity is cached and
12636 * will be returned. If the cache age of the Cell identity is more than 24 hours
12637 * it will be cleared and null will be returned.
12638 *
12639 */
12640 @Override
12641 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12642 String callingFeatureId) {
12643 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12644 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12645 LocationAccessPolicy.checkLocationPermission(mApp,
12646 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12647 .setCallingPackage(callingPackage)
12648 .setCallingFeatureId(callingFeatureId)
12649 .setCallingPid(Binder.getCallingPid())
12650 .setCallingUid(Binder.getCallingUid())
12651 .setMethod("getLastKnownCellIdentity")
12652 .setLogAsInfo(true)
12653 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12654 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12655 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12656 .build());
12657
12658 boolean hasFinePermission =
12659 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12660 if (!hasFinePermission
12661 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12662 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012663 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012664 }
12665
12666 final long identity = Binder.clearCallingIdentity();
12667 try {
Ling Mac28f0212023-03-24 16:07:15 -070012668 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012669 if (sst == null) return null;
12670 return sst.getLastKnownCellIdentity();
12671 } finally {
12672 Binder.restoreCallingIdentity(identity);
12673 }
12674 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012675
jimsun3b9ccac2021-10-26 15:01:23 +080012676 /**
12677 * Sets the modem service class Name that Telephony will bind to.
12678 *
12679 * @param serviceName The class name of the modem service.
12680 * @return true if the operation is succeed, otherwise false.
12681 */
12682 public boolean setModemService(String serviceName) {
12683 Log.d(LOG_TAG, "setModemService - " + serviceName);
12684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012686 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12687 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012688 return mPhoneConfigurationManager.setModemService(serviceName);
12689 }
12690
12691 /**
12692 * Return the class name of the currently bounded modem service.
12693 *
12694 * @return the class name of the modem service.
12695 */
12696 public String getModemService() {
12697 String result;
12698 Log.d(LOG_TAG, "getModemService");
12699 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12700 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012701 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012702 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12703 "getModemService");
12704 result = mPhoneConfigurationManager.getModemService();
12705 Log.d(LOG_TAG, "result = " + result);
12706 return result;
12707 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012708
Hakjun Choi3ee81112023-12-19 15:40:58 +000012709 /**
12710 * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources,
12711 * including carrier config, entitlement server, and config update.
12712 *
12713 * @param subId subId The subscription ID of the carrier.
12714 *
12715 * @return List of plmns for carrier satellite service. If no plmn is available, empty list will
12716 * be returned.
12717 *
12718 * @throws SecurityException if the caller doesn't have the required permission.
12719 */
Hakjun Choi74c16be2024-01-19 08:18:09 +000012720 @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) {
12721 enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier");
Hakjun Choi3ee81112023-12-19 15:40:58 +000012722 final long identity = Binder.clearCallingIdentity();
12723 try {
Hakjun Choi74c16be2024-01-19 08:18:09 +000012724 return mSatelliteController.getSatellitePlmnsForCarrier(subId);
Hakjun Choi3ee81112023-12-19 15:40:58 +000012725 } finally {
12726 Binder.restoreCallingIdentity(identity);
12727 }
12728 }
12729
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012730 @Override
12731 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12732 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12733 mApp.enforceCallingOrSelfPermission(
12734 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12735 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12736
12737 final long identity = Binder.clearCallingIdentity();
12738 try {
12739 Phone phone = getPhone(subId);
12740 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012741 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12742 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012743 phone.setVoiceServiceStateOverride(hasService);
12744 } finally {
12745 Binder.restoreCallingIdentity(identity);
12746 }
12747 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012748
12749 /**
12750 * set removable eSIM as default eUICC.
12751 *
12752 * @hide
12753 */
12754 @Override
12755 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12756 enforceModifyPermission();
12757 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12758
12759 final long identity = Binder.clearCallingIdentity();
12760 try {
12761 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12762 } finally {
12763 Binder.restoreCallingIdentity(identity);
12764 }
12765 }
12766
12767 /**
12768 * Returns whether the removable eSIM is default eUICC or not.
12769 *
12770 * @hide
12771 */
12772 @Override
12773 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12774 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12776
12777 final long identity = Binder.clearCallingIdentity();
12778 try {
12779 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12780 } finally {
12781 Binder.restoreCallingIdentity(identity);
12782 }
12783 }
12784
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012785 /**
12786 * Get the component name of the default app to direct respond-via-message intent for the
12787 * user associated with this subscription, update the cache if there is no respond-via-message
12788 * application currently configured for this user.
12789 * @return component name of the app and class to direct Respond Via Message intent to, or
12790 * {@code null} if the functionality is not supported.
12791 * @hide
12792 */
12793 @Override
12794 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12795 boolean updateIfNeeded) {
12796 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012797
joonhunshin4ac60942023-11-15 15:23:39 +000012798 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12799 PackageManager.FEATURE_TELEPHONY_MESSAGING,
12800 "getDefaultRespondViaMessageApplication");
12801
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012802 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12803
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012804 UserHandle userHandle = null;
12805 final long identity = Binder.clearCallingIdentity();
12806 try {
12807 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12808 } finally {
12809 Binder.restoreCallingIdentity(identity);
12810 }
12811 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12812 updateIfNeeded, userHandle);
12813 }
Jack Yuf5badd92022-12-08 00:50:53 -080012814
12815 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012816 * Set whether the device is able to connect with null ciphering or integrity
12817 * algorithms. This is a global setting and will apply to all active subscriptions
12818 * and all new subscriptions after this.
12819 *
12820 * @param enabled when true, null cipher and integrity algorithms are allowed.
12821 * @hide
12822 */
12823 @Override
12824 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12825 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12826 enforceModifyPermission();
12827 checkForNullCipherAndIntegritySupport();
12828
12829 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12830 // for listening to these preference changes and applying them immediately.
12831 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12832 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12833 editor.apply();
12834
12835 for (Phone phone: PhoneFactory.getPhones()) {
12836 phone.handleNullCipherEnabledChange();
12837 }
12838 }
12839
12840
12841 /**
12842 * Get whether the device is able to connect with null ciphering or integrity
12843 * algorithms. Note that this retrieves the phone-global preference and not
12844 * the state of the radio.
12845 *
12846 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12847 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12848 * version for this feature.
12849 * @hide
12850 */
12851 @Override
12852 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12853 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12854 enforceReadPermission();
12855 checkForNullCipherAndIntegritySupport();
12856 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12857 }
12858
12859 private void checkForNullCipherAndIntegritySupport() {
12860 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12861 throw new UnsupportedOperationException(
12862 "Null cipher and integrity operations require HAL 2.1 or above");
12863 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012864 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12865 throw new UnsupportedOperationException(
12866 "Null cipher and integrity operations unsupported by modem");
12867 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012868 }
12869
Gil Cukierman06403e12023-11-29 16:33:03 +000012870 private void checkForIdentifierDisclosureNotificationSupport() {
12871 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) {
12872 throw new UnsupportedOperationException(
12873 "Cellular identifier disclosure transparency operations require HAL 2.2 or "
12874 + "above");
12875 }
12876 if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) {
12877 throw new UnsupportedOperationException(
12878 "Cellular identifier disclosure transparency operations unsupported by modem");
12879 }
12880 }
12881
Michael Groover826b71d2023-12-21 22:08:06 -060012882 private void checkForNullCipherNotificationSupport() {
12883 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) {
12884 throw new UnsupportedOperationException(
12885 "Null cipher notification operations require HAL 2.2 or above");
12886 }
12887 if (!getDefaultPhone().isNullCipherNotificationSupported()) {
12888 throw new UnsupportedOperationException(
12889 "Null cipher notification operations unsupported by modem");
12890 }
12891 }
12892
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012893 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012894 * Get the SIM state for the slot index.
12895 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12896 *
12897 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12898 */
12899 @Override
12900 @SimState
12901 public int getSimStateForSlotIndex(int slotIndex) {
Tomasz Wasilczyk751bb1b2024-06-04 12:03:46 -070012902 if (!mApp.getResources().getBoolean(
12903 com.android.internal.R.bool.config_force_phone_globals_creation)) {
12904 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12905 PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex");
12906 }
joonhunshin4ac60942023-11-15 15:23:39 +000012907
Jack Yuf5badd92022-12-08 00:50:53 -080012908 IccCardConstants.State simState;
12909 if (slotIndex < 0) {
12910 simState = IccCardConstants.State.UNKNOWN;
12911 } else {
12912 Phone phone = null;
12913 try {
12914 phone = PhoneFactory.getPhone(slotIndex);
12915 } catch (IllegalStateException e) {
12916 // ignore
12917 }
12918 if (phone == null) {
12919 simState = IccCardConstants.State.UNKNOWN;
12920 } else {
12921 IccCard icc = phone.getIccCard();
12922 if (icc == null) {
12923 simState = IccCardConstants.State.UNKNOWN;
12924 } else {
12925 simState = icc.getState();
12926 }
12927 }
12928 }
12929 return simState.ordinal();
12930 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012931
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012932 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12933 boolean enableLogcat,
12934 long logcatStartTimestampMillis, boolean enableTelecomDump,
12935 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012936 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012937 TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder =
12938 new TelephonyManager.EmergencyCallDiagnosticData.Builder();
12939 ecdDataBuilder
12940 .setTelecomDumpsysCollectionEnabled(enableTelecomDump)
12941 .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012942 if (enableLogcat) {
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012943 ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis);
Pranav Madapurmathef6eeec2023-12-14 16:42:42 -080012944 }
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012945 TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build();
12946 Log.d(LOG_TAG, "persisting with Params " + ecdData.toString());
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012947 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12948 Executors.newCachedThreadPool(), db,
12949 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012950 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012951 }
12952
12953 /**
12954 * Request telephony to persist state for debugging emergency call failures.
12955 *
Pranav Madapurmath8883dbc2024-02-01 10:22:25 -080012956 * @param dropboxTag Tag to use when persisting data to dropbox service.
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012957 * @param enableLogcat whether to collect logcat output
12958 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12959 * @param enableTelecomDump whether to collect telecom dumpsys
12960 * @param enableTelephonyDump whether to collect telephony dumpsys
12961 */
12962 @Override
12963 @RequiresPermission(android.Manifest.permission.DUMP)
12964 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12965 long logcatStartTimestampMillis, boolean enableTelecomDump,
12966 boolean enableTelephonyDump) {
Pranav Madapurmath1767aaf2024-03-05 13:13:52 -080012967 // Verify that the caller has READ_DROPBOX_DATA permission.
12968 if (mTelecomFeatureFlags.telecomResolveHiddenDependencies()
12969 && Flags.enableReadDropboxPermission()) {
12970 mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA,
12971 "persistEmergencyCallDiagnosticData");
12972 } else {
12973 // Otherwise, enforce legacy permission.
12974 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12975 "persistEmergencyCallDiagnosticData");
12976 }
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012977 final long identity = Binder.clearCallingIdentity();
12978 try {
12979 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12980 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12981
12982 } finally {
12983 Binder.restoreCallingIdentity(identity);
12984 }
12985 }
12986
Hui Wang9b5793a2022-12-05 14:38:06 -060012987 /**
12988 * Get current cell broadcast ranges.
12989 */
12990 @Override
12991 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12992 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12993 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12994 "getCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000012995
12996 enforceTelephonyFeatureWithException(getCurrentPackageName(),
12997 PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges");
12998
Hui Wang9b5793a2022-12-05 14:38:06 -060012999 final long identity = Binder.clearCallingIdentity();
13000 try {
13001 return getPhone(subId).getCellBroadcastIdRanges();
13002 } finally {
13003 Binder.restoreCallingIdentity(identity);
13004 }
13005 }
13006
13007 /**
13008 * Set reception of cell broadcast messages with the list of the given ranges
13009 *
13010 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
13011 */
13012 @Override
13013 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
13014 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
13015 @Nullable IIntegerConsumer callback) {
13016 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
13017 "setCellBroadcastIdRanges");
joonhunshin4ac60942023-11-15 15:23:39 +000013018
13019 enforceTelephonyFeatureWithException(getCurrentPackageName(),
13020 PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges");
13021
Hui Wang9b5793a2022-12-05 14:38:06 -060013022 final long identity = Binder.clearCallingIdentity();
13023 try {
13024 Phone phone = getPhoneFromSubId(subId);
13025 if (DBG) {
13026 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
13027 }
13028 phone.setCellBroadcastIdRanges(ranges, result -> {
13029 if (callback != null) {
13030 try {
13031 callback.accept(result);
13032 } catch (RemoteException e) {
13033 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
13034 }
13035 }
13036 });
13037 } finally {
13038 Binder.restoreCallingIdentity(identity);
13039 }
13040 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000013041
13042 /**
13043 * Returns whether the device supports the domain selection service.
13044 *
13045 * @return {@code true} if the device supports the domain selection service.
13046 */
13047 @Override
13048 public boolean isDomainSelectionSupported() {
13049 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13050 "isDomainSelectionSupported");
13051
13052 final long identity = Binder.clearCallingIdentity();
13053 try {
13054 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
13055 } finally {
13056 Binder.restoreCallingIdentity(identity);
13057 }
13058 }
arunvoddud5c6ce02022-12-11 06:03:12 +000013059
13060 /**
Hunsuk Choi9c69a802024-04-11 20:39:23 +000013061 * Returns whether the AOSP domain selection service is supported.
13062 *
13063 * @return {@code true} if the AOSP domain selection service is supported,
13064 * {@code false} otherwise.
13065 */
13066 @Override
13067 public boolean isAospDomainSelectionService() {
13068 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
13069 "isAospDomainSelectionService");
13070
13071 final long identity = Binder.clearCallingIdentity();
13072 try {
13073 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
13074 String dssComponentName = mApp.getResources().getString(
13075 R.string.config_domain_selection_service_component_name);
13076 ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(),
13077 TelephonyDomainSelectionService.class.getName());
13078 Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName
13079 + ", aosp=" + componentName.flattenToString());
13080 return TextUtils.equals(componentName.flattenToString(), dssComponentName);
13081 }
13082 } finally {
13083 Binder.restoreCallingIdentity(identity);
13084 }
13085 return false;
13086 }
13087
13088 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013089 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
13090 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
13091 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080013092 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013093 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080013094 * @param enableSatellite {@code true} to enable the satellite modem and
13095 * {@code false} to disable.
13096 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
Thomas Nguyena8062672024-02-05 14:18:19 -080013097 * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise.
Sarah Chinabf081b2023-03-09 23:00:57 -080013098 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080013099 *
13100 * @throws SecurityException if the caller doesn't have the required permission.
13101 */
13102 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013103 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
Thomas Nguyena8062672024-02-05 14:18:19 -080013104 boolean isEmergency, @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013105 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013106 if (enableSatellite) {
13107 ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) {
13108 @Override
13109 protected void onReceiveResult(int resultCode, Bundle resultData) {
13110 Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode
13111 + ", resultData=" + resultData);
13112 boolean isAllowed = false;
13113 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(
13114 callback::accept);
13115 if (resultCode == SATELLITE_RESULT_SUCCESS) {
13116 if (resultData != null
13117 && resultData.containsKey(KEY_SATELLITE_COMMUNICATION_ALLOWED)) {
13118 isAllowed = resultData.getBoolean(KEY_SATELLITE_COMMUNICATION_ALLOWED);
13119 } else {
13120 loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist.");
13121 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013122 } else {
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013123 result.accept(resultCode);
13124 return;
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013125 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013126 if (isAllowed) {
13127 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013128 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013129 } else {
13130 result.accept(SATELLITE_RESULT_ACCESS_BARRED);
13131 }
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013132 }
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013133 };
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013134 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013135 subId, resultReceiver);
13136 } else {
13137 // No need to check if satellite is allowed at current location when disabling satellite
13138 mSatelliteController.requestSatelliteEnabled(
Hyosun Kimab304792024-03-29 09:18:03 +000013139 subId, enableSatellite, enableDemoMode, isEmergency, callback);
Thomas Nguyen060f5e02024-01-24 16:44:50 -080013140 }
Sarah Chin503828c2023-02-01 23:54:20 -080013141 }
13142
13143 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013144 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080013145 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013146 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013147 * @param result The result receiver that returns whether the satellite modem is enabled
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 the required permission.
13151 */
13152 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013153 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
13154 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013155 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013156 }
13157
13158 /**
Sarah Chin43457982023-02-15 17:50:38 -080013159 * Request to get whether the satellite service demo mode is enabled.
13160 *
13161 * @param subId The subId of the subscription to check whether the satellite demo mode
13162 * is enabled for.
13163 * @param result The result receiver that returns whether the satellite demo mode is enabled
13164 * if the request is successful or an error code if the request failed.
13165 *
13166 * @throws SecurityException if the caller doesn't have the required permission.
13167 */
13168 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013169 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
13170 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
13171 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080013172 }
13173
13174 /**
Thomas Nguyena8062672024-02-05 14:18:19 -080013175 * Request to get whether the satellite service is enabled with emergency mode.
13176 *
13177 * @param subId The subId of the subscription to check whether the satellite demo mode
13178 * is enabled for.
13179 * @param result The result receiver that returns whether the satellite emergency mode is
13180 * enabled if the request is successful or an error code if the request failed.
13181 *
13182 * @throws SecurityException if the caller doesn't have the required permission.
13183 */
13184 @Override
13185 public void requestIsEmergencyModeEnabled(int subId, @NonNull ResultReceiver result) {
13186 enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled");
13187 result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
13188 }
13189
13190 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013191 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080013192 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013193 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013194 * @param result The result receiver that returns whether the satellite service is supported on
13195 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013196 */
13197 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013198 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013199 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013200 }
13201
13202 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013203 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080013204 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013205 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013206 * @param result The result receiver that returns the {@link SatelliteCapabilities}
13207 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080013208 *
13209 * @throws SecurityException if the caller doesn't have required permission.
13210 */
13211 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013212 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
13213 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013214 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080013215 }
13216
13217 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013218 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013219 * This can be called by the pointing UI when the user starts pointing to the satellite.
13220 * Modem should continue to report the pointing input as the device or satellite moves.
13221 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013222 * @param subId The subId of the subscription to start satellite transmission updates for.
13223 * @param resultCallback The callback to get the result of the request.
13224 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080013225 *
13226 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013227 */
13228 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013229 public void startSatelliteTransmissionUpdates(int subId,
13230 @NonNull IIntegerConsumer resultCallback,
13231 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13232 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
13233 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080013234 }
13235
13236 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080013237 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080013238 * This can be called by the pointing UI when the user stops pointing to the satellite.
13239 *
Sarah Chinabf081b2023-03-09 23:00:57 -080013240 * @param subId The subId of the subscription to stop satellite transmission updates for.
13241 * @param resultCallback The callback to get the result of the request.
13242 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
13243 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080013244 *
13245 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080013246 */
13247 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080013248 public void stopSatelliteTransmissionUpdates(int subId,
13249 @NonNull IIntegerConsumer resultCallback,
13250 @NonNull ISatelliteTransmissionUpdateCallback callback) {
13251 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
13252 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013253 }
13254
13255 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013256 * Register the subscription with a satellite provider.
13257 * This is needed to register the subscription if the provider allows dynamic registration.
13258 *
13259 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013260 * @param token The token to be used as a unique identifier for provisioning with satellite
13261 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013262 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080013263 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013264 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013265 * @return The signal transport used by the caller to cancel the provision request,
13266 * or {@code null} if the request failed.
13267 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013268 * @throws SecurityException if the caller doesn't have the required permission.
13269 */
13270 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013271 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013272 @NonNull String token, @NonNull byte[] provisionData,
13273 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013274 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000013275 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
13276 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013277 }
13278
13279 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013280 * Unregister the device/subscription with the satellite provider.
13281 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013282 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013283 * should report as deprovisioned.
13284 *
13285 * @param subId The subId of the subscription to be deprovisioned.
13286 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080013287 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013288 *
13289 * @throws SecurityException if the caller doesn't have the required permission.
13290 */
13291 @Override
13292 public void deprovisionSatelliteService(int subId,
13293 @NonNull String token, @NonNull IIntegerConsumer callback) {
13294 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013295 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013296 }
13297
13298 /**
Sarah Chin43457982023-02-15 17:50:38 -080013299 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013300 *
Sarah Chin43457982023-02-15 17:50:38 -080013301 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013302 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013303 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013304 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013305 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013306 * @throws SecurityException if the caller doesn't have the required permission.
13307 */
13308 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013309 @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged(
13310 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013311 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013312 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013313 }
13314
13315 /**
Sarah Chin43457982023-02-15 17:50:38 -080013316 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013317 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013318 *
Sarah Chin43457982023-02-15 17:50:38 -080013319 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013320 * @param callback The callback that was passed to
13321 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013322 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013323 * @throws SecurityException if the caller doesn't have the required permission.
13324 */
13325 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013326 public void unregisterForSatelliteProvisionStateChanged(
13327 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013328 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013329 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013330 }
13331
13332 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013333 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013334 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013335 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013336 * @param result The result receiver that returns whether the device is provisioned with a
13337 * satellite provider if the request is successful or an error code if the
13338 * request failed.
13339 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013340 * @throws SecurityException if the caller doesn't have the required permission.
13341 */
13342 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013343 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13344 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013345 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013346 }
13347
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013348 /**
Sarah Chin43457982023-02-15 17:50:38 -080013349 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013350 *
Sarah Chin43457982023-02-15 17:50:38 -080013351 * @param subId The subId of the subscription to register for satellite modem state changed.
13352 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013353 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013354 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013355 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013356 * @throws SecurityException if the caller doesn't have the required permission.
13357 */
13358 @Override
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013359 @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013360 @NonNull ISatelliteModemStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080013361 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013362 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013363 }
13364
13365 /**
Sarah Chin43457982023-02-15 17:50:38 -080013366 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013367 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013368 *
Sarah Chin43457982023-02-15 17:50:38 -080013369 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080013370 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013371 * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013372 *
13373 * @throws SecurityException if the caller doesn't have the required permission.
13374 */
13375 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013376 public void unregisterForModemStateChanged(int subId,
Hakjun Choid4a52a22023-12-13 09:48:24 +000013377 @NonNull ISatelliteModemStateCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013378 enforceSatelliteCommunicationPermission("unregisterForModemStateChanged");
13379 mSatelliteController.unregisterForModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013380 }
13381
13382 /**
13383 * Register to receive incoming datagrams over satellite.
13384 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013385 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080013386 * @param callback The callback to handle incoming datagrams over satellite.
13387 *
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013388 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
Sarah Chindf715ec2023-02-13 13:46:24 -080013389 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013390 * @throws SecurityException if the caller doesn't have the required permission.
13391 */
13392 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013393 @SatelliteManager.SatelliteResult public int registerForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013394 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013395 enforceSatelliteCommunicationPermission("registerForIncomingDatagram");
13396 return mSatelliteController.registerForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013397 }
13398
13399 /**
13400 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013401 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013402 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013403 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13404 * @param callback The callback that was passed to
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013405 * {@link #registerForIncomingDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013406 *
13407 * @throws SecurityException if the caller doesn't have the required permission.
13408 */
13409 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013410 public void unregisterForIncomingDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080013411 @NonNull ISatelliteDatagramCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013412 enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram");
13413 mSatelliteController.unregisterForIncomingDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013414 }
13415
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013416 /**
13417 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013418 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013419 * This method requests modem to check if there are any pending datagrams to be received over
13420 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati0a78dfb2023-03-28 20:29:26 +000013421 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080013422 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013423 * @param subId The subId of the subscription used for receiving datagrams.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013424 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013425 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013426 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013427 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013428 public void pollPendingDatagrams(int subId, IIntegerConsumer callback) {
13429 enforceSatelliteCommunicationPermission("pollPendingDatagrams");
13430 mSatelliteController.pollPendingDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013431 }
13432
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013433 /**
13434 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013435 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000013436 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
13437 * input to this method. Datagram received here will be passed down to modem without any
13438 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013439 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013440 * @param subId The subId of the subscription to send satellite datagrams for.
13441 * @param datagramType datagram type indicating whether the datagram is of type
13442 * SOS_SMS or LOCATION_SHARING.
13443 * @param datagram encoded gateway datagram which is encrypted by the caller.
13444 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000013445 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
13446 * full screen mode.
Aishwarya Mallamapti1fd18f32023-08-25 00:23:13 +000013447 * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013448 *
13449 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013450 */
13451 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013452 public void sendDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000013453 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
13454 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013455 enforceSatelliteCommunicationPermission("sendDatagram");
13456 mSatelliteController.sendDatagram(subId, datagramType, datagram, needFullScreenPointingUI,
13457 callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013458 }
13459
Sarah Chindf715ec2023-02-13 13:46:24 -080013460 /**
13461 * Request to get whether satellite communication is allowed for the current location.
13462 *
13463 * @param subId The subId of the subscription to check whether satellite communication is
13464 * allowed for the current location for.
13465 * @param result The result receiver that returns whether satellite communication is allowed
13466 * for the current location if the request is successful or an error code
13467 * if the request failed.
13468 *
13469 * @throws SecurityException if the caller doesn't have the required permission.
13470 */
13471 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013472 public void requestIsCommunicationAllowedForCurrentLocation(int subId,
Sarah Chindf715ec2023-02-13 13:46:24 -080013473 @NonNull ResultReceiver result) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013474 enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation");
13475 mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(subId,
13476 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080013477 }
13478
13479 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013480 * Request to get the time after which the satellite will be visible.
Sarah Chindf715ec2023-02-13 13:46:24 -080013481 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013482 * @param subId The subId to get the time after which the satellite will be visible for.
13483 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013484 * be visible if the request is successful or an error code if the request failed.
13485 *
13486 * @throws SecurityException if the caller doesn't have the required permission.
13487 */
13488 @Override
13489 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13490 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000013491 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013492 }
13493
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013494 /**
Hakjun Choiae365972023-04-25 11:00:31 +000013495 * Inform that Device is aligned to satellite for demo mode.
13496 *
13497 * @param subId The subId to get the time after which the satellite will be visible for.
13498 * @param isAligned {@code true} Device is aligned with the satellite for demo mode
13499 * {@code false} Device fails to align with the satellite for demo mode.
13500 *
13501 * @throws SecurityException if the caller doesn't have required permission.
13502 */
13503 @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
13504
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013505 public void setDeviceAlignedWithSatellite(int subId, @NonNull boolean isAligned) {
Hakjun Choiae365972023-04-25 11:00:31 +000013506 enforceSatelliteCommunicationPermission("informDeviceAlignedToSatellite");
Aishwarya Mallamapti697af852023-08-11 00:21:10 +000013507 mSatelliteController.setDeviceAlignedWithSatellite(subId, isAligned);
Hakjun Choiae365972023-04-25 11:00:31 +000013508 }
13509
13510 /**
Hakjun Choicb39db92023-07-14 15:51:12 +000013511 * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach
13512 * by modem.
13513 *
13514 * @param subId The subId of the subscription to request for.
13515 * @param reason Reason for disallowing satellite communication for carrier.
Hakjun Choif92ac752024-03-18 19:34:29 +000013516 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013517 * operation.
13518 *
13519 * @throws SecurityException if the caller doesn't have required permission.
13520 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013521 public void addAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013522 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13523 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013524 enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013525 final long identity = Binder.clearCallingIdentity();
13526 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013527 mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013528 } finally {
13529 Binder.restoreCallingIdentity(identity);
13530 }
13531 }
13532
13533 /**
13534 * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach
13535 * by modem.
13536 *
13537 * @param subId The subId of the subscription to request for.
13538 * @param reason Reason for disallowing satellite communication.
Hakjun Choif92ac752024-03-18 19:34:29 +000013539 * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the
Hakjun Choicb39db92023-07-14 15:51:12 +000013540 * operation.
13541 *
13542 * @throws SecurityException if the caller doesn't have required permission.
13543 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013544 public void removeAttachRestrictionForCarrier(int subId,
Hakjun Choicb39db92023-07-14 15:51:12 +000013545 @SatelliteManager.SatelliteCommunicationRestrictionReason int reason,
13546 @NonNull IIntegerConsumer callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013547 enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013548 final long identity = Binder.clearCallingIdentity();
13549 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013550 mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback);
Hakjun Choicb39db92023-07-14 15:51:12 +000013551 } finally {
13552 Binder.restoreCallingIdentity(identity);
13553 }
13554 }
13555
13556 /**
13557 * Get reasons for disallowing satellite communication, as requested by
Hakjun Choif92ac752024-03-18 19:34:29 +000013558 * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}.
Hakjun Choicb39db92023-07-14 15:51:12 +000013559 *
13560 * @param subId The subId of the subscription to request for.
13561 *
13562 * @return Integer array of reasons for disallowing satellite communication.
13563 *
13564 * @throws SecurityException if the caller doesn't have the required permission.
13565 */
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013566 public @NonNull int[] getAttachRestrictionReasonsForCarrier(
Hakjun Choicb39db92023-07-14 15:51:12 +000013567 int subId) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013568 enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier");
Hakjun Choicb39db92023-07-14 15:51:12 +000013569 final long identity = Binder.clearCallingIdentity();
13570 try {
13571 Set<Integer> reasonSet =
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013572 mSatelliteController.getAttachRestrictionReasonsForCarrier(subId);
Hakjun Choicb39db92023-07-14 15:51:12 +000013573 return reasonSet.stream().mapToInt(i->i).toArray();
13574 } finally {
13575 Binder.restoreCallingIdentity(identity);
13576 }
13577 }
13578
13579 /**
Hakjun Choifa3e6172023-09-22 03:56:34 +000013580 * Request to get the signal strength of the satellite connection.
13581 *
13582 * @param subId The subId of the subscription to request for.
13583 * @param result Result receiver to get the error code of the request and the current signal
13584 * strength of the satellite connection.
13585 *
13586 * @throws SecurityException if the caller doesn't have required permission.
13587 */
13588 @Override
13589 public void requestNtnSignalStrength(int subId, @NonNull ResultReceiver result) {
13590 enforceSatelliteCommunicationPermission("requestNtnSignalStrength");
13591 final long identity = Binder.clearCallingIdentity();
13592 try {
13593 mSatelliteController.requestNtnSignalStrength(subId, result);
13594 } finally {
13595 Binder.restoreCallingIdentity(identity);
13596 }
13597 }
13598
13599 /**
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013600 * Registers for NTN signal strength changed from satellite modem. If the registration operation
13601 * is not successful, a {@link ServiceSpecificException} that contains
13602 * {@link SatelliteManager.SatelliteResult} will be thrown.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013603 *
13604 * @param subId The subId of the subscription to request for.
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013605 * @param callback The callback to handle the NTN signal strength changed event. If the
13606 * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged(
13607 * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of
13608 * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial
13609 * network has changed.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013610 *
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013611 * @throws SecurityException If the caller doesn't have the required permission.
13612 * @throws ServiceSpecificException If the callback registration operation fails.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013613 */
13614 @Override
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013615 public void registerForNtnSignalStrengthChanged(int subId,
13616 @NonNull INtnSignalStrengthCallback callback) throws RemoteException {
Hakjun Choifa3e6172023-09-22 03:56:34 +000013617 enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged");
13618 final long identity = Binder.clearCallingIdentity();
13619 try {
Hakjun Choi4c3668a2023-12-05 11:55:36 +000013620 mSatelliteController.registerForNtnSignalStrengthChanged(subId, callback);
Hakjun Choifa3e6172023-09-22 03:56:34 +000013621 } finally {
13622 Binder.restoreCallingIdentity(identity);
13623 }
13624 }
13625
13626 /**
13627 * Unregisters for NTN signal strength changed from satellite modem.
13628 * If callback was not registered before, the request will be ignored.
13629 *
Hakjun Choi8d96a562023-10-26 15:01:40 +000013630 * @param subId The subId of the subscription to unregister for listening NTN signal strength
13631 * changed event.
Hakjun Choifa3e6172023-09-22 03:56:34 +000013632 * @param callback The callback that was passed to
13633 * {@link #registerForNtnSignalStrengthChanged(int, INtnSignalStrengthCallback)}
13634 *
13635 * @throws SecurityException if the caller doesn't have the required permission.
13636 */
13637 @Override
13638 public void unregisterForNtnSignalStrengthChanged(
13639 int subId, @NonNull INtnSignalStrengthCallback callback) {
13640 enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged");
13641 final long identity = Binder.clearCallingIdentity();
13642 try {
13643 mSatelliteController.unregisterForNtnSignalStrengthChanged(subId, callback);
13644 } finally {
13645 Binder.restoreCallingIdentity(identity);
13646 }
13647 }
13648
13649 /**
Hakjun Choi8d96a562023-10-26 15:01:40 +000013650 * Registers for satellite capabilities change event from the satellite service.
13651 *
13652 * @param subId The subId of the subscription to request for.
13653 * @param callback The callback to handle the satellite capabilities changed event.
13654 *
13655 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13656 *
13657 * @throws SecurityException if the caller doesn't have required permission.
13658 */
13659 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013660 @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged(
Hakjun Choi8d96a562023-10-26 15:01:40 +000013661 int subId, @NonNull ISatelliteCapabilitiesCallback callback) {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013662 enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013663 final long identity = Binder.clearCallingIdentity();
13664 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013665 return mSatelliteController.registerForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013666 } finally {
13667 Binder.restoreCallingIdentity(identity);
13668 }
13669 }
13670
13671 /**
13672 * Unregisters for satellite capabilities change event from the satellite service.
13673 * If callback was not registered before, the request will be ignored.
13674 *
13675 * @param subId The subId of the subscription to unregister for satellite capabilities change.
13676 * @param callback The callback that was passed to.
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013677 * {@link #registerForCapabilitiesChanged(int, ISatelliteCapabilitiesCallback)}.
Hakjun Choi8d96a562023-10-26 15:01:40 +000013678 *
13679 * @throws SecurityException if the caller doesn't have required permission.
13680 */
13681 @Override
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013682 public void unregisterForCapabilitiesChanged(int subId,
13683 @NonNull ISatelliteCapabilitiesCallback callback) {
13684 enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged");
Hakjun Choi8d96a562023-10-26 15:01:40 +000013685 final long identity = Binder.clearCallingIdentity();
13686 try {
Hakjun Choi3c9303b2023-12-21 06:37:41 +000013687 mSatelliteController.unregisterForCapabilitiesChanged(subId, callback);
Hakjun Choi8d96a562023-10-26 15:01:40 +000013688 } finally {
13689 Binder.restoreCallingIdentity(identity);
13690 }
13691 }
13692
13693 /**
Hakjun Choif92ac752024-03-18 19:34:29 +000013694 * Registers for the satellite supported state changed.
13695 *
13696 * @param subId The subId of the subscription to register for supported state changed.
13697 * @param callback The callback to handle the satellite supported state changed event.
13698 *
13699 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
13700 *
13701 * @throws SecurityException if the caller doesn't have the required permission.
13702 */
13703 @Override
13704 @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged(
13705 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13706 enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged");
13707 return mSatelliteController.registerForSatelliteSupportedStateChanged(subId, callback);
13708 }
13709
13710 /**
13711 * Unregisters for the satellite supported state changed.
13712 * If callback was not registered before, the request will be ignored.
13713 *
13714 * @param subId The subId of the subscription to unregister for supported state changed.
13715 * @param callback The callback that was passed to
13716 * {@link #registerForSatelliteSupportedStateChanged(int, ISatelliteSupportedStateCallback)}.
13717 *
13718 * @throws SecurityException if the caller doesn't have the required permission.
13719 */
13720 @Override
13721 public void unregisterForSatelliteSupportedStateChanged(
13722 int subId, @NonNull ISatelliteSupportedStateCallback callback) {
13723 enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged");
13724 mSatelliteController.unregisterForSatelliteSupportedStateChanged(subId, callback);
13725 }
13726
13727 /**
Thomas Nguyend34a5fc2023-03-23 21:07:03 -070013728 * This API can be used by only CTS to update satellite vendor service package name.
13729 *
13730 * @param servicePackageName The package name of the satellite vendor service.
13731 * @return {@code true} if the satellite vendor service is set successfully,
13732 * {@code false} otherwise.
13733 */
13734 public boolean setSatelliteServicePackageName(String servicePackageName) {
13735 Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName);
13736 TelephonyPermissions.enforceShellOnly(
13737 Binder.getCallingUid(), "setSatelliteServicePackageName");
13738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13739 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13740 "setSatelliteServicePackageName");
13741 return mSatelliteController.setSatelliteServicePackageName(servicePackageName);
13742 }
13743
13744 /**
Thomas Nguyen1854a5a2023-04-04 09:31:47 -070013745 * This API can be used by only CTS to update satellite gateway service package name.
13746 *
13747 * @param servicePackageName The package name of the satellite gateway service.
13748 * @return {@code true} if the satellite gateway service is set successfully,
13749 * {@code false} otherwise.
13750 */
13751 public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) {
13752 Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName);
13753 TelephonyPermissions.enforceShellOnly(
13754 Binder.getCallingUid(), "setSatelliteGatewayServicePackageName");
13755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13756 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13757 "setSatelliteGatewayServicePackageName");
13758 return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName);
13759 }
13760
13761 /**
Thomas Nguyen87dce732023-04-20 18:27:16 -070013762 * This API can be used by only CTS to update satellite pointing UI app package and class names.
13763 *
13764 * @param packageName The package name of the satellite pointing UI app.
13765 * @param className The class name of the satellite pointing UI app.
13766 * @return {@code true} if the satellite pointing UI app package and class is set successfully,
13767 * {@code false} otherwise.
13768 */
13769 public boolean setSatellitePointingUiClassName(
13770 @Nullable String packageName, @Nullable String className) {
13771 Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName
13772 + ", className=" + className);
13773 TelephonyPermissions.enforceShellOnly(
13774 Binder.getCallingUid(), "setSatellitePointingUiClassName");
13775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13776 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13777 "setSatelliteGatewayServicePackageName");
13778 return mSatelliteController.setSatellitePointingUiClassName(packageName, className);
13779 }
13780
13781 /**
Thomas Nguyenf9a533c2023-04-06 20:48:41 -070013782 * This API can be used by only CTS to update the timeout duration in milliseconds that
13783 * satellite should stay at listening mode to wait for the next incoming page before disabling
13784 * listening mode.
13785 *
13786 * @param timeoutMillis The timeout duration in millisecond.
13787 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13788 */
13789 public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) {
13790 Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis);
13791 TelephonyPermissions.enforceShellOnly(
13792 Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration");
13793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13794 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13795 "setSatelliteListeningTimeoutDuration");
13796 return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis);
13797 }
13798
13799 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013800 * This API can be used by only CTS to override the timeout durations used by the
13801 * DatagramController module.
Hakjun Choiae365972023-04-25 11:00:31 +000013802 *
13803 * @param timeoutMillis The timeout duration in millisecond.
13804 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13805 */
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013806 public boolean setDatagramControllerTimeoutDuration(
13807 boolean reset, int timeoutType, long timeoutMillis) {
13808 Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
13809 + reset + ", timeoutMillis=" + timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013810 TelephonyPermissions.enforceShellOnly(
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013811 Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
Hakjun Choiae365972023-04-25 11:00:31 +000013812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13813 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013814 "setDatagramControllerTimeoutDuration");
13815 return mSatelliteController.setDatagramControllerTimeoutDuration(
13816 reset, timeoutType, timeoutMillis);
13817 }
13818
13819 /**
Aishwarya Mallampati3f0ef9b2024-05-17 22:47:04 +000013820 * This API can be used by only CTS to override the boolean configs used by the
13821 * DatagramController module.
13822 *
13823 * @param enable Whether to enable or disable boolean config.
13824 * @return {@code true} if the boolean config is set successfully, {@code false} otherwise.
13825 */
13826 public boolean setDatagramControllerBooleanConfig(
13827 boolean reset, int booleanType, boolean enable) {
13828 Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType
13829 + ", reset=" + reset + ", enable=" + enable);
13830 TelephonyPermissions.enforceShellOnly(
13831 Binder.getCallingUid(), "setDatagramControllerBooleanConfig");
13832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13833 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13834 "ssetDatagramControllerBooleanConfig");
13835 return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, enable);
13836 }
13837
13838
13839 /**
Thomas Nguyen8b8777f2024-02-05 11:50:23 -080013840 * This API can be used by only CTS to override the timeout durations used by the
13841 * SatelliteController module.
13842 *
13843 * @param timeoutMillis The timeout duration in millisecond.
13844 * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
13845 */
13846 public boolean setSatelliteControllerTimeoutDuration(
13847 boolean reset, int timeoutType, long timeoutMillis) {
13848 Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
13849 + reset + ", timeoutMillis=" + timeoutMillis);
13850 TelephonyPermissions.enforceShellOnly(
13851 Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
13852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13853 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13854 "setSatelliteControllerTimeoutDuration");
13855 return mSatelliteController.setSatelliteControllerTimeoutDuration(
13856 reset, timeoutType, timeoutMillis);
Hakjun Choiae365972023-04-25 11:00:31 +000013857 }
13858
13859 /**
Thomas Nguyen11a051f2023-10-25 10:14:55 -070013860 * This API can be used in only testing to override connectivity status in monitoring emergency
13861 * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer.
13862 *
13863 * @param handoverType The type of handover from emergency call to satellite messaging. Use one
13864 * of the following values to enable the override:
13865 * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS
13866 * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911
13867 * To disable the override, use -1 for handoverType.
13868 * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer
13869 * delaySeconds after the emergency call starts.
13870 * @return {@code true} if the handover type is set successfully, {@code false} otherwise.
13871 */
13872 public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) {
13873 Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType);
13874 TelephonyPermissions.enforceShellOnly(
13875 Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType");
13876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13877 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13878 "setEmergencyCallToSatelliteHandoverType");
13879 return mSatelliteController.setEmergencyCallToSatelliteHandoverType(
13880 handoverType, delaySeconds);
13881 }
13882
13883 /**
Thomas Nguyen3d602742024-01-19 11:29:35 -080013884 * This API can be used in only testing to override oem-enabled satellite provision status.
13885 *
13886 * @param reset {@code true} mean the overriding status should not be used, {@code false}
13887 * otherwise.
13888 * @param isProvisioned The overriding provision status.
13889 * @return {@code true} if the provision status is set successfully, {@code false} otherwise.
13890 */
13891 public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) {
13892 Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset
13893 + ", isProvisioned=" + isProvisioned);
13894 TelephonyPermissions.enforceShellOnly(
13895 Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus");
13896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13897 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13898 "setOemEnabledSatelliteProvisionStatus");
13899 return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned);
13900 }
13901
13902 /**
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -080013903 * This API should be used by only CTS tests to forcefully set telephony country codes.
13904 *
13905 * @return {@code true} if the country code is set successfully, {@code false} otherwise.
13906 */
13907 public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes,
13908 Map cachedNetworkCountryCodes, String locationCountryCode,
13909 long locationCountryCodeTimestampNanos) {
13910 Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes="
13911 + String.join(", ", currentNetworkCountryCodes)
13912 + ", locationCountryCode=" + locationCountryCode
13913 + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos
13914 + ", reset=" + reset + ", cachedNetworkCountryCodes="
13915 + String.join(", ", cachedNetworkCountryCodes.keySet()));
13916 TelephonyPermissions.enforceShellOnly(
13917 Binder.getCallingUid(), "setCachedLocationCountryCode");
13918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13919 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13920 "setCachedLocationCountryCode");
13921 return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext()).setCountryCodes(
13922 reset, currentNetworkCountryCodes, cachedNetworkCountryCodes, locationCountryCode,
13923 locationCountryCodeTimestampNanos);
13924 }
13925
13926 /**
13927 * This API should be used by only CTS tests to override the overlay configs of satellite
13928 * access controller.
13929 *
13930 * @param reset {@code true} mean the overridden configs should not be used, {@code false}
13931 * otherwise.
13932 * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise.
13933 */
13934 public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed,
13935 String s2CellFile, long locationFreshDurationNanos,
13936 List<String> satelliteCountryCodes) {
13937 Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset
13938 + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile
13939 + ", locationFreshDurationNanos=" + locationFreshDurationNanos
13940 + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null)
13941 ? String.join(", ", satelliteCountryCodes) : null));
13942 TelephonyPermissions.enforceShellOnly(
13943 Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs");
13944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13945 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13946 "setSatelliteAccessControlOverlayConfigs");
13947 return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, isAllowed,
13948 s2CellFile, locationFreshDurationNanos, satelliteCountryCodes);
13949 }
13950
13951 /**
Hakjun Choibc6ce992023-11-07 16:04:33 +000013952 * This API can be used by only CTS to override the cached value for the device overlay config
13953 * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether
13954 * outgoing satellite datagrams should be sent to modem in demo mode.
13955 *
13956 * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to
13957 * satellite modem or not.
13958 *
13959 * @return {@code true} if the operation is successful, {@code false} otherwise.
13960 */
13961 public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) {
13962 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13963 Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is "
13964 + "disabled");
13965 return false;
13966 }
13967 Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode");
13968 TelephonyPermissions.enforceShellOnly(
13969 Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode");
13970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13971 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13972 "setShouldSendDatagramToModemInDemoMode");
13973 return mSatelliteController.setShouldSendDatagramToModemInDemoMode(
13974 shouldSendToModemInDemoMode);
13975 }
13976
13977 /**
Hakjun Choi4a832d12024-05-28 22:23:55 +000013978 * This API can be used by only CTS to set the cache whether satellite communication is allowed.
13979 *
13980 * @param state a state indicates whether satellite access allowed state should be cached and
13981 * the allowed state.
13982 * @return {@code true} if the setting is successful, {@code false} otherwise.
13983 */
13984 public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) {
13985 if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
13986 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13987 + "oemEnabledSatelliteFlag is disabled");
13988 return false;
13989 }
13990
13991 Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: "
13992 + "state=" + state);
13993 TelephonyPermissions.enforceShellOnly(
13994 Binder.getCallingUid(),
13995 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
13996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
13997 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
13998 "setIsSatelliteCommunicationAllowedForCurrentLocationCache");
13999 return mSatelliteAccessController.setIsSatelliteCommunicationAllowedForCurrentLocationCache(
14000 state);
14001 }
14002
14003 /**
Hunsuk Choi13078be2023-09-13 10:55:21 +000014004 * Sets the service defined in ComponentName to be bound.
14005 *
14006 * This should only be used for testing.
14007 * @return {@code true} if the DomainSelectionService to bind to was set,
14008 * {@code false} otherwise.
14009 */
14010 @Override
14011 public boolean setDomainSelectionServiceOverride(ComponentName componentName) {
14012 Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName);
14013
14014 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14015 "setDomainSelectionServiceOverride");
14016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14017 getDefaultSubscription(), "setDomainSelectionServiceOverride");
14018
14019 final long identity = Binder.clearCallingIdentity();
14020 try {
14021 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14022 return DomainSelectionResolver.getInstance()
14023 .setDomainSelectionServiceOverride(componentName);
14024 }
14025 } finally {
14026 Binder.restoreCallingIdentity(identity);
14027 }
14028 return false;
14029 }
14030
14031 /**
14032 * Clears the DomainSelectionService override.
14033 *
14034 * This should only be used for testing.
14035 * @return {@code true} if the DomainSelectionService override was cleared,
14036 * {@code false} otherwise.
14037 */
14038 @Override
14039 public boolean clearDomainSelectionServiceOverride() {
14040 Log.i(LOG_TAG, "clearDomainSelectionServiceOverride");
14041
14042 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
14043 "clearDomainSelectionServiceOverride");
14044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
14045 getDefaultSubscription(), "clearDomainSelectionServiceOverride");
14046
14047 final long identity = Binder.clearCallingIdentity();
14048 try {
14049 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
14050 return DomainSelectionResolver.getInstance()
14051 .clearDomainSelectionServiceOverride();
14052 }
14053 } finally {
14054 Binder.restoreCallingIdentity(identity);
14055 }
14056 return false;
14057 }
14058
14059 /**
Gil Cukierman06403e12023-11-29 16:33:03 +000014060 * Enable or disable notifications sent for cellular identifier disclosure events.
14061 *
14062 * Disclosure events are defined as instances where a device has sent a cellular identifier
14063 * on the Non-access stratum (NAS) before a security context is established. As a result the
14064 * identifier is sent in the clear, which has privacy implications for the user.
14065 *
14066 * @param enable if notifications about disclosure events should be enabled
14067 * @throws SecurityException if the caller does not have the required privileges
14068 * @throws UnsupportedOperationException if the modem does not support this feature.
14069 */
14070 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014071 public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) {
Gil Cukierman06403e12023-11-29 16:33:03 +000014072 enforceModifyPermission();
14073 checkForIdentifierDisclosureNotificationSupport();
14074
14075 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14076 editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable);
14077 editor.apply();
14078
14079 // Each phone instance is responsible for updating its respective modem immediately
14080 // after we've made a preference change.
14081 for (Phone phone : PhoneFactory.getPhones()) {
14082 phone.handleIdentifierDisclosureNotificationPreferenceChange();
14083 }
14084 }
14085
14086 /**
14087 * Get whether or not cellular identifier disclosure notifications are enabled.
14088 *
14089 * @throws SecurityException if the caller does not have the required privileges
14090 * @throws UnsupportedOperationException if the modem does not support this feature.
14091 */
14092 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Gil Cukiermanff9ec8e2023-12-13 15:42:56 +000014093 public boolean isCellularIdentifierDisclosureNotificationsEnabled() {
Gil Cukierman06403e12023-11-29 16:33:03 +000014094 enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled");
14095 checkForIdentifierDisclosureNotificationSupport();
14096 return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled();
14097 }
14098
14099 /**
Michael Groover826b71d2023-12-21 22:08:06 -060014100 * Enables or disables notifications sent when cellular null cipher or integrity algorithms
14101 * are in use by the cellular modem.
14102 *
14103 * @throws IllegalStateException if the Telephony process is not currently available
14104 * @throws SecurityException if the caller does not have the required privileges
14105 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14106 * and integrity algorithms in use
14107 * @hide
14108 */
14109 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
Michael Grooverae447b22024-01-24 22:35:46 -060014110 public void setNullCipherNotificationsEnabled(boolean enable) {
Michael Groover826b71d2023-12-21 22:08:06 -060014111 enforceModifyPermission();
14112 checkForNullCipherNotificationSupport();
14113
14114 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
14115 editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable);
14116 editor.apply();
14117
14118 // Each phone instance is responsible for updating its respective modem immediately
14119 // after a preference change.
14120 for (Phone phone : PhoneFactory.getPhones()) {
14121 phone.handleNullCipherNotificationPreferenceChanged();
14122 }
14123 }
14124
14125 /**
14126 * Get whether notifications are enabled for null cipher or integrity algorithms in use by the
14127 * cellular modem.
14128 *
14129 * @throws IllegalStateException if the Telephony process is not currently available
14130 * @throws SecurityException if the caller does not have the required privileges
14131 * @throws UnsupportedOperationException if the modem does not support reporting on ciphering
14132 * and integrity algorithms in use
14133 * @hide
14134 */
14135 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
14136 public boolean isNullCipherNotificationsEnabled() {
14137 enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled");
14138 checkForNullCipherNotificationSupport();
14139 return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled();
14140 }
14141
14142 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000014143 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
14144 *
14145 * <p>This method behaves in one of the following ways:
14146 * <ul>
14147 * <li>return true : if the calling package has the appop permission {@link
14148 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
14149 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
14150 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
14151 * Owner device identifier access check, or the calling package has carrier privileges</>
14152 * <li>throw SecurityException: if the caller does not meet any of the requirements.
14153 * </ul>
14154 */
14155 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
14156 String callingPackage, @Nullable String callingFeatureId, String message) {
14157 for (Phone phone : PhoneFactory.getPhones()) {
14158 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
14159 phone.getSubId(), callingPackage, callingFeatureId, message)) {
14160 return true;
14161 }
14162 }
14163 return false;
14164 }
arunvoddud7401012022-12-15 16:08:12 +000014165
14166 /**
Jack Yufa8ed012023-02-11 15:42:28 -080014167 * @return The subscription manager service instance.
14168 */
14169 public SubscriptionManagerService getSubscriptionManagerService() {
14170 return SubscriptionManagerService.getInstance();
14171 }
14172
14173 /**
arunvoddud7401012022-12-15 16:08:12 +000014174 * Class binds the consumer[callback] and carrierId.
14175 */
14176 private static class CallerCallbackInfo {
14177 private final Consumer<Integer> mConsumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014178 private final Set<Integer> mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014179
Steve Statia28b7cb32024-03-11 23:58:50 +000014180 public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) {
arunvoddud7401012022-12-15 16:08:12 +000014181 mConsumer = consumer;
Steve Statia28b7cb32024-03-11 23:58:50 +000014182 mCarrierIds = carrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014183 }
14184
14185 public Consumer<Integer> getConsumer() {
14186 return mConsumer;
14187 }
14188
Steve Statia28b7cb32024-03-11 23:58:50 +000014189 public Set<Integer> getCarrierIds() {
14190 return mCarrierIds;
arunvoddud7401012022-12-15 16:08:12 +000014191 }
14192 }
joonhunshin4ac60942023-11-15 15:23:39 +000014193
14194 /*
14195 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14196 * But the context that is passed in is unused if the phone app is already alive.
14197 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14198 */
14199 @VisibleForTesting
14200 public void setPackageManager(PackageManager packageManager) {
14201 mPackageManager = packageManager;
14202 }
14203
14204 /*
Nate Myren453c3472024-03-13 11:28:11 -070014205 * PhoneInterfaceManager is a singleton. Unit test calls the init() with context.
14206 * But the context that is passed in is unused if the phone app is already alive.
14207 * In this case PackageManager object is different in PhoneInterfaceManager and Unit test.
14208 */
14209 @VisibleForTesting
14210 public void setAppOpsManager(AppOpsManager appOps) {
14211 mAppOps = appOps;
14212 }
14213
14214 /*
joonhunshin4ac60942023-11-15 15:23:39 +000014215 * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags.
14216 * But the FeatureFlags that is passed in is unused if the phone app is already alive.
14217 * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test.
14218 */
14219 @VisibleForTesting
14220 public void setFeatureFlags(FeatureFlags featureFlags) {
14221 mFeatureFlags = featureFlags;
14222 }
14223
14224 /**
14225 * Make sure the device has required telephony feature
14226 *
14227 * @throws UnsupportedOperationException if the device does not have required telephony feature
14228 */
14229 private void enforceTelephonyFeatureWithException(@Nullable String callingPackage,
14230 @NonNull String telephonyFeature, @NonNull String methodName) {
14231 if (callingPackage == null || mPackageManager == null) {
14232 return;
14233 }
14234
14235 if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
14236 || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage,
joonhunshinf624b2a2024-04-18 04:42:12 +000014237 Binder.getCallingUserHandle())
14238 || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
14239 // Skip to check associated telephony feature,
14240 // if compatibility change is not enabled for the current process or
14241 // the SDK version of vendor partition is less than Android V.
joonhunshin4ac60942023-11-15 15:23:39 +000014242 return;
14243 }
14244
14245 if (!mPackageManager.hasSystemFeature(telephonyFeature)) {
14246 throw new UnsupportedOperationException(
14247 methodName + " is unsupported without " + telephonyFeature);
14248 }
14249 }
youngtaecha5d483d52024-04-29 17:05:45 +000014250
14251 /**
14252 * Registers for the satellite communication allowed state changed.
14253 *
14254 * @param subId The subId of the subscription to register for the satellite communication
14255 * allowed state changed.
14256 * @param callback The callback to handle the satellite communication allowed
14257 * state changed event.
14258 *
14259 * @return The {@link SatelliteManager.SatelliteResult} result of the operation.
14260 *
14261 * @throws SecurityException if the caller doesn't have the required permission.
14262 */
14263 @Override
14264 @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged(
14265 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14266 enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged");
14267 return mSatelliteAccessController.registerForCommunicationAllowedStateChanged(
14268 subId, callback);
14269 }
14270
14271 /**
14272 * Unregisters for the satellite communication allowed state changed.
14273 * If callback was not registered before, the request will be ignored.
14274 *
14275 * @param subId The subId of the subscription to unregister for the satellite communication
14276 * allowed state changed.
14277 * @param callback The callback that was passed to
14278 * {@link #registerForCommunicationAllowedStateChanged(int,
14279 * ISatelliteCommunicationAllowedStateCallback)}. *
14280 * @throws SecurityException if the caller doesn't have the required permission.
14281 */
14282 @Override
14283 public void unregisterForCommunicationAllowedStateChanged(
14284 int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) {
14285 enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged");
14286 mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, callback);
14287 }
Aishwarya Mallampatif265cea2024-06-04 19:55:41 +000014288
14289 /**
14290 * Request to get the {@link SatelliteSessionStats} of the satellite service.
14291 *
14292 * @param subId The subId of the subscription to the satellite session stats for.
14293 * @param result The result receiver that returns the {@link SatelliteSessionStats}
14294 * if the request is successful or an error code if the request failed.
14295 *
14296 * @throws SecurityException if the caller doesn't have required permission.
14297 */
14298 @Override
14299 public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) {
14300 enforceModifyPermission();
14301 enforcePackageUsageStatsPermission("requestSatelliteSessionStats");
14302 mSatelliteController.requestSatelliteSessionStats(subId, result);
14303 }
Hyosun Kim8bac3be2024-06-28 13:35:30 +000014304
14305 /**
14306 * Request to get list of prioritized satellite subscriber ids to be used for provision.
14307 *
14308 * @param result The result receiver, which returns the list of prioritized satellite tokens
14309 * to be used for provision if the request is successful or an error code if the request failed.
14310 *
14311 * @throws SecurityException if the caller doesn't have the required permission.
14312 */
14313 @Override
14314 public void requestProvisionSubscriberIds(@NonNull ResultReceiver result) {
14315 enforceSatelliteCommunicationPermission("requestProvisionSubscriberIds");
14316 mSatelliteController.requestProvisionSubscriberIds(result);
14317 }
14318
14319 /**
14320 * Request to get provisioned status for given a satellite subscriber id.
14321 *
14322 * @param satelliteSubscriberId Satellite subscriber id requiring provisioned status check.
14323 * @param result The result receiver, which returns the provisioned status of the token if the
14324 * request is successful or an error code if the request failed.
14325 *
14326 * @throws SecurityException if the caller doesn't have the required permission.
14327 */
14328 @Override
14329 public void requestIsProvisioned(String satelliteSubscriberId, @NonNull ResultReceiver result) {
14330 enforceSatelliteCommunicationPermission("requestIsProvisioned");
14331 mSatelliteController.requestIsProvisioned(satelliteSubscriberId, result);
14332 }
14333
14334 /**
14335 * Deliver the list of provisioned satellite subscriber ids.
14336 *
14337 * @param list List of provisioned satellite subscriber ids.
14338 * @param result The result receiver that returns whether deliver success or fail.
14339 *
14340 * @throws SecurityException if the caller doesn't have the required permission.
14341 */
14342 @Override
14343 public void provisionSatellite(List<ProvisionSubscriberId> list,
14344 @NonNull ResultReceiver result) {
14345 enforceSatelliteCommunicationPermission("provisionSatellite");
14346 mSatelliteController.provisionSatellite(list, result);
14347 }
Jack Yufa8ed012023-02-11 15:42:28 -080014348}